Pending course, rest ready for launch
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { createServerClient } from "@supabase/ssr";
|
||||
import { cookies } from "next/headers";
|
||||
import { db } from "@/lib/prisma";
|
||||
import { UserRole } from "@prisma/client";
|
||||
|
||||
export async function requireUser() {
|
||||
const cookieStore = await cookies();
|
||||
@@ -13,6 +14,20 @@ export async function requireUser() {
|
||||
const { data: { user } } = await supabase.auth.getUser();
|
||||
if (!user) return null;
|
||||
|
||||
const profile = await db.profile.findUnique({ where: { id: user.id } });
|
||||
return profile;
|
||||
}
|
||||
const profile = await db.profile.findUnique({ where: { id: user.id } }).catch((error) => {
|
||||
console.error("Failed to load profile for authenticated user.", error);
|
||||
return null;
|
||||
});
|
||||
if (profile) return profile;
|
||||
|
||||
// Keep authenticated flows working even if profile lookup fails.
|
||||
return {
|
||||
id: user.id,
|
||||
email: user.email ?? "unknown@acve.local",
|
||||
fullName: (user.user_metadata?.full_name as string | undefined) ?? null,
|
||||
avatarUrl: null,
|
||||
role: UserRole.LEARNER,
|
||||
createdAt: new Date(0),
|
||||
updatedAt: new Date(0),
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user