fix: use admin_users table in passwort route
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
5b82ad93b3
commit
20f8a0a0f0
|
|
@ -16,14 +16,14 @@ export async function POST(req: NextRequest) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const db = createServiceClient()
|
const db = createServiceClient()
|
||||||
const { data: admin } = await db.from('admins').select('password_hash').eq('id', session.id).single()
|
const { data: admin } = await db.from('admin_users').select('password_hash').eq('id', session.id).single()
|
||||||
if (!admin) return NextResponse.json({ error: 'Admin nicht gefunden.' }, { status: 404 })
|
if (!admin) return NextResponse.json({ error: 'Admin nicht gefunden.' }, { status: 404 })
|
||||||
|
|
||||||
const ok = await bcrypt.compare(currentPassword, admin.password_hash)
|
const ok = await bcrypt.compare(currentPassword, admin.password_hash)
|
||||||
if (!ok) return NextResponse.json({ error: 'Aktuelles Passwort ist falsch.' }, { status: 401 })
|
if (!ok) return NextResponse.json({ error: 'Aktuelles Passwort ist falsch.' }, { status: 401 })
|
||||||
|
|
||||||
const hash = await bcrypt.hash(newPassword, 10)
|
const hash = await bcrypt.hash(newPassword, 10)
|
||||||
const { error } = await db.from('admins').update({ password_hash: hash }).eq('id', session.id)
|
const { error } = await db.from('admin_users').update({ password_hash: hash }).eq('id', session.id)
|
||||||
if (error) return NextResponse.json({ error: error.message }, { status: 500 })
|
if (error) return NextResponse.json({ error: error.message }, { status: 500 })
|
||||||
|
|
||||||
return NextResponse.json({ success: true })
|
return NextResponse.json({ success: true })
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue