From 18ed563a6303a3c6e16c7a08c39e9c013671593f Mon Sep 17 00:00:00 2001
From: Jeremie BRISON <ext.sopra.jbrison@grandlyon.com>
Date: Thu, 7 Jan 2021 16:21:17 +0100
Subject: [PATCH] fix structureLink error

---
 src/app/profile/services/profile.service.ts | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/app/profile/services/profile.service.ts b/src/app/profile/services/profile.service.ts
index 819eb0d3f..78e6a3c1e 100644
--- a/src/app/profile/services/profile.service.ts
+++ b/src/app/profile/services/profile.service.ts
@@ -14,7 +14,7 @@ export class ProfileService {
 
   public async getProfile(): Promise<User> {
     // Get profil by API only on first time
-    if (!this.currentProfile) {
+    if (!this.currentProfile && this.authService.isLoggedIn()) {
       const profile = await this.http.get<User>(`${this.baseUrl}/profile`).toPromise();
       this.currentProfile = profile;
     }
@@ -22,6 +22,12 @@ export class ProfileService {
   }
 
   public isLinkedToStructure(idStructure: number): boolean {
+    if (!this.authService.isLoggedIn()) {
+      this.currentProfile = null;
+    }
+    if (!this.currentProfile) {
+      return false;
+    }
     return this.currentProfile.structuresLink.includes(idStructure);
   }
 
-- 
GitLab