Authentication
signIn()
The signIn function checks the authentication status and handles routing based on the global configuration. It supports both credential-based and automatic login flows.
Parameters
This function uses Angular's dependency injection and doesn't require explicit parameters. It injects:
Router- For navigationNavigationService- To get the URL after navigation
Configuration Dependencies
The function relies on the following global configuration properties:
| Property | Type | Description |
|---|---|---|
useCredentials | boolean | Whether to use credential-based authentication |
loginPath | string | The path to redirect to for login |
userOverrideActive | boolean | Whether user override is currently active |
Complete Flow Diagram
Authentication Flow
Error Handling Flow
Usage
app.config.ts
export const appConfig: ApplicationConfig = {
providers: [
provideAppInitializer(() => signIn()),
...
]
}
Implementation Details
The function performs the following steps:
- Injection Context Check: Ensures it's called within an Angular injection context
- Service Injection: Injects required services (Router, NavigationService)
- Configuration Check: Reads global configuration for authentication strategy
- Conditional Authentication:
- If
userOverrideActiveis true, no authentication is performed - If
useCredentialsis true, redirects to login page with return URL - Otherwise, attempts automatic login via API
- If
- Error Handling: Handles login failures with appropriate routing
Error Scenarios
- 401 Unauthorized: Redirects to login page
- No Response: Redirects to loading page with warning
- Other Errors: Re-throws for upstream error handling