directus-main — auth & request flow

One route guard, two directions — and the branch a test never covered.

LoginForm.vue knows nothing about how login actually works — it just calls whatever onSubmit function it's given. LoginPage.vue is the one that wires it to a real (simulated) authClient. See System Architecture for where these pieces sit, and Data Model for the Session shape setSession actually stores.

Login

LoginForm submits { email, password }
↓ onSubmit prop — LoginForm never imports authClient itself
LoginPage.handleLogin → authClient.login(credentials)
demo@directus-main.dev / demo1234 auth.setSession(token, expiresAt) → router.push('/')
anything else throws InvalidCredentialsError — LoginForm shows its message, stays on /login

Route Guard (every navigation)

→ / without a session requiresAuth meta + no session → redirected to /login
→ /login while already logged in redirected straight to / — never shows the form again

Logout

HomePage: "Log out" clicked
↓
auth.clearSession() → router.push('/login')
!

Real bug, found while writing a test: the "redirected away from /login when already authenticated" branch above had zero test coverage — unlike a genuinely untestable branch elsewhere in this app, this one just hadn't gotten a test yet. Writing it exposed a real, previously-silent defect: earlier tests' mounted App instances were never unmounted, and since they all shared one router singleton, their stale RouterView registrations interfered with the new test. Fixed with @vue/test-utils's enableAutoUnmount(afterEach), then applied to every test file with the same latent risk — not just the one that had actually failed. See Testing Strategy for the full test-layer picture this bug came out of.