Gating the App on Auth

One gate to rule the app

You now have a vault, a session, and a login screen. The last piece decides which world the user sees β€” and it lives in exactly one place: ContentView, the root view. It reads AuthSession from the environment and branches:

  • Still restoring? Show a bare Brand.canvas β€” a calm blank in the app's background color. Not a spinner: restore() usually finishes in a blink, and a flash of spinner looks like jank. Crucially, not the login screen either β€” flashing "Log in" at someone who is already signed in feels broken.
  • Signed in? Route by role, in one if: a .walker gets WalkerHomeView (the walker's dashboard β€” you'll dig into it in a later module), everyone else gets the HomeView you know.
  • Otherwise: AuthView.

Nobody navigates between these worlds. When currentUser changes β€” login, logout, a 401 tripwire β€” signedIn changes, ContentView re-evaluates, and SwiftUI swaps the entire tree. Log out from five screens deep and the whole stack simply ceases to exist.

Note the optional chaining in the role check: auth.currentUser?.role == .walker. If currentUser were somehow nil, the comparison is just false β€” no crash, owner path wins.