Overview
New Expensify uses token-based authentication with automatic session management and reauthentication.Authentication Flow
Session Management
Session Storage
Session data is stored in Onyx:Getting Session Data
Sign In
Basic Sign In
Sign In Implementation
Fromsrc/libs/actions/Session.ts:
Short-Lived Auth Token
For magic links and deep links:Automatic Reauthentication
How It Works
When the server returnsjsonCode: 407 (expired auth token):
- Reauthentication middleware intercepts the response
- Automatically calls
ReauthenticateAPI - Gets new
authToken - Retries the original request
- User never sees an error
Reauthentication Middleware
Fromsrc/libs/Middleware/Reauthentication.ts:
Credentials Storage
Credentials are stored separately from session:Sign Out
Basic Sign Out
Sign Out Implementation
Two-Factor Authentication (2FA)
Enabling 2FA
Validating 2FA Code
Sign In with 2FA
When 2FA is enabled, sign-in is a two-step process:Magic Code / OTP
Request Magic Code
Sign In with Magic Code
Auth Token Management
Including Auth Token in Requests
Auth token is automatically included in all requests:Token Expiration
Auth tokens expire after a period of inactivity:- Expiration: ~30 days of inactivity
- Handling: Automatic reauthentication
- User Impact: Seamless, no action required
Encrypted Auth Token
For sensitive operations (payments, bank accounts):Account Validation
Email Validation
New accounts must validate their email:Adding New Login Method
Handling Deleted Accounts
When an account is deleted (jsonCode 408):Testing Authentication
Mock Session
Mock Sign In
Authentication Best Practices
1. Check Auth State
2. Handle Unauthenticated Users
3. Never Store Passwords
4. Trust Automatic Reauthentication
Security Considerations
Secure Storage
- Auth tokens stored in secure storage on native platforms
- Web uses httpOnly cookies when possible
- Credentials are encrypted before storage
HTTPS Only
All API calls use HTTPS:Token Rotation
Tokens are rotated on:- Sign in
- Reauthentication
- Password change
- Security events
Troubleshooting
Stuck at Login
Reauthentication Loop
407 Errors
- Check that credentials are stored
- Verify password hasn’t changed
- Clear app data and sign in again
Next Steps
API Overview
Learn API fundamentals
API Endpoints
Explore available endpoints
State Management
Understand session in Onyx
Testing
Test authenticated flows
