# Authentication & Session Handling

> Email, social and passwordless sign-in, OAuth with PKCE, token storage and refresh, and gating the app on auth state. Free notes, key concepts, resources and a...

Canonical: https://www.internhack.in/roadmaps/tracks/mobile/authentication
Last updated: 2026-11-28

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](https://www.internhack.in/roadmaps/tracks/mobile/navigation), [Local Storage: Key-value, SQLite & Files](https://www.internhack.in/roadmaps/tracks/mobile/local-storage)

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](https://docs.expo.dev/develop/authentication/) (Expo)
- [OAuth 2.0: PKCE](https://oauth.net/2/pkce/) (oauth.net)
- [Firebase Authentication](https://firebase.google.com/docs/auth) (Firebase)

Previous: [Backend-as-a-Service: Firebase & Supabase](https://www.internhack.in/roadmaps/tracks/mobile/baas) · Next: [Push & Local Notifications](https://www.internhack.in/roadmaps/tracks/mobile/push-notifications)

## More in Backend Services, Auth & Notifications

- [Backend-as-a-Service: Firebase & Supabase](https://www.internhack.in/roadmaps/tracks/mobile/baas)
- [Authentication & Session Handling](https://www.internhack.in/roadmaps/tracks/mobile/authentication)
- [Push & Local Notifications](https://www.internhack.in/roadmaps/tracks/mobile/push-notifications)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [Mobile App Developer Roadmap](https://www.internhack.in/roadmaps/tracks/mobile)
