From f9aec3805ca3a02e2da7f06e63a274d3f0ca509b Mon Sep 17 00:00:00 2001 From: Charles Le Maux Date: Sat, 21 Sep 2024 12:04:44 +0200 Subject: [PATCH] [+] Fixed optimization issue --- src/service/api.tsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/service/api.tsx b/src/service/api.tsx index 0c76d47..810def7 100644 --- a/src/service/api.tsx +++ b/src/service/api.tsx @@ -3,6 +3,8 @@ import {Bounce, toast} from "react-toastify"; const apiUrl: string = 'https://www.servii.fr/api'; //const apiUrl: string = 'http://localhost:3000'; +let token_fetched: boolean = false; +let token: string; interface ApiResponse { return_code: number; @@ -124,7 +126,14 @@ class serviiApi { private static async token(): Promise { try { - return await auth.currentUser.getIdToken(true); + if (!token_fetched) { + token = await auth.currentUser.getIdToken(true); + token_fetched = true; + return token; + } + else { + return token; + } } catch (error) { throw new Error("No token retrieved."); }