an app to share curated trails sidetrail.app
atproto nextjs react rsc
at main 32 lines 801 B view raw
1import "server-only"; 2import { cookies } from "next/headers"; 3import { getIronSession, IronSession } from "iron-session"; 4import { getCookieSecret } from "./client"; 5 6export interface SessionData { 7 did?: string; 8} 9 10const SESSION_OPTIONS = { 11 cookieName: "sidetrail-session", 12 password: "", 13 cookieOptions: { 14 secure: process.env.NODE_ENV === "production", 15 httpOnly: true, 16 sameSite: "lax" as const, 17 path: "/", 18 }, 19}; 20 21export async function getSession(): Promise<IronSession<SessionData>> { 22 const cookieStore = await cookies(); 23 return getIronSession<SessionData>(cookieStore, { 24 ...SESSION_OPTIONS, 25 password: getCookieSecret(), 26 }); 27} 28 29export async function getCurrentDid(): Promise<string | null> { 30 const session = await getSession(); 31 return session.did || null; 32}