Authentication
signIn()
The signIn function checks the authentication status and handles routing based on the global configuration. It supports both credential-based, SSO, 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 |
useSSO | boolean | Whether the browser handles SSO authentication |
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)
- Session Cleanup: Calls
clearSessionTokens()to clear any existing session before authenticating - Conditional Authentication:
- If
useCredentialsis true, redirects to the login page with a return URL - If
useSSOis true, reloads the page to let the browser trigger SSO authentication - 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: Logs a warning and continues (no redirect)
- Other Errors: Re-throws for upstream error handling