尝试使用Hash.make(user.password)
from加密用户密码import Hash from '@ioc:Adonis/Core/Hash'
当代码尝试Hash.make
在@beforesave 中执行当前时,就会出现问题,它给了我一个referenceError。
message:'Hash is not defined'
stack:'ReferenceError: Hash is not defined\n at eval (eval at hashPassword (/usr/src/app/Models/User.ts:35:9), <anonymous>:2:28)
这是用户模型。
import { DateTime } from 'luxon'
import Hash from '@ioc:Adonis/Core/Hash'
import { column, beforeSave, BaseModel } from '@ioc:Adonis/Lucid/Orm'
import Logger from '@ioc:Adonis/Core/Logger'
export default class User extends BaseModel {
@column({ isPrimary: true })
public id: number
@column()
public email: string
@column({ columnName: 'first_name' })
public firstName: string
@column({ columnName: 'last_name' })
public lastName: string
@column({ serializeAs: null })
public password: string
@column()
public rememberMeToken?: string
@column.dateTime({ autoCreate: true })
public createdAt: DateTime
@column.dateTime({ autoCreate: true, autoUpdate: true })
public updatedAt: DateTime
@beforeSave()
public static async hashPassword(user: User) {
if (user.$dirty.password) {
try {
user.password = await Hash.make(user.password)
}
catch (error) {
Logger.error(error)
}
}
}
}
当调试步骤进入属于哈希依赖项的正确路径时,我认为它在哈希驱动程序中失败了