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:
@@ -6,11 +6,11 @@
|
||||
att logga ut applikationen och logga in på nytt.
|
||||
</p>
|
||||
</digi-typography>
|
||||
<ng-container *ngIf="user$ | async as user">
|
||||
<ng-container *ngIf="organizations$ | async as organizations">
|
||||
<msfa-organization-picker-form
|
||||
class="organization-picker__form"
|
||||
*ngIf="user.organizations?.length !== 1"
|
||||
[organizations]="user.organizations"
|
||||
*ngIf="organizations.length !== 1"
|
||||
[organizations]="organizations"
|
||||
(selectedOrganizationChanged)="loginWithOrganization($event)"
|
||||
></msfa-organization-picker-form>
|
||||
</ng-container>
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { ChangeDetectionStrategy, Component, OnDestroy, OnInit } from '@angular/core';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { ChangeDetectionStrategy, Component } from '@angular/core';
|
||||
import { Router } from '@angular/router';
|
||||
import { UnsubscribeDirective } from '@msfa-directives/unsubscribe.directive';
|
||||
import { Organization } from '@msfa-models/organization.model';
|
||||
import { UserService } from '@msfa-services/api/user.service';
|
||||
|
||||
export const redirectUriQueryParam = 'redirect_uri';
|
||||
import { Observable } from 'rxjs';
|
||||
import { filter, map } from 'rxjs/operators';
|
||||
|
||||
@Component({
|
||||
selector: 'msfa-organization-picker',
|
||||
@@ -12,38 +12,25 @@ export const redirectUriQueryParam = 'redirect_uri';
|
||||
styleUrls: ['./organization-picker.component.scss'],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
})
|
||||
export class OrganizationPickerComponent extends UnsubscribeDirective implements OnInit {
|
||||
user$ = this.userService.user$;
|
||||
export class OrganizationPickerComponent extends UnsubscribeDirective {
|
||||
organizations$: Observable<Organization[]> = this.userService.user$.pipe(
|
||||
filter(user => !!(user && user.organizations?.length)),
|
||||
map(({ organizations }) => organizations)
|
||||
);
|
||||
|
||||
private redirectUri: string | null = null;
|
||||
|
||||
constructor(private userService: UserService, private router: Router, private route: ActivatedRoute) {
|
||||
constructor(private userService: UserService, private router: Router) {
|
||||
super();
|
||||
super.unsubscribeOnDestroy(
|
||||
this.user$.subscribe(user => {
|
||||
if (user?.organizations?.length === 1) {
|
||||
this.loginWithOrganization(user.organizations[0]);
|
||||
this.organizations$.subscribe(organizations => {
|
||||
if (organizations.length === 1) {
|
||||
this.loginWithOrganization(organizations[0]);
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
super.unsubscribeOnDestroy(
|
||||
this.route.queryParams.subscribe(params => {
|
||||
this.redirectUri = params[redirectUriQueryParam] ? decodeURI(params[redirectUriQueryParam]) : null;
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
loginWithOrganization(organization: Organization): void {
|
||||
this.userService.setSelectedUserOrganization(organization);
|
||||
|
||||
if (this.redirectUri) {
|
||||
location.href = this.redirectUri;
|
||||
return;
|
||||
}
|
||||
|
||||
this.router.navigateByUrl('/');
|
||||
this.userService.setSelectedOrganization(organization);
|
||||
void this.router.navigateByUrl('/');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user