feat(auth): add shared authentication state and user-session model - #34
Open
ayushtr-aws wants to merge 1 commit into
Conversation
Introduce a framework-agnostic auth model under src/auth: - Typed signedIn, signedOut, loading, and expired-session states as a discriminated AuthState union, with User/UserSession types and authState constructors. - Validation helpers: isValidEmail, isValidPassword, isValidUser, isValidSession, isSessionExpired, isSessionActive, deriveAuthState, isAuthenticated. - Focused unit tests (vitest) covering all states and helpers. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Task-Id: 01KZXZN46CAW1WYDYS07APWMT7 Prompt-Version: 1c9c10e027a2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements TG-15: Define authentication state and user session model from the Add user sign-in functionality epic.
Adds a framework-agnostic authentication and user-session model under
soccer-app/src/auth/that both the UI and service layer can consume:types.ts— Typed states as a discriminatedAuthStateunion:loading,signedOut,signedIn(carries aUserSession), andexpired(carries theUser). IncludesUser,UserSession, andAuthStatustypes, plusauthStateconvenience constructors.validation.ts— Pure validation/derivation helpers:isValidEmail,isValidPassword,isValidUser,isValidSession,isSessionExpired,isSessionActive,deriveAuthState, andisAuthenticated.index.ts— Public barrel export for the module.auth.test.ts— 22 focused unit tests covering every state constructor and helper (valid/invalid/expired paths).Naming, routes, fields and shapes follow the shared orchestration context so they align with sibling sub-issues.
Tooling
vitestas a dev dependency and atestnpm script (vitest run). No test runner previously existed in this repo.Build & test results
All run from repo root:
mise run build(tsc -b && vite build) — PASS (built in ~107ms, 20 modules transformed).mise run lint(oxlint) — PASS (no warnings/errors).npm test(vitest run) — PASS (1 file, 22/22 tests passing).Decisions made
statusfor exhaustive, type-safe narrowing.expiredstate carries theUser(not the full session) so the UI can greet the returning user while requiring re-authentication.vitestsince the repo had no test infrastructure; it integrates cleanly with the existing Vite setup.Agent notes
mise. Adding an isolatedsrc/authmodule with no framework coupling was low-risk, and the stricttsconfig.app.json(verbatimModuleSyntax, noUnusedLocals) caught issues early.tsc -bcompiles the test file too, so tests must stay type-clean.oxlintfor linting; strict TS config using bundler module resolution andverbatimModuleSyntax(useimport typefor type-only imports).testtask tomise.tomlfor parity withbuild/lint. The sign-in UI and service-layer sub-issues can import fromsrc/authand usederiveAuthStateto map a persisted/restored session to the correct state.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of the project license.