diff --git a/src/lib/auth.ts b/src/lib/auth.ts index 68c749f..8db19c0 100644 --- a/src/lib/auth.ts +++ b/src/lib/auth.ts @@ -1,4 +1,4 @@ -import { createServerFn } from "@tanstack/react-start"; +import { createServerFn, createServerOnlyFn } from "@tanstack/react-start"; import { z } from "zod"; import { toLocalDateTimeString } from "@/lib/datetime"; @@ -41,12 +41,12 @@ function toPerfil(row: PerfilRow): Perfil { }; } -async function getSessionUserId(): Promise { +const getSessionUserId = createServerOnlyFn(async (): Promise => { const { getSessionUserId: getServerSessionUserId } = await import("@/lib/auth.server"); return await getServerSessionUserId(); -} +}); -async function fetchSessionProfile(userId: string): Promise { +const fetchSessionProfile = createServerOnlyFn(async (userId: string): Promise => { const [{ getPool, sql }] = await Promise.all([import("@/lib/db.server")]); const pool = await getPool(); @@ -82,7 +82,7 @@ async function fetchSessionProfile(userId: string): Promise admin: Boolean(row.admin), perfil, }; -} +}); async function requireSession(): Promise { const userId = await getSessionUserId();