import { ApplicationConfig, provideBrowserGlobalErrorListeners, provideZonelessChangeDetection, APP_INITIALIZER } from '@angular/core'; import { provideRouter } from '@angular/router'; import { provideAnimations } from '@angular/platform-browser/animations'; import { provideHttpClient } from '@angular/common/http'; import { TOAST_CONFIG, DefaultGlobalConfig } from 'ngx-toastr'; import { routes } from './app.routes'; import { AuthService } from './services/auth/auth.service'; /** * On every page load the HttpOnly `rag_session` cookie is validated with `GET /me` * before the first route activates; a 401 drops the authenticated state so the * guard sends the user to the login page. */ function initializeAuth(auth: AuthService): () => Promise { return () => auth.ensureIdentity().catch(() => false); } export const appConfig: ApplicationConfig = { providers: [ provideBrowserGlobalErrorListeners(), provideZonelessChangeDetection(), provideRouter(routes), provideAnimations(), provideHttpClient(), { provide: APP_INITIALIZER, useFactory: initializeAuth, deps: [AuthService], multi: true, }, { provide: TOAST_CONFIG, useValue: { default: DefaultGlobalConfig, config: {} } } ] };