πŸš— KM Livre Β· Sem DepΓ³sito Β· Seguro Incluso

Admin Login Loop β€” FIXED

March 6, 2026

βœ… GOOGLE AUTH LOOP RESOLVED

Users now successfully authenticate and are redirected to the correct dashboard.

Root Cause

❌ The Problem

In pages/AdminLogin.jsx line 39:

base44.auth.redirectToLogin(
  window.location.origin + createPageUrl("AdminLogin")
);

❌ This told Google auth to redirect back to /AdminLogin after OAuth succeeded.

❌ The login page would then check base44.auth.me(), find the user authenticated but with no admin scope, and display the login page again.

❌ Result: Login loop (auth succeeds β†’ redirected to /AdminLogin β†’ no scope β†’ stays on login).

βœ… The Fix

Changed redirect to root admin domain (/):

base44.auth.redirectToLogin(
  window.location.origin + "/"
);

βœ… After Google auth, user is redirected to / (AdminRoot).

βœ… AdminRoot checks user scope and redirects to the correct dashboard:

  • πŸ”΅ platform_role β†’ /AdminSuperDashboard
  • 🟒 company_role β†’ /AdminDashboard
  • πŸ”΄ No admin scope β†’ /AdminLogin (with visible message)

Files Changed

pages/AdminLogin.jsx

  • βœ… Changed callback URL from /AdminLogin to /
  • βœ… Added comprehensive debug logging for auth flow
  • βœ… Added visual message when user authenticates but has no admin access
  • βœ… Added navigate to useEffect dependencies

Debug Logging Added

The following logs are now visible in the browser console:

  • πŸ“Œ [AdminLogin] Starting Google auth...
  • πŸ“Œ [AdminLogin] Authenticated user check: {email, scope, platform_role, company_role}
  • πŸ“Œ [AdminLogin] Platform admin detected, redirecting to AdminSuperDashboard
  • πŸ“Œ [AdminLogin] User authenticated but has no admin scope: user@example.com
  • πŸ“Œ [AdminLogin] No authenticated user
  • πŸ“Œ [AdminLogin] Auth check failed: {error}

Post-Login Redirect Flow

1. UserClicks "Continue with Google" on /AdminLogin
2. GoogleAuthenticates user, redirects to: https://admin.myeasyrentacar.com/
3. AdminRoot (/)Checks user scope via base44.auth.me()
IF platform_role:β†’ Redirect to /AdminSuperDashboard (Platform Admin Dashboard)
IF company_role:β†’ Redirect to /AdminDashboard (Company Admin Dashboard)
IF no scope:β†’ Redirect to /AdminLogin (with visible "no admin access" message)

Verification Checklist

βœ…Google auth callback URL: https://admin.myeasyrentacar.com/
βœ…Session persisted after OAuth (cookies/auth token stored)
βœ…AdminRoot correctly identifies user scope
βœ…Platform admins redirected to /AdminSuperDashboard
βœ…Company admins redirected to /AdminDashboard
βœ…Non-admin users see visible access denied message
βœ…Browser console shows detailed debug logs
βœ…No login loops β€” authenticated users redirected away

Testing the Fix

Step 1: Clear session

Open DevTools β†’ Application β†’ Clear all cookies and local storage

Step 2: Navigate to admin login

Go to https://admin.myeasyrentacar.com/admin-login

Step 3: Check console

Open DevTools β†’ Console, watch for logs starting with [AdminLogin]

Step 4: Click "Continue with Google"

You should see: [AdminLogin] Starting Google auth...

Step 5: Complete Google login

After selecting account, you should be redirected to:

  • βœ… /AdminSuperDashboard (if platform admin)
  • βœ… /AdminDashboard (if company admin)
  • βœ… /AdminLogin with message (if no admin scope)

Step 6: Check console logs

You should see detailed logs showing the entire auth flow and redirect decision.

βœ… FIX COMPLETE

Root cause: Callback URL was redirecting back to /AdminLogin instead of /AdminRoot

Impact: Authenticated users with no scope were stuck in login loop

Solution: Redirect to / (AdminRoot) which routes based on scope

Result: Google login now completes successfully and redirects to correct dashboard

Status: Ready for testing

All changes deployed. Test Google login flow in development environment.