Skip to content

How to Implement a LogoutOtherDevices Feature Similar to Laravel in AdonisJS #4907

Closed Answered by MohammedElattar
retronew asked this question in Help
Discussion options

You must be logged in to vote

I've ended up to create it manually (working with access tokens)

  • access_token_model.ts
import CustomModel from '#models/utils/custom_model'
import { column } from '@adonisjs/lucid/orm'

export default class AccessTokenModel extends CustomModel {
  public static table = 'auth_access_tokens'

  @column({ isPrimary: true })
  declare id: number
}
  • logout_user.ts action
import UserContextHelper from '../utils/user_context_helper.js'
import AccessTokenModel from '../models/access_token_model.js'

export default class LogoutUser {
  public static async handle() {
    await AccessTokenModel.query().where('tokenable_id', UserContextHelper.id()).delete()
  }
}

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

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