Pending course, rest ready for launch

This commit is contained in:
Marcelo
2026-03-15 13:52:11 +00:00
parent be4ca2ed78
commit 62b3cfe467
77 changed files with 6450 additions and 868 deletions

View File

@@ -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),
};
}