【发布时间】:2021-02-01 19:50:55
【问题描述】:
JWT 验证码 这是使用 typescript 验证 jwt 的验证功能。
public verify(
token: string,
secretOrPublicKey?: string | Buffer,
options?: jwt.VerifyOptions
): Promise<object | string> {
if (!secretOrPublicKey) {
secretOrPublicKey = this.secretOrPublicKey;
}
return new Promise((resolve, reject) => {
jwt.verify(
token,
secretOrPublicKey,
options,
(err: jwt.VerifyErrors, decoded: object | string) => {
if (err) {
reject(err);
} else {
resolve(decoded);
}
}
);
});
}
我在secrectOrPublicKey 上发现了以下警告线以及如何解决这个问题。任何评论都会对我很有帮助。
(parameter) secretOrPublicKey: string | Buffer | undefined Argument of type 'string | Buffer | undefined' is not assignable to parameter of type 'string | Buffer | { key: string | Buffer; passphrase: string; } | GetPublicKeyOrSecret'. Type 'undefined' is not assignable to type 'string | Buffer | { key: string | Buffer; passphrase: string; } | GetPublicKeyOrSecret'.ts(2345)
【问题讨论】:
标签: javascript node.js typescript express jwt