Is there a way to force expire jwt token (not refresh token) in adonis-js.
I am creating a token on login and setting its time to expire for 10 mins. When I log out I want to force expire that token before 10 mins.
Asked
Active
Viewed 1,230 times
0
trighati
- 1,306
- 8
- 20
- 55
-
Does this answer your question? [Invalidating JSON Web Tokens](https://stackoverflow.com/questions/21978658/invalidating-json-web-tokens) – Laxmikant Dange Dec 25 '19 at 07:54
2 Answers
4
Try these things for your token. The tokens can be expired. But you cannot do it on demand.
- Set a reasonable expiration time on tokens.
- Delete the stored token from the client-side upon log out.
- Have DB of no longer active tokens that still have some time to live.
- Query provided token against The Blacklist on every authorized request.
Ankit Kumar Rajpoot
- 5,032
- 1
- 38
- 28
1
I did it this way:
async login({ request, auth }) {
const { email, password } = request.all();
const user = await auth.validate(email, password, true);
const { name, admin, confirmed } = user;
const token = await auth.generate(user, false, { expiresIn: '10m' })
return { token, user }
}
Sandro
- 63
- 5