From 4e4f9ba7b8d6d2e555fd61c049d0e7ace74598cb Mon Sep 17 00:00:00 2001 From: Antony Raj Date: Thu, 1 Aug 2024 02:02:34 +0800 Subject: [PATCH] remove duplicated code --- frontend/src/hooks/auth.tsx | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/frontend/src/hooks/auth.tsx b/frontend/src/hooks/auth.tsx index 99c9de32..7668ee49 100644 --- a/frontend/src/hooks/auth.tsx +++ b/frontend/src/hooks/auth.tsx @@ -46,7 +46,7 @@ const client = createClient({ const authMiddleware: Middleware = { async onRequest({ request }) { - const accessToken = localStorage.getItem("AUTH"); + const accessToken = localStorage.getItem(AUTH_KEY_ID); if (!accessToken) { throw new Error("No access token found"); } @@ -68,15 +68,7 @@ export const AuthenticationProvider = (props: AuthenticationProviderProps) => { // Add the API key to the request headers, if the user is authenticated. if (apiKeyId !== null) { - client.use({ - async onRequest({ request }) { - request.headers.set("Authorization", `Bearer ${apiKeyId}`); - return request; - }, - async onResponse({ response }) { - return response; - }, - }); + client.use(authMiddleware); } const login = useCallback((apiKeyId: string) => {