19 lines
530 B
TypeScript
19 lines
530 B
TypeScript
import { cookies } from 'next/headers'
|
|
|
|
const LAST_PRODUCT_COOKIE = 'lastProductId'
|
|
const THIRTY_DAYS_SECONDS = 60 * 60 * 24 * 30
|
|
|
|
export async function setLastProductCookie(productId: string) {
|
|
const store = await cookies()
|
|
store.set(LAST_PRODUCT_COOKIE, productId, {
|
|
httpOnly: true,
|
|
sameSite: 'lax',
|
|
maxAge: THIRTY_DAYS_SECONDS,
|
|
path: '/',
|
|
})
|
|
}
|
|
|
|
export async function getLastProductCookie(): Promise<string | null> {
|
|
const store = await cookies()
|
|
return store.get(LAST_PRODUCT_COOKIE)?.value ?? null
|
|
}
|