52 lines
1.2 KiB
TypeScript
52 lines
1.2 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", isPrimary: true })
|
||
|
declare id: number
|
||
|
|
||
|
@column({
|
||
|
columnName: "full_name",
|
||
|
})
|
||
|
declare fullName: string | null
|
||
|
|
||
|
@column({
|
||
|
columnName: "email",
|
||
|
})
|
||
|
declare email: string
|
||
|
|
||
|
@column({ columnName: "password", serializeAs: null })
|
||
|
declare password: string
|
||
|
|
||
|
@column.dateTime({
|
||
|
columnName: "created_at",
|
||
|
autoCreate: true,
|
||
|
})
|
||
|
declare createdAt: DateTime
|
||
|
|
||
|
@column.dateTime({
|
||
|
columnName: "updated_at",
|
||
|
autoCreate: true,
|
||
|
autoUpdate: true,
|
||
|
})
|
||
|
declare updatedAt: DateTime | null
|
||
|
|
||
|
static accessTokens = DbAccessTokensProvider.forModel(User)
|
||
|
}
|