Files
Reactive-Resume/apps/web/src/libs/auth/session.ts
T
Amruth Pillai 50ba37a27f v5.1.0 (#2970)
* chore(release): v5.1.0

* feat: implement resume thumbnails

* fix: remove unused mcp tools

* docs: fix formatting of docs
2026-05-07 15:12:33 +02:00

26 lines
1.1 KiB
TypeScript

// Isomorphic getSession.
// On the server, calls Better Auth's server API directly (uses request headers).
// On the client, calls the auth client's getSession over fetch.
//
// This lives in apps/web (not @reactive-resume/auth) because @reactive-resume/auth
// is server-only — importing its `auth` instance into client code drags in
// drizzle/pg/jose and triggers TanStack Start's client/server import-protection
// (the "tanstack-start-injected-head-scripts" virtual-module error).
import type { AuthSession } from "@reactive-resume/auth/types";
import { createIsomorphicFn } from "@tanstack/react-start";
import { getRequestHeaders } from "@tanstack/react-start/server";
import { auth } from "@reactive-resume/auth/config";
import { authClient } from "./client";
export const getSession = createIsomorphicFn()
.client(async (): Promise<AuthSession | null> => {
const { data, error } = await authClient.getSession();
if (error) return null;
return data as AuthSession;
})
.server(async (): Promise<AuthSession | null> => {
const result = await auth.api.getSession({ headers: getRequestHeaders() });
return result as AuthSession | null;
});