From 7b1dd6f68c357d327104508dca57057aaa900000 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste WATENBERG Date: Fri, 26 Apr 2024 16:08:06 +0200 Subject: [PATCH] shell-ui: Add token to window object --- shell-ui/src/auth/AuthProvider.tsx | 18 ++++++++++++++++-- shell-ui/src/index.tsx | 1 + 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/shell-ui/src/auth/AuthProvider.tsx b/shell-ui/src/auth/AuthProvider.tsx index 85d5d014aa..1786cab82c 100644 --- a/shell-ui/src/auth/AuthProvider.tsx +++ b/shell-ui/src/auth/AuthProvider.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { PropsWithChildren, useMemo } from 'react'; import { useCallback, useEffect } from 'react'; import { useAuthConfig } from './AuthConfigProvider'; import { @@ -153,7 +153,21 @@ function OAuth2AuthProvider({ children }: { children: React.ReactNode }) { }, userManager, }; - return {children}; + return ( + + {children} + + ); +} + +function SyncTokenWithGlobalWindow({ children }: PropsWithChildren<{}>) { + const auth = useOauth2Auth(); + useMemo(() => { + if (auth && auth.userData) { + window.TOKEN = auth.userData.access_token; + } + }, [auth]); + return <>{children}; } export type UserData = { diff --git a/shell-ui/src/index.tsx b/shell-ui/src/index.tsx index 74574d4468..dea5367d96 100644 --- a/shell-ui/src/index.tsx +++ b/shell-ui/src/index.tsx @@ -17,6 +17,7 @@ declare global { null | (BuildtimeWebFinger | RuntimeWebFinger)[] >; }; + TOKEN: string; } }