maxgalbu / adonis5-jwt

JWT Authentication service for Adonisjs v5
MIT License
86 stars 15 forks source link

How to get the payload of a token? #2

Closed JhonatanPatrocinio closed 2 years ago

JhonatanPatrocinio commented 2 years ago

await auth.use("jwt").generate(user, { payload: { is_verified: true, }, });

how can I obtain this payload on the middleware?

maxgalbu commented 2 years ago

hi @JhonatanPatrocinio, this example from the readme is fitting:

//authenticate() example
Route.get('/dashboard', async ({ auth }) => {
    await auth.use("jwt").authenticate();
    const userPayload = auth.use("jwt").user!;
});

userPayload is the payload you used to generate the JWT

JhonatanPatrocinio commented 2 years ago

I try this and userPayload is equal to User instance

maxgalbu commented 2 years ago

You're right. Let me check

maxgalbu commented 2 years ago

https://github.com/maxgalbu/adonis5-jwt/commit/823cf95c72b92f0182f4e896b1422ebff7e890f6 added payload to the guard, see the readme for docs

I've also published 1.0.9 with that commit