fehler 2
This commit is contained in:
parent
166a1b5d06
commit
aec4b93439
|
|
@ -1,7 +1,7 @@
|
|||
'use server'
|
||||
|
||||
import { prisma } from '@innungsapp/shared'
|
||||
import { auth, getSanitizedHeaders } from '@/lib/auth'
|
||||
import { auth } from '@/lib/auth'
|
||||
import { revalidatePath } from 'next/cache'
|
||||
import { redirect } from 'next/navigation'
|
||||
import { headers } from 'next/headers'
|
||||
|
|
@ -16,23 +16,9 @@ function normalizeEmail(email: string | null | undefined): string {
|
|||
|
||||
/**
|
||||
* Sets a credential (email+password) account for a user.
|
||||
* Tries auth.api.updateUser first (uses better-auth's internal hashing, guaranteed compatible).
|
||||
* Falls back to direct DB write if that fails.
|
||||
* Uses direct DB write with better-auth's hashPassword for compatibility.
|
||||
*/
|
||||
async function setCredentialPassword(userId: string, password: string) {
|
||||
// Primary: use better-auth's own API to ensure correct hash format
|
||||
try {
|
||||
const authHeaders = await getSanitizedHeaders()
|
||||
await auth.api.updateUser({
|
||||
body: { userId, password },
|
||||
headers: authHeaders,
|
||||
})
|
||||
return
|
||||
} catch (e) {
|
||||
console.error('[setCredentialPassword] auth.api.updateUser failed, falling back to direct write:', e)
|
||||
}
|
||||
|
||||
// Fallback: write directly with better-auth compatible hash
|
||||
const hashedPassword = await hashPassword(password)
|
||||
const updated = await prisma.account.updateMany({
|
||||
where: { userId, providerId: 'credential' },
|
||||
|
|
|
|||
Loading…
Reference in New Issue