feat: add admin setup page and login redirect for admins

- Add /setup-admin page for first-time admin account creation
- Add /api/admin/setup route (only works when no admin exists)
- Update login to redirect admins to /admin instead of /dashboard
- Setup page creates auth user + profile with is_admin=true

https://claude.ai/code/session_01H2aRGDaKgarPvhay2HxN6Y
This commit is contained in:
Claude
2026-02-10 13:33:52 +00:00
parent 1d0bd349fd
commit 9ae7dd2d2d
3 changed files with 247 additions and 1 deletions

View File

@@ -21,7 +21,7 @@ export default function LoginPage() {
try {
const supabase = createClient();
const { error: authError } = await supabase.auth.signInWithPassword({
const { data: authData, error: authError } = await supabase.auth.signInWithPassword({
email,
password,
});
@@ -35,6 +35,21 @@ export default function LoginPage() {
return;
}
// Vérifier si l'utilisateur est admin pour la redirection
if (authData.user) {
const { data: profile } = await supabase
.from("profiles")
.select("is_admin")
.eq("id", authData.user.id)
.single();
if (profile && (profile as { is_admin?: boolean }).is_admin) {
router.push("/admin");
router.refresh();
return;
}
}
router.push("/dashboard");
router.refresh();
} catch {