56 lines
1.3 KiB
TypeScript
56 lines
1.3 KiB
TypeScript
import { DbAccessTokensProvider } from "@adonisjs/auth/access_tokens"
|
|
import { withAuthFinder } from "@adonisjs/auth/mixins/lucid"
|
|
import { compose } from "@adonisjs/core/helpers"
|
|
import hash from "@adonisjs/core/services/hash"
|
|
import { BaseModel, column } from "@adonisjs/lucid/orm"
|
|
import { DateTime } from "luxon"
|
|
|
|
const AuthFinder = withAuthFinder(
|
|
() => {
|
|
return hash.use("scrypt")
|
|
},
|
|
{
|
|
uids: ["email"],
|
|
passwordColumnName: "password",
|
|
},
|
|
)
|
|
|
|
export default class User extends compose(BaseModel, AuthFinder) {
|
|
protected tableName = "users"
|
|
|
|
@column({ columnName: "id", serializeAs: "id", isPrimary: true })
|
|
declare id: number
|
|
|
|
@column({
|
|
columnName: "full_name",
|
|
serializeAs: "fullName",
|
|
})
|
|
declare fullName: string
|
|
|
|
@column({
|
|
columnName: "email",
|
|
serializeAs: "email",
|
|
})
|
|
declare email: string
|
|
|
|
@column({ columnName: "password", serializeAs: null })
|
|
declare password: string
|
|
|
|
@column.dateTime({
|
|
columnName: "created_at",
|
|
serializeAs: "createdAt",
|
|
autoCreate: true,
|
|
})
|
|
declare createdAt: DateTime
|
|
|
|
@column.dateTime({
|
|
columnName: "updated_at",
|
|
serializeAs: "updatedAt",
|
|
autoCreate: true,
|
|
autoUpdate: true,
|
|
})
|
|
declare updatedAt: DateTime
|
|
|
|
static accessTokens = DbAccessTokensProvider.forModel(User)
|
|
}
|