Files
Toju/toju-app/src/app/domains/auth

Auth Domain

Handles user authentication (login and registration) against the configured server endpoint. Provides the login, register, and user-bar UI components.

Module map

auth/
├── application/
│   └── auth.service.ts              HTTP login/register against the active server endpoint
│
├── feature/
│   ├── login/                       Login form component
│   ├── register/                    Registration form component
│   └── user-bar/                    Displays current user or login/register links
│
└── index.ts                         Barrel exports

Service overview

AuthService resolves the API base URL from ServerDirectoryFacade, then makes POST requests for login and registration. It does not hold session state itself; after a successful login the calling component stores currentUserId in localStorage and dispatches UsersActions.setCurrentUser into the NgRx store.

graph TD
    Login[LoginComponent]
    Register[RegisterComponent]
    UserBar[UserBarComponent]
    Auth[AuthService]
    SD[ServerDirectoryFacade]
    Store[NgRx Store]

    Login --> Auth
    Register --> Auth
    UserBar --> Store
    Auth --> SD
    Login --> Store

    click Auth "application/auth.service.ts" "HTTP login/register" _blank
    click Login "feature/login/" "Login form" _blank
    click Register "feature/register/" "Registration form" _blank
    click UserBar "feature/user-bar/" "Current user display" _blank
    click SD "../server-directory/application/server-directory.facade.ts" "Resolves API URL" _blank

Login flow

sequenceDiagram
    participant User
    participant Login as LoginComponent
    participant Auth as AuthService
    participant SD as ServerDirectoryFacade
    participant API as Server API
    participant Store as NgRx Store

    User->>Login: Submit credentials
    Login->>Auth: login(username, password)
    Auth->>SD: getApiBaseUrl()
    SD-->>Auth: https://server/api
    Auth->>API: POST /api/auth/login
    API-->>Auth: { userId, displayName }
    Auth-->>Login: success
    Login->>Store: UsersActions.setCurrentUser
    Login->>Login: localStorage.setItem(currentUserId)

Registration flow

Registration follows the same pattern but posts to /api/auth/register with an additional displayName field. On success the user is treated as logged in and the same store dispatch happens.

User bar

UserBarComponent reads the current user from the NgRx store. When logged in it shows the user's display name; when not logged in it shows links to the login and register views.