Handle expired tokens better

This commit is contained in:
Douglas Barone 2023-06-19 08:03:08 -04:00
parent 58f077950c
commit b8d73e3a94
2 changed files with 7 additions and 3 deletions

View File

@ -34,7 +34,7 @@ export class AuthenticationController {
return user
} catch (error: any) {
throw new Error('Invalid token')
throw new Error(`Invalid token. ${error.message}`)
}
}
}

View File

@ -21,8 +21,12 @@ export async function injectUserMiddleware(
const token = getToken(req)
if (token) {
const user = await AuthenticationController.authenticate(token)
req.user = user
try {
const user = await AuthenticationController.authenticate(token)
req.user = user
} catch (error: any) {
return res.status(401).json({ error: error.message })
}
}
next()