Files
2026-06-03 04:11:30 +03:00

34 lines
883 B
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
'use server'
import { cookies } from 'next/headers'
import { redirect } from 'next/navigation'
export async function login(prevState: any, formData: FormData) {
const username = formData.get('username')
const password = formData.get('password')
if (
username === process.env.ADMIN_USERNAME &&
password === process.env.ADMIN_PASSWORD
) {
const cookieStore = await cookies()
cookieStore.set('admin_session', process.env.ADMIN_SECRET || 'secret', {
httpOnly: true,
secure: process.env.NODE_ENV === 'production',
sameSite: 'lax',
path: '/',
maxAge: 60 * 60 * 24 * 7 // 1 week
})
redirect('/admin')
} else {
return { error: 'Geçersiz kullanıcı adı veya şifre' }
}
}
export async function logout() {
const cookieStore = await cookies()
cookieStore.delete('admin_session')
redirect('/admin/login')
}