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

PHASE 1 FIX SUMMARY

March 6, 2026 | Production-Ready Access Architecture

βœ… PHASE 1 COMPLETE AND FIXED

All access loops resolved. Role model is deterministic. Login routes normalized.

Issues Fixed

βœ… Access Loop (Company Invitee)

Problem: Company invitee logged in with role "user", got blocked by old permission logic requiring "staff".

Fix: Removed all legacy role checks (user/staff/admin). Now uses explicit scope + role model only.

βœ… Login Route 404

Problem: "Back to Login" button redirected to /admin-login, but route didn't exist or was inconsistent.

Fix: Normalized all login references to use createPageUrl('AdminLogin'). Canonical route: /admin-login

βœ… Legacy Role Logic

Problem: Code mixing old access checks (user/staff/admin) with new scope-based model.

Fix: Removed deprecated minRole param from AdminGuard. All access checks now use getUserScope() + explicit role checks.

Files Changed

components/admin/AdminGuard.jsx

  • ❌ Removed deprecated minRole parameter
  • βœ… Added createPageUrl import
  • βœ… Changed login redirect from hardcoded /admin-login to createPageUrl('AdminLogin')
  • βœ… Added navigate to dependency array

pages/AcceptInvite.jsx

  • βœ… Added createPageUrl import
  • βœ… Changed redirect in success handler from hardcoded /admin-login to createPageUrl('AdminLogin')
  • βœ… Changed "Go to Login" button href from hardcoded to createPageUrl('AdminLogin')
  • βœ… Changed "Log in here" link from hardcoded to createPageUrl('AdminLogin')

entities/User.json

  • βœ… platform_role (explicit platform roles only)
  • βœ… company_role (explicit company roles only)
  • βœ… company_id (required if company_role set)
  • βœ… status (active/inactive/pending_activation)
  • ❌ No legacy "role" field with user/staff/admin

entities/UserInvitation.json

  • βœ… scope (platform | company)
  • βœ… platform_role (if scope=platform)
  • βœ… company_role (if scope=company)
  • βœ… company_id (if scope=company)
  • βœ… token + token_expires_at
  • ❌ No legacy "role" field

Final Role Model

Platform Scope

  • platform_owner β€” Highest platform privilege
  • platform_admin β€” Standard platform admin
  • platform_support β€” Platform support staff

Company Scope

  • company_owner β€” Highest company privilege
  • company_admin β€” Standard company admin
  • fleet_manager β€” Vehicle operations
  • reservations_manager β€” Booking management
  • finance_manager β€” Financial operations
  • support_agent β€” Customer support

Canonical Login Route

Canonical Route:

/admin-login via createPageUrl('AdminLogin')

All buttons/redirects now use:

// Instead of:
href="/admin-login"
navigate("/admin-login")

// Use:
href={createPageUrl('AdminLogin')}
navigate(createPageUrl('AdminLogin'))

Login Redirect Rules

platform_role→ /admin-super-dashboard (Platform Admin)
company_role→ /admin-dashboard (Company Admin)
no scope→ /admin-login (Access Denied)
not authenticated→ /admin-login (Login Page)

Legacy Logic Removed

❌ Removed All Occurrences:

  • role === "user" for admin access checks
  • role === "staff" for permission logic
  • minRole parameter in guards
  • Generic "admin" fallback checks
  • Undefined role helper variables
  • Hardcoded /admin-login strings (use createPageUrl)

Access Control Summary

πŸ“‹ AdminGuard (Base Auth)

Checks: User authenticated + has valid scope

Behavior: Loading UI β†’ scope check β†’ allow/deny with visible UI

πŸ”’ PlatformAdminGuard

Checks: isPlatformAdmin(user)

Behavior: Allow platform scope users only, deny company users with visible error

🏒 CompanyAdminGuard

Checks: isCompanyAdmin(user) OR isPlatformAdmin(user) && impersonatingCompanyId

Behavior: Allow company scope users, allow platform users impersonating company

Validation Checklist

βœ…/admin-login route works (canonical)
βœ…/AdminSuperDashboard loads (platform only)
βœ…/AdminDashboard loads (company only)
βœ…Company invitee no longer gets role="user"
βœ…All login buttons point to canonical route
βœ…No access loops (deterministic routing)
βœ…No legacy role checks (user/staff/admin)
βœ…Visible UI on all error states
βœ…Loading states shown properly

βœ… PHASE 1 STATUS

Production-ready access architecture fully implemented and fixed.

  • βœ… Deterministic scope + role model
  • βœ… Normalized login routes
  • βœ… All legacy role logic removed
  • βœ… Access denied UI visible and helpful
  • βœ… No access loops
  • βœ… Company invitee role properly mapped
  • βœ… Ready for user validation testing