When testing on the postman, tokens still available on the DB, and will re-use.
\nWhat i ask about it, how to correct implementation this section?
\nMaybe can this auth-access-tokens-guard is stateless without using JWT?
In case: I Use adonis.js as a backend, and remix as a frontend-ssr
","upvoteCount":4,"answerCount":4,"acceptedAnswer":{"@type":"Answer","text":"I just hardcode tricky using import DB from '@adonisjs/lucid/services/db'
So here is my full code deleting all tokens on the Database related id from User
\nimport type { HttpContext } from '@adonisjs/core/http'\nimport User from '#models/user'\nimport DB from '@adonisjs/lucid/services/db'\n\nexport default class LogoutsController {\n public async logout({ auth, response }: HttpContext) {\n\n const getUser = auth.user?.id\n const user = await User.findOrFail(getUser)\n await User.accessTokens.delete(user, user.id)\n\n await DB.from('auth_access_tokens').where('tokenable_id', user.id).delete()\n\n return response.ok({\n success: true,\n message: 'User logged out',\n })\n }\n}\n
-
Hi i just implemented the new V6 core. However got the issues about Deleting tokens using auth-access-tokens-guard.
When testing on the postman, tokens still available on the DB, and will re-use. What i ask about it, how to correct implementation this section? In case: I Use adonis.js as a backend, and remix as a frontend-ssr |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 4 replies
-
I just hardcode tricky using So here is my full code deleting all tokens on the Database related id from User
|
Beta Was this translation helpful? Give feedback.
-
async logout({ auth, response }: HttpContext) {
const user = auth.getUserOrFail()
const token = auth.user?.currentAccessToken.identifier
if (!token) {
return response.badRequest({ message: 'Token not found' })
}
await User.accessTokens.delete(user, token)
return response.ok({ message: 'Logged out' })
} |
Beta Was this translation helpful? Give feedback.
-
@heirro I'm many months late, but I'll add this for anyone who may find this useful.
|
Beta Was this translation helpful? Give feedback.
-
Wow! That would be my next question, thanks bro! |
Beta Was this translation helpful? Give feedback.
I just hardcode tricky using
import DB from '@adonisjs/lucid/services/db'
So here is my full code deleting all tokens on the Database related id from User