feat: add src/lib/auth.ts
This commit is contained in:
parent
0319eb9f9d
commit
ba63c93d6c
|
|
@ -0,0 +1,26 @@
|
||||||
|
import { cookies } from 'next/headers';
|
||||||
|
|
||||||
|
const SESSION_COOKIE = 'admin_session';
|
||||||
|
const SESSION_SECRET = 'marines-agen-secret-2024';
|
||||||
|
|
||||||
|
export function createSession(): void {
|
||||||
|
const cookieStore = cookies();
|
||||||
|
cookieStore.set(SESSION_COOKIE, SESSION_SECRET, {
|
||||||
|
httpOnly: true,
|
||||||
|
secure: process.env.NODE_ENV === 'production',
|
||||||
|
sameSite: 'lax',
|
||||||
|
maxAge: 60 * 60 * 8, // 8 hours
|
||||||
|
path: '/',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function destroySession(): void {
|
||||||
|
const cookieStore = cookies();
|
||||||
|
cookieStore.delete(SESSION_COOKIE);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isAuthenticated(): boolean {
|
||||||
|
const cookieStore = cookies();
|
||||||
|
const session = cookieStore.get(SESSION_COOKIE);
|
||||||
|
return session?.value === SESSION_SECRET;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue