17 lines
416 B
TypeScript
17 lines
416 B
TypeScript
import { redirect } from "next/navigation";
|
|
import { supabaseServer } from "@/lib/supabase/server";
|
|
|
|
export const requireUser = async (redirectTo: string) => {
|
|
const supabase = await supabaseServer();
|
|
if (!supabase) {
|
|
return null;
|
|
}
|
|
|
|
const { data } = await supabase.auth.getUser();
|
|
if (!data.user) {
|
|
redirect(`/auth/login?redirectTo=${encodeURIComponent(redirectTo)}`);
|
|
}
|
|
|
|
return data.user;
|
|
};
|