Add lockout logic and email notification utils
All checks were successful
Staging Build / build (push) Successful in 3m34s

This commit is contained in:
DanielS
2026-06-30 22:28:30 +02:00
parent 4927216794
commit 8f447d52e5
2 changed files with 52 additions and 0 deletions

View File

@@ -3,6 +3,7 @@
import { createClient } from '@/lib/supabase/server'
import { createAdminClient } from '@/lib/supabase/admin'
import { headers } from 'next/headers'
import { sendLockoutEmail } from '@/lib/utils/email'
export async function signIn(email: string, password: string) {
try {
@@ -12,6 +13,32 @@ export async function signIn(email: string, password: string) {
password,
})
if (error) {
// Track failed attempts
const { data: usr, error: usrError } = await supabase
.from('users')
.select('failed_attempts, email')
.eq('email', email)
.single()
const attempts = (usr?.failed_attempts ?? 0) + 1
// Update attempts count
await supabase
.from('users')
.update({ failed_attempts: attempts })
.eq('email', email)
// Lock account on 5th failure
if (attempts >= 5) {
await supabase
.from('users')
.update({ role: 'gesperrt' })
.eq('email', email)
// Notify admin
await sendLockoutEmail('info@hephex.de')
return { success: false, error: 'Konto gesperrt nach 5 Fehlversuchen.' }
}
return { success: false, error: error.message }
}