import { DateTime } from 'luxon' import hash from '@adonisjs/core/services/hash' import { compose } from '@adonisjs/core/helpers' import { BaseModel, column } from '@adonisjs/lucid/orm' import { withAuthFinder } from '@adonisjs/auth/mixins/lucid' import { DbAccessTokensProvider } from '@adonisjs/auth/access_tokens' const AuthFinder = withAuthFinder(() => hash.use('scrypt'), { uids: ['username'], passwordColumnName: 'password', }) export default class User extends compose(BaseModel, AuthFinder) { @column({ isPrimary: true }) declare id: number @column() declare username: string @column({ serializeAs: null }) declare password: string @column.dateTime({ autoCreate: true }) declare createdAt: DateTime @column.dateTime({ autoCreate: true, autoUpdate: true }) declare updatedAt: DateTime | null @column() declare firstName: string | null @column() declare lastName: string | null /** * Bearer tokens used to authenticate API requests. * (Bảng auth_access_tokens — chính là "token" trong schema của bạn.) */ static accessTokens = DbAccessTokensProvider.forModel(User) }