Skip to content
\n

When testing on the postman, tokens still available on the DB, and will re-use.

\n

What i ask about it, how to correct implementation this section?
\nMaybe can this auth-access-tokens-guard is stateless without using JWT?

\n

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'

\n

So here is my full code deleting all tokens on the Database related id from User

\n
import 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
","upvoteCount":3,"url":"https://github.com/orgs/adonisjs/discussions/4391#discussioncomment-8426060"}}}

[V6] How to Logged Out or Remove Access Tokens from Database After Logout #4391

Answered by heirro
heirro asked this question in Help
Discussion options

You must be logged in to vote

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

import type { HttpContext } from '@adonisjs/core/http'
import User from '#models/user'
import DB from '@adonisjs/lucid/services/db'

export default class LogoutsController {
    public async logout({ auth, response }: HttpContext) {

        const getUser = auth.user?.id
        const user = await User.findOrFail(getUser)
        await User.accessTokens.delete(user, user.id)

        await DB.from('auth_access_tokens').where('tokenable_id', user.id).delete()

        return response.ok({
            success: true,
            message: '…

Replies: 4 comments 4 replies

Comment options

You must be logged in to vote
3 replies
@thetutlage
Comment options

@mertgibi
Comment options

@thetutlage
Comment options

Answer selected by heirro
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@marhao
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
7 participants