I am facing an issue with the following code. I'm not sure what is causing the error or how to fix it. The specific error message is:
Type 'CookieSessionObject | null | undefined' is not assignable to type '{ token: string; refreshToken: string; }'.
Type 'undefined' is not assignable to type '{ token: string; refreshToken: string; }'
...
namespace CookieSessionInterfaces {
interface CookieSessionObject {
token?: string;
refreshToken?: string;
}
}
}
const currentUser = async (req: Request, res: Response, next: NextFunction) => {
const { token, refreshToken }: { token: string, refreshToken: string } = req.session;
...
Additionally, req.session?.token
and req.session?.refreshToken
are functioning properly.