fehler 2
This commit is contained in:
parent
166a1b5d06
commit
aec4b93439
|
|
@ -1,7 +1,7 @@
|
||||||
'use server'
|
'use server'
|
||||||
|
|
||||||
import { prisma } from '@innungsapp/shared'
|
import { prisma } from '@innungsapp/shared'
|
||||||
import { auth, getSanitizedHeaders } from '@/lib/auth'
|
import { auth } from '@/lib/auth'
|
||||||
import { revalidatePath } from 'next/cache'
|
import { revalidatePath } from 'next/cache'
|
||||||
import { redirect } from 'next/navigation'
|
import { redirect } from 'next/navigation'
|
||||||
import { headers } from 'next/headers'
|
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.
|
* Sets a credential (email+password) account for a user.
|
||||||
* Tries auth.api.updateUser first (uses better-auth's internal hashing, guaranteed compatible).
|
* Uses direct DB write with better-auth's hashPassword for compatibility.
|
||||||
* Falls back to direct DB write if that fails.
|
|
||||||
*/
|
*/
|
||||||
async function setCredentialPassword(userId: string, password: string) {
|
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 hashedPassword = await hashPassword(password)
|
||||||
const updated = await prisma.account.updateMany({
|
const updated = await prisma.account.updateMany({
|
||||||
where: { userId, providerId: 'credential' },
|
where: { userId, providerId: 'credential' },
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue