ex) 12345 ⇒ hashFunction(12345) ⇒ very random
<aside> 🥕
npm i bcrypt
npm i @types/bcrypt // 패키지에 대한 타입스크립트 얻기 위함
</aside>
app > create-account > actions.ts
import bcrypt from "bcrypt";
// ...
export async function createAccount(prevState:any, formData: FormData) {
// ...
if (!result.success) {
return result.error.flatten();
} else {
// hash password
const hashedPassword = await bcrypt.hash(result.data.password, 12);
// save the user to db
const user = await db.user.create({
data : {
username: result.data.username,
email: result.data.email,
password: hashedPassword
},
select :{ // 필요한 것만 db에서 받아오기
id: true
}
});
}
}