From 073dc99860eeb01744a9fe3f3d2bcd193f0fefc7 Mon Sep 17 00:00:00 2001 From: DanielS Date: Thu, 20 Aug 2026 17:44:30 +0200 Subject: [PATCH] chore(auth): add 2FA database logging - capture and log insert errors during 2FA code generation - print verification queries and lookup parameters to console --- shop/lib/actions/auth.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/shop/lib/actions/auth.ts b/shop/lib/actions/auth.ts index 49df9e4..a523ab0 100644 --- a/shop/lib/actions/auth.ts +++ b/shop/lib/actions/auth.ts @@ -185,9 +185,16 @@ async function send2FACodeInternal(userId: string, deviceHash: string, email: st .eq('device_hash', deviceHash) // Neuen Code speichern - await adminClient + const { data: insData, error: insError } = await adminClient .from('device_verification_codes') .insert({ user_id: userId, code, device_hash: deviceHash, expires_at: expiresAt }) + .select() + + if (insError) { + console.error("2FA CODE INSERT ERROR:", insError) + } else { + console.log("2FA CODE INSERTED:", code, insData) + } // Mail senden await sendMail({ @@ -222,6 +229,7 @@ export async function verifyDevice2FA(userId: string, code: string, deviceHash: const cleanCode = code.trim() // Code prüfen (unter Berücksichtigung von Leerzeichen & device_hash) + console.log("VERIFYING 2FA: userId =", userId, "code =", cleanCode) const { data: codeEntries, error: codeError } = await adminClient .from('device_verification_codes') .select('*') @@ -231,6 +239,7 @@ export async function verifyDevice2FA(userId: string, code: string, deviceHash: .limit(1) const codeEntry = codeEntries && codeEntries.length > 0 ? codeEntries[0] : null + console.log("VERIFY 2FA DB RESULT: entry =", codeEntry, "error =", codeError) if (codeError || !codeEntry) { // Doppelklick- & Race-Condition Schutz: Prüfen ob das Gerät eben bereits verifiziert wurde