JWT auth middleware in adonis 4.1


#1

Auth jwt middleware is not working in adonisjs 4.1. On logout it updates is_revoked field to 1 but still allows access to protected routes.

// Generate token
const user = await User.find(1)
const token = await auth.authenticator(‘jwt’).withRefreshToken()
.generate(user)

// My logout method
async logout ({request, response, auth}) {
try {
const user = await auth.authenticator(‘jwt’).getUser()
await auth.authenticator(‘jwt’).revokeTokensForUser(user)

// Clear device token
user.device_token = ''
await user.save()

} catch (err) {
console.log( err );
}

response.messageResponse(‘You have been logged-out successfully.’)
}

// My logout route
Route.group(() => {
Route.get(‘logout’, ‘Api/WebserviceController.logout’)
}).prefix(‘api/v1’).middleware(‘auth:jwt’);

THANK
CRISTIANO


#2

Can you please format the question properly? Formatting questions in a nicer way, will increase the changes of getting quick answers, so please don’t be lazy