Files
beenvoice-web/src/lib/auth-server.ts
T
soconnorandCursor 31151e7f39 Sync time entries with invoice lines and harden auth for mobile.
Link clocked time to invoice items with bidirectional sync, add entry editing on web, broaden session cookie detection for Expo clients, and handle API rate limits without signing users out.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-28 21:44:19 -04:00

32 lines
859 B
TypeScript

import { headers as nextHeaders } from "next/headers";
import { auth } from "~/lib/auth";
export function hasSessionCookie(headers: Headers): boolean {
const cookie = headers.get("cookie") ?? "";
if (!cookie.trim()) return false;
return (
cookie.includes("session_token=") ||
cookie.includes("session_data=") ||
cookie.includes("better-auth.session_token=") ||
cookie.includes("__Secure-better-auth.session_token=")
);
}
export async function getOptionalServerSession(headers: Headers) {
if (!hasSessionCookie(headers)) {
return null;
}
try {
return await auth.api.getSession({ headers });
} catch (error) {
console.error("[auth] Failed to resolve session:", error);
return null;
}
}
export async function getOptionalServerSessionFromHeaders() {
return getOptionalServerSession(await nextHeaders());
}