initial webapp
This commit is contained in:
26
lib/auth/cookies.ts
Normal file
26
lib/auth/cookies.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { cookies } from 'next/headers';
|
||||
|
||||
const TOKEN_COOKIE_NAME = 'habit-tracker-token';
|
||||
const TOKEN_COOKIE_OPTIONS = {
|
||||
httpOnly: true,
|
||||
secure: process.env.NODE_ENV === 'production',
|
||||
sameSite: 'lax' as const,
|
||||
maxAge: 60 * 60 * 24 * 365, // 1 year
|
||||
path: '/',
|
||||
};
|
||||
|
||||
export async function setTokenCookie(token: string) {
|
||||
const cookieStore = await cookies();
|
||||
cookieStore.set(TOKEN_COOKIE_NAME, token, TOKEN_COOKIE_OPTIONS);
|
||||
}
|
||||
|
||||
export async function getTokenCookie(): Promise<string | undefined> {
|
||||
const cookieStore = await cookies();
|
||||
const cookie = cookieStore.get(TOKEN_COOKIE_NAME);
|
||||
return cookie?.value;
|
||||
}
|
||||
|
||||
export async function deleteTokenCookie() {
|
||||
const cookieStore = await cookies();
|
||||
cookieStore.delete(TOKEN_COOKIE_NAME);
|
||||
}
|
Reference in New Issue
Block a user