Merge pull request #60 in TEA/dafa-web-monorepo from bugs/TV-397 to develop

Squashed commit of the following:

commit 4213320a89111b3486ff799dbdd9b648a245fc00
Author: arbetsformedlingen_garcn <christian.gardebrink@arbetsformedlingen.se>
Date:   Fri Aug 20 09:27:04 2021 +0200

    TV-397 tog bort metoder som fanns i två servicar.

commit 01195a0b2b5ea8da234c5e32692b51aff32b23e6
Merge: 6b5b1e9 1e2d925
Author: arbetsformedlingen_garcn <christian.gardebrink@arbetsformedlingen.se>
Date:   Fri Aug 20 09:24:01 2021 +0200

    Merge branch 'develop-remote' into bugs/TV-397

commit 6b5b1e9fbad2c68ddbd38f0a3c5e183fc6a707c4
Author: arbetsformedlingen_garcn <christian.gardebrink@arbetsformedlingen.se>
Date:   Thu Aug 19 15:42:36 2021 +0200

    TV-397 fixed bug that occurs if userService is brought in as a dependency before authentication is done.
This commit is contained in:
Christian Gårdebrink
2021-08-20 10:30:18 +02:00
parent 1e2d925d27
commit d4447933f8
5 changed files with 13 additions and 22 deletions
@@ -1,6 +1,5 @@
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 { Observable, of } from 'rxjs';
@@ -9,17 +8,13 @@ import { redirectUriQueryParam } from '../../pages/organization-picker/organizat
@Injectable()
export class AuthGuard implements CanActivate {
constructor(
private authenticationService: AuthenticationService,
private userService: UserService,
private router: Router
) {}
constructor(private authenticationService: AuthenticationService, private router: Router) {}
canActivate(route: ActivatedRouteSnapshot): Observable<boolean> {
return this.authenticationService.isLoggedIn$.pipe(
switchMap(loggedIn => {
if (loggedIn) {
if (!this.userService.hasSelectedUserOrganization()) {
if (!this.authenticationService.hasSelectedUserOrganization()) {
this.router.navigateByUrl(`/organization-picker?${redirectUriQueryParam}=${encodeURI(location.href)}`);
}