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