first commit
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
'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')
|
||||
}
|
||||
Reference in New Issue
Block a user