Skip to content

Commit

Permalink
hash token on account creation, not just password reset
Browse files Browse the repository at this point in the history
  • Loading branch information
boazsender committed Feb 16, 2024
1 parent 4ff37ae commit 95702c2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions app/models/user.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,16 @@ export async function createUser(
password: string,
doNotSell: boolean,
) {
const newToken = randomBytes(16).toString("hex");
const hashedNewToken = sha256(newToken);

const hashedPassword = await bcrypt.hash(password, 10);

return prisma.user.create({
data: {
email,
doNotSell,
token: hashedNewToken,
password: {
create: {
hash: hashedPassword,
Expand Down Expand Up @@ -120,6 +124,7 @@ export async function verifyEmail({
},
data: {
emailVerified: true,
token: "",
},
});
}
Expand Down
2 changes: 1 addition & 1 deletion prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ datasource db {
model User {
id String @id @default(cuid())
email String @unique
token String @unique @default(uuid())
token String @unique
emailVerified Boolean? @default(false)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
Expand Down

0 comments on commit 95702c2

Please sign in to comment.