Next · Unreleased

Working-tree content. Subject to change and not yet released. Commit: e3d4530507.

Feature — Auth

Sign-in, sign-up, sign-out, and the user profile screen. Session is persisted in MMKV. Backed by a mock API today; swap to a real backend by editing api.ts only.

Files

src/features/auth/
  api.ts                              # mock signIn/signUp/signOut
  mappers.ts                          # SessionDto -> Session
  types.ts                            # User, Session, payloads
  queries.ts                          # useSignInMutation, useSignUpMutation, useSignOutMutation
  store.ts                            # zustand + MMKV (session)
  components/AuthForm.tsx             # email + password (+ name) form
  screens/SignInScreen.tsx
  screens/SignUpScreen.tsx
  screens/ProfileScreen.tsx

Routes:

Types at a glance

Auth store

interface AuthState {
  session: Session | null;
  hydrated: boolean;
  setSession: (s: Session | null) => void;
  signOut: () => void;
  setHydrated: () => void;
}
  • MMKV key: auth
  • partialize whitelists only session — hydrated is local-only.
  • onRehydrateStorage calls setHydrated() so screens can wait for storage if needed (currently MMKV is synchronous so this fires immediately).

Mutations

The screen never calls router.replace. It just runs the mutation; setSession updates the store, the root layout's <Stack.Protected guard={hasCompleted && !!session}> becomes the active block, and Expo Router mounts (app)/(tabs). See routing.md for the full guard model.

useSignOutMutation additionally calls queryClient.clear() so cached server data doesn't leak between users.

Form

AuthForm is shared between sign-in and sign-up — the mode prop conditionally shows the displayName field. The parent owns the mutation; the form is a controlled trio of inputs + submit button.

Mock API behaviour

api.ts simulates latency (400-800 ms) and rejects obviously bad inputs (no @, too-short password, empty display name). It returns a generated SessionDto so the rest of the stack can be exercised without a backend.

When wiring to a real API:

  1. Replace bodies of signInRequest / signUpRequest / signOutRequest with apiClient.post(...) / .delete(...) calls.
  2. Make sure the DTO shape from the server matches SessionDto; if not, adjust types.ts + mappers.ts.
  3. Add apiClient getAuthToken: () => useAuthStore.getState().session?.accessToken so subsequent calls are authenticated.

Profile screen

Reads useAuthStore().session for display and exposes:

  • Sign out → useSignOutMutation.mutate(). Mutation's onSuccess flips session to null; root layout's <Stack.Protected> swaps to (auth)/sign-in. No router call.
  • Reset onboarding flow → closes paywall, useOnboardingStore.getState().reset(), useTutorialStore.getState().reset(), and signOut(). The onboarding guard has the highest priority, so the root layout mounts (onboarding) for the full onboarding → paywall → tutorial sequence. No router call.

Tablet layout (components/profile-tablet-layout.ts, Figma "Profile - iPad A16"): the top bar (Go Premium + settings gear) sits 24 off the screen's top and right edges, and the Recent Song card's difficulty chip hugs its word with the label at 14. The phone keeps its own layout.