Authentication
Overview
Authentication is managed by AuthProvider in src/context/auth-context.tsx. It provides JWT token state, user profile, and sign-in/sign-out functions to the entire app.
Auth Context API
interface AuthContextValue {
signIn: (token: string, isSignup?: boolean) => Promise<void>;
signInWithUserPayload: (token: string, userPayload: Record<string, unknown>, isSignup?: boolean) => Promise<void>;
signOut: () => Promise<void>;
refreshUser: () => Promise<void>;
token: string | null;
user: User | null;
isLoading: boolean;
}signIn— Saves token, fetches user profile from API, identifies in MixpanelsignInWithUserPayload— Used for SSO flows where the user data comes with the login response. Sets user immediately from payload, then refreshes from API in the backgroundsignOut— Deletes token from secure storage, clears user staterefreshUser— Re-fetches user profile using the stored token
Token Storage
JWTs are stored in expo-secure-store via src/lib/token-storage.ts:
getToken()— Read from secure storage (key:jwt_token)setToken(token)— Write to secure storagedeleteToken()— Remove from secure storage
On app launch, AuthProvider checks for a stored token and fetches the user profile. The splash screen stays visible until this completes.
Sign-In Flows by Region
UK Sign-In
Defined in src/features/auth/components/uk-sign-in.tsx. Options:
- Email + Password — Standard login via
apiV1 - Google Sign-In — Via
@react-native-google-signin/google-signin(requires development build) - Apple Sign-In — Via
expo-apple-authentication(iOS only) - Sign Up — Routes to
/uk-sign-upwith multi-step form
US Sign-In
Defined in src/features/auth/components/us-sign-in.tsx. Options:
- SSO Login — University SSO via
my.UNL(redirects to university login page)
Routes to /(auth)/sso-login.tsx for the SSO WebView flow.
Apple Sign-In Flow
Implemented in src/lib/apple-signin.ts:
- Request Apple authentication credentials (name + email)
- POST to
apiV1atappleSignin.phpwith{ name, email, userID } - If response type is
"login"— callsignIn(token)and navigate to explore - If response type is
"signup"or 404 — redirect to/uk-sign-upwith Apple user data pre-filled - If 403 — account blocked alert
Google Sign-In Flow
Implemented in src/lib/google-signin.ts:
- Configure Google Sign-In with web/iOS client IDs and birthday/phone scopes
- Sign in via
GoogleSignin.signIn() - Fetch birthday and phone from Google People API using the access token
- POST to
apiV1atgoogleSignin.phpwith{ idToken, user, birthday } - If
"existingUser"— callsignIn(token)and navigate to explore - If
"newUser"or 404 — redirect to/uk-sign-upwith Google user data pre-filled
Google Sign-In is not available in Expo Go (requires a development build). The module is dynamically imported to avoid crashes.
Auth Routes
src/app/(auth)/
_layout.tsx # Auth stack layout
forgot-password.tsx # Forgot password form
forgot-password-otp.tsx # OTP verification for password reset
reset-password.tsx # New password entry
uk-sign-up.tsx # UK multi-step signup
verify-otp.tsx # OTP verification
sso-login.tsx # US SSO WebView loginRoute Protection
The NavigationGuardProvider in src/context/navigation-guard-context.tsx intercepts navigation to protected routes. If a user is not authenticated, they are redirected to /sign-in.
Protected routes: events, wallet, profile, viewings, bills, roomie, rideshare.
The custom tab bar also uses useNavigationGuard to gate tab presses.
User Type
The User interface is defined in src/features/auth/types/index.ts and mapped from the v1 API response via mapUserApiResponseToUser().