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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user