refactor: stricter domain: auth
This commit is contained in:
77
toju-app/src/app/domains/authentication/README.md
Normal file
77
toju-app/src/app/domains/authentication/README.md
Normal file
@@ -0,0 +1,77 @@
|
||||
# Authentication Domain
|
||||
|
||||
Handles user authentication (login and registration) against the configured server endpoint. Provides the login, register, and user-bar UI components.
|
||||
|
||||
## Module map
|
||||
|
||||
```
|
||||
authentication/
|
||||
├── application/
|
||||
│ └── authentication.service.ts HTTP login/register against the active server endpoint
|
||||
│
|
||||
├── domain/
|
||||
│ └── authentication.model.ts LoginResponse interface
|
||||
│
|
||||
├── feature/
|
||||
│ ├── login/ Login form component
|
||||
│ ├── register/ Registration form component
|
||||
│ └── user-bar/ Displays current user or login/register links
|
||||
│
|
||||
└── index.ts Barrel exports
|
||||
```
|
||||
|
||||
## Service overview
|
||||
|
||||
`AuthenticationService` 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.
|
||||
|
||||
```mermaid
|
||||
graph TD
|
||||
Login[LoginComponent]
|
||||
Register[RegisterComponent]
|
||||
UserBar[UserBarComponent]
|
||||
Auth[AuthenticationService]
|
||||
SD[ServerDirectoryFacade]
|
||||
Store[NgRx Store]
|
||||
|
||||
Login --> Auth
|
||||
Register --> Auth
|
||||
UserBar --> Store
|
||||
Auth --> SD
|
||||
Login --> Store
|
||||
|
||||
click Auth "application/authentication.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
|
||||
|
||||
```mermaid
|
||||
sequenceDiagram
|
||||
participant User
|
||||
participant Login as LoginComponent
|
||||
participant Auth as AuthenticationService
|
||||
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.
|
||||
Reference in New Issue
Block a user