How to Implement a LogoutOtherDevices Feature Similar to Laravel in AdonisJS #4907
-
I have a requirement to log out all devices except the current session when a user changes their password. In Laravel, there is a built-in method called I would like to know if AdonisJS has a similar method available. If not, could you please guide me on how to retrieve all user sessions so that I can handle the logout process manually? Any insights or code examples would be greatly appreciated. Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hey @retronew I don’t think Adonis Core has a built-in helper for this, but you can find a similar feature on the Adocast website since it's open source. Take a look at this class to see if it implements what you need: |
Beta Was this translation helpful? Give feedback.
-
I've ended up to create it manually (working with access tokens)
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
}
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()
}
} |
Beta Was this translation helpful? Give feedback.
I've ended up to create it manually (working with access tokens)