feat(login): Now adding orgnr to all API requests. (TV-399)
Squashed commit of the following:
commit b0cc0cf07a4eeaf85c8fdfc111fee1898fa14185
Merge: be9d909 59ce393
Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se>
Date: Tue Aug 24 13:42:09 2021 +0200
Merged develop and fixed conflicts
commit be9d909232326eb06221336a966fc40c7c88289d
Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se>
Date: Tue Aug 24 08:02:12 2021 +0200
Updated auth guard to remove localstorage data when user is not logged in
commit a4a182f565689a44e612b9353ae46514c1b439c7
Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se>
Date: Mon Aug 23 15:08:00 2021 +0200
Updated organization functionality to check if organization matches users organizations
commit c170245c2799118bbf7961e95d507885a0571de6
Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se>
Date: Fri Aug 20 14:34:33 2021 +0200
Now saving organization instead of organization number
commit 7c19600f712f48c9c56ba797e4e281a82adcf72f
Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se>
Date: Fri Aug 20 13:43:27 2021 +0200
Removed all headers from API requests from services
commit 7c243bafc63f0544e11f1fa8729a139615cb14c0
Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se>
Date: Fri Aug 20 13:18:19 2021 +0200
Dynamically adding orgnr to interceptor
This commit is contained in:
@@ -1,33 +1,39 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { ActivatedRouteSnapshot, CanActivate, Router } from '@angular/router';
|
||||
import { UserService } from '@msfa-services/api/user.service';
|
||||
import { environment } from '@msfa-environment';
|
||||
import { AuthenticationService } from '@msfa-services/api/authentication.service';
|
||||
import { UserService } from '@msfa-services/api/user.service';
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
import { redirectUriQueryParam } from '../../pages/organization-picker/organization-picker.component';
|
||||
|
||||
@Injectable()
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class AuthGuard implements CanActivate {
|
||||
constructor(
|
||||
private authenticationService: AuthenticationService,
|
||||
private userService: UserService,
|
||||
private router: Router
|
||||
private router: Router,
|
||||
private userService: UserService
|
||||
) {}
|
||||
|
||||
canActivate(route: ActivatedRouteSnapshot): Observable<boolean> {
|
||||
return this.authenticationService.isLoggedIn$.pipe(
|
||||
switchMap(loggedIn => {
|
||||
if (loggedIn) {
|
||||
if (!this.authenticationService.hasSelectedUserOrganization()) {
|
||||
this.router.navigateByUrl(`/organization-picker?${redirectUriQueryParam}=${encodeURI(location.href)}`);
|
||||
}
|
||||
|
||||
return of(true);
|
||||
return this.userService.selectedOrganization$.pipe(
|
||||
map(organization => {
|
||||
if (!organization) {
|
||||
void this.router.navigateByUrl(`/organization-picker`);
|
||||
}
|
||||
return true;
|
||||
})
|
||||
);
|
||||
} else if (route.queryParams.code) {
|
||||
return this.authenticationService.login$(route.queryParams.code).pipe(map(result => !!result));
|
||||
}
|
||||
|
||||
void this.authenticationService.removeLocalStorageData();
|
||||
|
||||
if (environment.environment === 'local') {
|
||||
void this.router.navigateByUrl(environment.loginUrl);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user