Skip to content

[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