feat: implement full authentication system with middleware protection

- Install @supabase/ssr package for server-side auth
- Create middleware.ts for route protection (redirects to login if not authenticated)
- Fix login page admin check to verify specific user ID
- Add AUTH_SETUP.md with complete setup instructions
- Add setup-admin.sql for database configuration
- Logout button already exists in sidebar
This commit is contained in:
Millian Lamiaux
2026-03-17 10:59:52 +01:00
parent 4c5bcc41c5
commit e0057e18e0
6 changed files with 368 additions and 3 deletions

View File

@@ -23,16 +23,19 @@ export default function LoginPage() {
setError("");
try {
const { error: authError } = await supabase.auth.signInWithPassword({
const { data: authData, error: authError } = await supabase.auth.signInWithPassword({
email,
password,
});
if (authError) throw authError;
if (!authData.user) throw new Error("Login failed");
// Check if the logged-in user is in admin_users table
const { data: adminUser } = await supabase
.from("admin_users")
.select("*")
.eq("id", authData.user.id)
.single();
if (!adminUser) {