Handle expired tokens better
This commit is contained in:
parent
58f077950c
commit
b8d73e3a94
|
@ -34,7 +34,7 @@ export class AuthenticationController {
|
||||||
|
|
||||||
return user
|
return user
|
||||||
} catch (error: any) {
|
} 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)
|
const token = getToken(req)
|
||||||
|
|
||||||
if (token) {
|
if (token) {
|
||||||
|
try {
|
||||||
const user = await AuthenticationController.authenticate(token)
|
const user = await AuthenticationController.authenticate(token)
|
||||||
req.user = user
|
req.user = user
|
||||||
|
} catch (error: any) {
|
||||||
|
return res.status(401).json({ error: error.message })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
next()
|
next()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user