Prompt
I’m building a mobile app with Apple sign-in and email/password login. How should I design the auth flow?
Latest observation
A good mobile auth flow should be simple for users, secure by default, and easy to extend. Since you have both Sign in with Apple and email/password, the best design is usually:
1) Use one account system, multiple login methods
Treat Apple sign-in and email/password as different ways to authenticate the same user account.
- One backend user record
- A user can have:
- Apple identity
- email/password credential
- optional verified email
- If the same person uses both, let them link methods to one account
This avoids duplicate accounts and confusion.
2) Recommended sign-in screen structure
On the mobile app’s auth screen:
- Continue with Apple
- Sign in with Email
- Create account with Email
- Optionally: “Forgot password?”
Keep Apple as a prominent option on iOS. If your app is iOS-only, Apple sign-in should be very easy to access.
3) Typical backend auth architecture
Use a backend-issued session/token model:
Option A: OAuth/OpenID Connect + JWTs
- Apple returns an identity token
- Your backend verifies it with Apple
- Your backend issues:
- short-lived access token
- refresh token
- Mobile app stores tokens securely in Keychain
Option B: Managed auth provider
Examples: Auth0, Firebase Auth, Cognito, Clerk, Supabase Auth
This is often the fastest route because they already handle:
- Apple login
- email/password
- token issuance
- account linking
- password reset
- email verification
If you’re shipping quickly, a managed provider is usually the best choice.
4) How the flows should work
Apple sign-in flow
- User taps Continue with Apple
- Apple shows consent screen
- App receives Apple identity token + authorization code
- Backend verifies token with Apple
- Backend finds or creates the user
- Backend returns app session tokens
- App logs in
Important:
- Use the Apple
subclaim as the stable Apple user identifier - Don’t rely only on email from Apple, because it may be hidden or relay-based
- Ask for name only on first sign-in if needed
Email/password sign-up flow
- User enters email/password
- Backend creates account
- Send verification email
- Until email is verified, limit sensitive actions if needed
- On verification, issue session tokens or allow login
Security basics:
- Hash passwords with Argon2id, bcrypt, or scrypt
- Enforce strong password policy
- Rate-limit sign-up and login attempts
Email/password sign-in flow
- User enters email/password
- Backend verifies credentials
- Backend checks account status
- Return session tokens
- App stores them securely
5) Account linking strategy
This is the part that often causes problems, so design it explicitly.
Best practice
If an Apple login uses an email that matches an existing email/password account:
- Don’t automatically merge accounts just by email alone
- Require proof of ownership of the existing account, or ask the user to log in first and then link Apple
Why?
- Apple may provide private relay emails
- Email alone is not always a safe unique identifier across providers
- Automatic merging can create account takeover risk
Safer linking flow
If user is already signed in with email/password:
- In settings, choose Link Apple account
- Apple login completes
- Backend links Apple
subto the current account
If user signs in with Apple first:
- Create/find account using Apple
sub - If later they want email/password too, let them add and verify an email, then set a password
6) Handle “Hide My Email” properly
Apple may give:
- real email
- private relay email
- no email on subsequent logins
So:
- Use Apple’s stable user ID (
sub) as the primary Apple identity key - Don’t depend on Apple email to identify the account later
- Store whichever email Apple provides as a contact field, not as the identity key
7) Session management on mobile
Use:
- short-lived access token
- refresh token with rotation
- store refresh token in Keychain
- access token can live in memory, or also Keychain if needed
Recommended:
- refresh token rotation
- revoke refresh tokens on logout
- support remote session revocation if a device is lost
8) Password reset flow
For email/password users:
- User requests reset
- Send email with one-time reset link or code
- User sets new password
- Invalidate existing sessions if appropriate
If the account was originally created with Apple only and no password exists, show:
- “Use Apple to sign in”
- or “Add email/password to your account” if they want that option
9) UX recommendations
A clean mobile auth UX usually includes:
- one screen with Apple + email options
- minimal form fields
- clear error messages
- automatic progress after successful sign-in
- no unnecessary account creation distinction unless needed
- if password login fails, suggest Apple login only if that account is linked
Examples:
- “Continue with Apple”
- “Sign in with email”
- “Create account”
- “Forgot password?”
10) Security checklist
- Verify Apple tokens server-side
- Never trust the client alone
- Use Keychain for token storage
- Hash passwords securely
- Rate-limit login and reset endpoints
- Use TLS everywhere
- Add email verification
- Consider MFA for sensitive apps
- Log auth events for fraud detection
- Support account deletion and data export if needed
11) A practical recommended design
If I were designing this from scratch, I’d do:
Frontend
- Apple button
- Email sign-in / sign-up
- Forgot password
- Link account UI in settings
Backend
- Single user table
- Separate identity table:
- provider = apple / password
- provider_user_id = Apple
subor internal password credential
- Session table / refresh tokens
- Email verification and password reset tables
Rules
- Apple identity maps to one user
- Email/password maps to one user
- Link identities only after explicit user action or authenticated proof
- Never auto-merge by email alone
12) If you want the simplest implementation
Use a managed auth provider and configure:
- Apple provider
- email/password provider
- account linking
- email verification
- password reset
- token/session handling
That will save you a lot of edge-case handling.
If you want, I can also give you:
- a sample auth state diagram,
- a backend database schema, or
- a React Native / Swift implementation outline.