Fix admin redirect by using isAdmin from auth context instead of user_metadata.role
The root cause was that ProtectedRoute and Auth.tsx were checking user.user_metadata?.role, but the admin role is stored in the user_roles table, not in user metadata. Changes: - ProtectedRoute: Use isAdmin flag from useAuth context instead of user.user_metadata?.role - Auth.tsx: Use isAdmin flag for role-based redirect logic - Remove redundant auth checks from individual admin/member pages (ProtectedRoute handles it) - Add isAdmin to useEffect dependencies to ensure redirect happens after admin check completes This fixes the issue where admins were being redirected to /dashboard instead of /admin after login, because the role check was happening before the async admin role lookup completed. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -15,12 +15,6 @@ export default function AdminSettings() {
|
||||
const { user, isAdmin, loading: authLoading } = useAuth();
|
||||
const navigate = useNavigate();
|
||||
|
||||
useEffect(() => {
|
||||
if (!authLoading) {
|
||||
if (!user) navigate('/auth');
|
||||
else if (!isAdmin) navigate('/dashboard');
|
||||
}
|
||||
}, [user, isAdmin, authLoading, navigate]);
|
||||
|
||||
if (authLoading) {
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user