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

Check if it is the user's own offer

parent b7287e05
No related branches found
No related tags found
1 merge request!936Resolve "[modification fiche structure] - Offre structure vs. Offre accompagnant numérique + ordre des blocs"
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import decode from 'jwt-decode';
import { Observable, lastValueFrom } from 'rxjs';
import { catchError, map } from 'rxjs/operators';
import { Employer } from '../../models/employer.model';
......@@ -23,6 +22,14 @@ export class ProfileService {
private notificationService: NotificationService,
) {}
public getId(): string {
if (this.authService.isLoggedIn()) {
const tokenPayload = this.authService.tokenPayload;
return tokenPayload?.id;
}
return null;
}
public async getProfile(): Promise<User> {
if (this.authService.isLoggedIn()) {
const profile = await lastValueFrom(this.http.get<User>(`${this.baseUrl}/profile`));
......@@ -55,10 +62,7 @@ export class ProfileService {
public isAdmin(): boolean {
if (this.authService.isLoggedIn()) {
const user = this.authService.userValue;
const token = user.accessToken;
// decode the token to get its payload
const tokenPayload: User = decode(token);
const tokenPayload = this.authService.tokenPayload;
if (tokenPayload.role === UserRole.admin) {
return true;
}
......
......@@ -101,8 +101,8 @@ export class StructureEditionSummaryComponent implements OnInit {
// Get categories labels
if (personalOffer) {
// TODO : recuperer si c'est le user connecté en utilisant le profileService, mais a priori le profileService a pas l'id du user...
const isMyself = true;
// Check if it is the user's own offer
const isMyself = this.profileService.getId() === member._id;
const offerHolder = {
user: member,
......
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import decode from 'jwt-decode';
import { DateTime } from 'luxon';
import { BehaviorSubject, Observable } from 'rxjs';
import { map } from 'rxjs/operators';
......@@ -33,6 +34,15 @@ export class AuthService {
return null;
}
public get tokenPayload(): User {
const token = this.token;
if (!token) return null;
// decode the token to get its payload
const tokenPayload: User = decode(token);
return tokenPayload;
}
public logout(): void {
localStorage.removeItem('user');
this.userSubject.next(null);
......
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