Im quite new to Typescript, I'm not sure what the correct syntax is to use.
I'm using a promise to return the decoded content from jwt.verify - jsonwebtoken. It works as expected and returns an object containing the user.id, the iat, and the expiry but the following type error appears on the resolve promise.
"Argument of type 'object' is not assignable to parameter of type 'IVerifiedUserType | PromiseLike | undefined'."
Below is the Interface and code that I am returning. Im using async await on the promise.
export interface IVerifiedUserType {
id: number;
iat: number;
exp: number;
}
const verifyToken = (token: string, config: IConfigType): Promise<IVerifiedUserType> =>
new Promise((resolve, reject) => {
if (config.secrets.jwt) {
jwt.verify(token, config.secrets.jwt, (err, decoded) => {
if (err) {
return reject(err);
}
if (typeof decoded === "object") {
resolve(decoded);
}
});
}
});
const verifiedToken = await authService.verifyToken(token, config);
Im using "jsonwebtoken": "^8.5.1", and "@types/jsonwebtoken": "^8.3.3", for types.