1 year ago
#274667
Maxim
Routes / Interceptor not working in Angular 11 App
I'm having the classic issue of my Angular 11 app not working after having made some changes, without knowing which change caused it. The app should be redirecting the user to "auth/login", but the call to router.navigate doesn't seem to do anything. I have this AuthGuardService that was also previously in use:
@Injectable()
export class AuthGuardService implements CanActivate {
constructor(public _settings: AppSettings, public router: Router, private _authService:AuthenticationService) { }
canActivate(): boolean {
if (!this._authService.isAuthenticated) {
console.log('User is not authenticated!');
if (!environment.windowsAuth) {
console.log('Rerouting to auth/login.');
this.router.navigate(['auth/login']);
return false;
} else {
console.log('Rerouting to auth/windowslogin.');
this.router.navigate(['auth/windowslogin']);
}
} else {
console.log('Authentication check successfull.');
return true;
}
And here's part of the app-routing.module.ts:
{
path: 'arbeitszeiten',
component: ArbeitszeitenOperativComponent,
canActivate: [AuthGuardService]
},
{
path: 'auth',
loadChildren: () => import('./authentication.module').then(m => m.AuthenticationModule)
}];
And here's some code from the authInterceptor:
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
if (!this._authService.authorization) {
if (req.url.endsWith(this._settings.authLoginApi) ||
req.url.endsWith(this._settings.authWindowsloginApi) ||
req.url.endsWith(this._settings.localizationApi) ||
req.url.endsWith(this._settings.settingsApi) ||
req.url.indexOf("microsoftonline") != -1) {
return next.handle(req).pipe(tap(result => {
}));
}
The routing and part was made by a different programmer, so I'm not exactly sure what's happening there. But the console doesn't show any error, the app just never redirects to the login page. Any ideas why that might be?
Edit: after enabling the router-tracing I get the following output, I currently don't know what to make of it though:
angular
angular-routing
angular-http-interceptors
angular11
auth-guard
0 Answers
Your Answer