This should be an easy one yet I cant figure it out at all. I am using firebase to try to verify a token form client side
const isAuthenticated = async (req: Request, res: Response, next: NextFunction) => {
try {
let token: string;
if (req.headers.token !== undefined) {
token = req.headers.token || '';
const result = await auth.verifyIdToken(token)
}
return next()
} catch (error) {
res.status(401).json({
error:'Invalid token'
})
}
}
The error type 'string | string[]' is not assignable to type 'string'
in the given on
token = req.headers.token || '';
The verifyToken
is meant to take a string as a parameter and obviously the req.headers.token
isn't defined yet. What am i doing wrong?