import "server-only" import { cache } from "react" import { redirect } from "next/navigation" import { createClient } from "@/lib/supabase/server" export const getSession = cache(async () => { const supabase = await createClient() const { data: { user } } = await supabase.auth.getUser() return user }) export const getProfile = cache(async () => { const user = await getSession() if (!user) return null const supabase = await createClient() const { data } = await supabase .from("profiles") .select("role, name, email, terms_accepted_at") .eq("id", user.id) .single() return data }) export const verifySession = cache(async () => { const user = await getSession() if (!user) redirect("/") const profile = await getProfile(); if(!profile) redirect("/") return { userId: user.id, name: profile.name, email: profile.email, role: profile.role, isLoggedIn: true, isAdmin: profile.role === "admin", isClient: profile.role === "client", hasAcceptedTerms: profile.terms_accepted_at != null, } })