Skip to main content
Version: Next 🚧

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 navigation
  • NavigationService - To get the URL after navigation

Configuration Dependencies​

The function relies on the following global configuration properties:

PropertyTypeDescription
useCredentialsbooleanWhether to use credential-based authentication
loginPathstringThe path to redirect to for login
useSSObooleanWhether 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:

  1. Injection Context Check: Ensures it's called within an Angular injection context
  2. Service Injection: Injects required services (Router, NavigationService)
  3. Session Cleanup: Calls clearSessionTokens() to clear any existing session before authenticating
  4. Conditional Authentication:
    • If useCredentials is true, redirects to the login page with a return URL
    • If useSSO is true, reloads the page to let the browser trigger SSO authentication
    • Otherwise, attempts automatic login via API
  5. 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