AuthContext wraps the entire app and exposes user state and auth actions to all components. Customer profiles are auto-created in the customer_profiles table on every signup via an upsert.
Routes
| Route | Component | Auth Required |
|---|---|---|
/login | Login (src/pages/auth/Login.tsx) | No |
/signup | SignUp (src/pages/auth/SignUp.tsx) | No |
/profile | Profile | Yes |
/orders | Orders | Yes |
/loyalty | Loyalty | Yes |
Service Functions
All auth operations are insrc/services/auth.service.ts:
Auto-Profile Creation on Signup
After a successfulsupabase.auth.signUp(), signUp() immediately calls createCustomerProfile() with an upsert (not insert), making signup idempotent:
id equals auth.uid() — enforced by the customer_profiles table schema and RLS policies.
AuthContext
AuthContext (src/contexts/AuthContext.tsx) is provided at the top of the provider tree (inside BrowserRouter, wrapping QueryClientProvider):
useAuth() hook:
ProtectedRoute Component
ProtectedRoute (src/components/auth/ProtectedRoute.tsx) wraps routes that require authentication:
- While
loading === true, renders a full-page skeleton/spinner - If
user === null, redirects to/loginwithstate={{ from: location }}so the user returns to their intended destination after login - If authenticated, renders
children
CustomerProfile Interface
The profile data stored in customer_profiles and exposed via AuthContext. Defined in src/types/customer.ts:
The loyalty tier field is named
tier, not customer_tier. The points field is a cached balance — authoritative balance comes from the get_customer_points_balance RPC.Account Status (God Mode)
Theaccount_status field on customer_profiles is managed exclusively by admins via the God Mode feature in AdminCustomerDetails:
Ban
Sets
account_status = 'banned'. The customer can no longer log in or access protected routes.Suspend
Sets
account_status = 'suspended'. Temporary restriction — the admin can lift it at any time.The storefront does not currently enforce
account_status checks on the client side. Status enforcement is primarily at the Supabase RLS policy level and admin interface.Password Reset Flow
Request reset
The login page includes a “Forgot password” link. The user enters their email and
resetPassword(email) is called.Supabase sends email
Supabase Auth emails a magic link with
redirectTo: ${window.location.origin}/login.User clicks link
The link redirects back to
/login with a Supabase session token in the URL hash, which the auth listener in AuthContext picks up.