i'm new to nestjs.
i'm trying to transform plaintext password to crypted string but i'm receiving it as "Promise { }"
how can I await here?
import { Transform } from 'class-transformer';
import * as bcrypt from "bcrypt";
const hashPass = async user => {
return await bcrypt.hash(user.password, 7);
}
export class UserDto {
readonly name: string;
readonly phone: number;
readonly username: string;
readonly email: string;
@Transform( hashPass, {toClassOnly: true})
readonly password: string;
}
You can't as of now, since class-transformer doesn't support it.
The transformer decorator expects a synchronous transform function.
As a workaround, you can try the non-promise version of bcrypt:
bcrypt.hashSync(user.password, 7);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.