Handle expired tokens better
This commit is contained in:
parent
58f077950c
commit
b8d73e3a94
|
@ -34,7 +34,7 @@ export class AuthenticationController {
|
|||
|
||||
return user
|
||||
} catch (error: any) {
|
||||
throw new Error('Invalid token')
|
||||
throw new Error(`Invalid token. ${error.message}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue
Block a user