Authentication & Session Handling
Email, social and passwordless sign-in, OAuth with PKCE, token storage and refresh, and gating the app on auth state.
Intermediate · about 8 hours · difficulty 4/5
Learn first: Navigation Patterns, Local Storage: Key-value, SQLite & Files
Authentication on mobile is harder than on the web because the app is a public client: anything shipped inside it can be extracted. Get the fundamentals right.
Sign-in methods
- Email and password or passwordless (magic links, one-time codes).
- Social login: Sign in with Apple (required on iOS if you offer other social logins), Google Sign-In.
- Passkeys: phishing-resistant, increasingly supported on both platforms.
OAuth 2.0 and OpenID Connect
Use the Authorization Code flow with PKCE, opening the provider in the system browser (expo-auth-session, AppAuth). Never embed a client secret in the app, and avoid collecting third-party passwords in your own WebView.
Tokens and sessions
- A short-lived access token authorises API calls; a refresh token gets new access tokens.
- Store tokens in secure storage (Keychain/Keystore), not plain storage.
- Refresh proactively or on
401, making sure concurrent requests share one refresh. - On logout: clear tokens, caches and any user data on the device.
App structure
Hold auth state in one place, show a splash while restoring the session on launch, and route users to the auth or main stack accordingly.
Good enough to move on: your app supports one social login and email sign-in, survives restarts without re-login, and refreshes tokens transparently.
Key concepts
- Email, password and passwordless
- Sign in with Apple and Google
- OAuth 2.0 with PKCE
- Access and refresh tokens
- Secure token storage
- Session restore on launch
- Passkeys
- Multi-factor authentication
Mini project
Add auth to your grocery app: Google or Apple sign-in, persisted session in secure storage, automatic token refresh, and a clean logout.
Check yourself
Why must a mobile app use PKCE instead of a client secret for OAuth?
Free resources
- Expo: Authentication (Expo)
- OAuth 2.0: PKCE (oauth.net)
- Firebase Authentication (Firebase)