Skip to content
Snippets Groups Projects
Commit b9beb70b authored by Etienne LOUPIAS's avatar Etienne LOUPIAS
Browse files

fix(structure): edit page reload redirect to home

parent 99d78125
No related branches found
No related tags found
2 merge requests!807V3.0.2,!803Resolve "Reload redirige vers les news"
import { ActivatedRouteSnapshot, Router, UrlTree } from '@angular/router';
import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, Router, UrlTree } from '@angular/router';
import { ProfileService } from '../profile/services/profile.service';
import { AuthService } from '../services/auth.service';
import { RouteRole } from '../shared/enum/routeRole.enum';
......@@ -15,14 +15,14 @@ export class RoleGuard {
private authService: AuthService,
) {}
canActivate(route: ActivatedRouteSnapshot): UrlTree | boolean {
async canActivate(route: ActivatedRouteSnapshot): Promise<UrlTree | boolean> {
const allowedRoles = route.data.allowedRoles;
if (this.authService.isLoggedIn()) {
if (this.profileService.isAdmin()) return true;
if (allowedRoles.includes(RouteRole.structureAdmin)) {
const structureId = route.params.id;
if (this.profileService.isLinkedToStructure(structureId)) {
if (await this.profileService.isLinkedToStructure(structureId)) {
return true;
}
}
......
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import decode from 'jwt-decode';
import { Observable } from 'rxjs';
import { Observable, lastValueFrom } from 'rxjs';
import { catchError, map } from 'rxjs/operators';
import { Employer } from '../../models/employer.model';
import { Job } from '../../models/job.model';
......@@ -25,7 +25,7 @@ export class ProfileService {
public async getProfile(): Promise<User> {
if (this.authService.isLoggedIn()) {
const profile = await this.http.get<User>(`${this.baseUrl}/profile`).toPromise();
const profile = await lastValueFrom(this.http.get<User>(`${this.baseUrl}/profile`));
this.currentProfile = profile;
}
return this.currentProfile;
......@@ -38,7 +38,8 @@ export class ProfileService {
return this.http.delete<User>(`${this.baseUrl}`);
}
public isLinkedToStructure(idStructure: string): boolean {
public async isLinkedToStructure(idStructure: string): Promise<boolean> {
await this.getProfile();
if (!this.currentProfile) {
return false;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment