mirror of
https://github.com/a-mayb3/KanbanCloneAngular.git
synced 2026-03-21 18:05:38 +01:00
changed base project files
This commit is contained in:
parent
2cf0856db5
commit
0d82ea47c3
6 changed files with 117 additions and 343 deletions
|
|
@ -1,11 +1,38 @@
|
|||
import { ApplicationConfig, provideBrowserGlobalErrorListeners } from '@angular/core';
|
||||
import { ApplicationConfig, provideBrowserGlobalErrorListeners, APP_INITIALIZER } from '@angular/core';
|
||||
import { provideRouter } from '@angular/router';
|
||||
import { provideHttpClient, withInterceptors } from '@angular/common/http';
|
||||
import { catchError, of } from 'rxjs';
|
||||
|
||||
import { routes } from './app.routes';
|
||||
import { httpInterceptor } from './interceptors/http.interceptor';
|
||||
import { AuthService } from './services/auth.service';
|
||||
|
||||
/**
|
||||
* Initialize auth state on app startup by checking for existing session
|
||||
*/
|
||||
function initializeAuth(authService: AuthService) {
|
||||
return () => authService.checkSession().pipe(
|
||||
catchError((error) => {
|
||||
// Session check failed - user is not logged in or session expired
|
||||
console.log('No active session or session expired');
|
||||
authService.clearAuthState();
|
||||
return of(null);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
export const appConfig: ApplicationConfig = {
|
||||
providers: [
|
||||
provideBrowserGlobalErrorListeners(),
|
||||
provideRouter(routes)
|
||||
provideRouter(routes),
|
||||
provideHttpClient(
|
||||
withInterceptors([httpInterceptor])
|
||||
),
|
||||
{
|
||||
provide: APP_INITIALIZER,
|
||||
useFactory: initializeAuth,
|
||||
deps: [AuthService],
|
||||
multi: true
|
||||
}
|
||||
]
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue