Fix-auth-hashing-update-worklog

This commit is contained in:
SpecialX
2026-02-24 15:50:38 +08:00
parent bb4555f611
commit a2e89ce795
5 changed files with 63 additions and 10 deletions

View File

@@ -1,4 +1,5 @@
import { Metadata } from "next"
import { hash } from "bcryptjs"
import { createId } from "@paralleldrive/cuid2"
import { eq } from "drizzle-orm"
@@ -10,6 +11,12 @@ export const metadata: Metadata = {
description: "Create an account",
}
const normalizeBcryptHash = (value: string) => {
if (value.startsWith("$2")) return value
if (value.startsWith("$")) return `$2b${value}`
return `$2b$${value}`
}
export default function RegisterPage() {
async function registerAction(formData: FormData): Promise<ActionState> {
"use server"
@@ -37,11 +44,12 @@ export default function RegisterPage() {
})
if (existing) return { success: false, message: "该邮箱已注册" }
const hashedPassword = normalizeBcryptHash(await hash(password, 10))
await db.insert(users).values({
id: createId(),
name: name.length ? name : null,
email,
password,
password: hashedPassword,
role: "student",
})