Replies: 1 comment
-
@Alnsentry , I don't think we need the identifier. Here is my code and hope it is help. async destroy(ctx: HttpContext) {
const token = ctx.auth.user?.currentAccessToken;
if (token)
await User.accessTokens.delete(ctx.auth.getUserOrFail(), token.identifier);
ctx.response.success(null, 'Logout successful', 204);
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Property 'currentAccessToken' does not exist on type 'never'.ts(2339)
i have this error on my code when i want to delete my current access token
Controller
async destroy({ response, auth }: 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' }) }
Model
`import { DateTime } from 'luxon'
import hash from '@adonisjs/core/services/hash'
import { compose } from '@adonisjs/core/helpers'
import { BaseModel, column, hasOne } from '@adonisjs/lucid/orm'
import { withAuthFinder } from '@adonisjs/auth/mixins/lucid'
import { DbAccessTokensProvider } from '@adonisjs/auth/access_tokens'
import type { HasOne } from '@adonisjs/lucid/types/relations'
// Model
import Information from '#models/user_information'
const AuthFinder = withAuthFinder(() => hash.use('scrypt'), {
uids: ['email', 'information.ptbestId'],
passwordColumnName: 'password',
})
export default class User extends compose(BaseModel, AuthFinder) {
@column({ isPrimary: true })
declare id: number
@column()
declare name: string
@column()
declare email: string
@column.dateTime()
declare emailVerifiedAt: DateTime | null
@column()
declare password: string
@column.dateTime({ autoCreate: true })
declare createdAt: DateTime
@column.dateTime({ autoCreate: true, autoUpdate: true })
declare updatedAt: DateTime | null
@column.dateTime()
declare deletedAt: DateTime | null
// Relations
@hasone(() => Information)
declare information: HasOne
static accessTokens = DbAccessTokensProvider.forModel(User, {
expiresIn: '30 days',
prefix: 'oat_',
table: 'auth_access_tokens',
type: 'auth_token',
tokenSecretLength: 40,
})
}
`
Beta Was this translation helpful? Give feedback.
All reactions