From f0b2a859db71d8bb0e7446f53148bc5de0fd5e64 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Sun, 15 Sep 2024 15:37:10 +0200 Subject: [PATCH] [FEAT] correct some connection/disconnection of SSO --- front2/src/components/TopBar/TopBar.tsx | 17 ++++++++++++++--- front2/src/components/index.ts | 8 +++++--- front2/src/service/Album.ts | 1 + front2/src/service/Artist.ts | 1 + front2/src/service/Gender.ts | 1 + front2/src/service/Track.ts | 1 + front2/src/utils/data-store.ts | 8 +++++++- front2/src/utils/sso.ts | 10 ++++++++-- 8 files changed, 38 insertions(+), 9 deletions(-) diff --git a/front2/src/components/TopBar/TopBar.tsx b/front2/src/components/TopBar/TopBar.tsx index 78ae4f1..26bf905 100644 --- a/front2/src/components/TopBar/TopBar.tsx +++ b/front2/src/components/TopBar/TopBar.tsx @@ -38,6 +38,7 @@ import { SessionState } from '@/service/SessionState'; import { colors } from '@/theme/foundations/colors'; import { requestSignIn, requestSignOut, requestSignUp } from '@/utils/sso'; import { useThemeMode } from '@/utils/theme-tools'; +import { useSessionService } from '@/service/session'; export const TOP_BAR_HEIGHT = '50px'; @@ -53,6 +54,7 @@ export type TopBarProps = { export const TopBar = ({ title, children }: TopBarProps) => { const { mode, colorMode, toggleColorMode } = useThemeMode(); + const { clearToken } = useSessionService(); const { session } = useServiceContext(); const backColor = mode('back.100', 'back.800'); @@ -62,17 +64,26 @@ export const TopBar = ({ title, children }: TopBarProps) => { }; const navigate = useNavigate(); const onSignIn = (): void => { + clearToken(); requestSignIn(); }; const onSignUp = (): void => { + clearToken(); requestSignUp(); }; const onSignOut = (): void => { + clearToken(); requestSignOut(); }; const onSelectHome = () => { navigate('/'); }; + const onHelp = () => { + navigate('/help'); + }; + const onSettings = () => { + navigate('/settings'); + }; return ( { Sign in as {session?.login ?? 'Fail'} - }>Settings - }>Help - }> + } onClick={onSettings}>Settings + } onClick={onHelp}>Help + } onClick={onSignOut}> Sign-out {colorMode === 'light' ? ( diff --git a/front2/src/components/index.ts b/front2/src/components/index.ts index 84f3569..9ff2e4b 100644 --- a/front2/src/components/index.ts +++ b/front2/src/components/index.ts @@ -1,3 +1,5 @@ - -export * from './Icons'; - +export * from './AudioPlayer'; +export * from './Cover'; +export * from './EmptyEnd'; +export * from './Icon'; +export * from './SearchInput'; diff --git a/front2/src/service/Album.ts b/front2/src/service/Album.ts index 90b7b25..575981f 100644 --- a/front2/src/service/Album.ts +++ b/front2/src/service/Album.ts @@ -23,6 +23,7 @@ export const useAlbumServiceWrapped = ( { restApiName: 'ALBUM', primaryKey: 'id', + available: session.token !== undefined, getsCall: () => { return AlbumResource.gets({ restConfig: session.getRestConfig(), diff --git a/front2/src/service/Artist.ts b/front2/src/service/Artist.ts index 0aab255..3f82645 100644 --- a/front2/src/service/Artist.ts +++ b/front2/src/service/Artist.ts @@ -23,6 +23,7 @@ export const useArtistServiceWrapped = ( { restApiName: 'ARTIST', primaryKey: 'id', + available: session.token !== undefined, getsCall: () => { return ArtistResource.gets({ restConfig: session.getRestConfig(), diff --git a/front2/src/service/Gender.ts b/front2/src/service/Gender.ts index c085dfa..143172e 100644 --- a/front2/src/service/Gender.ts +++ b/front2/src/service/Gender.ts @@ -23,6 +23,7 @@ export const useGenderServiceWrapped = ( { restApiName: 'GENDER', primaryKey: 'id', + available: session.token !== undefined, getsCall: () => { return GenderResource.gets({ restConfig: session.getRestConfig(), diff --git a/front2/src/service/Track.ts b/front2/src/service/Track.ts index ad99a14..a5466c2 100644 --- a/front2/src/service/Track.ts +++ b/front2/src/service/Track.ts @@ -23,6 +23,7 @@ export const useTrackServiceWrapped = ( { restApiName: 'TRACK', primaryKey: 'id', + available: session.token !== undefined, getsCall: () => { return TrackResource.gets({ restConfig: session.getRestConfig(), diff --git a/front2/src/utils/data-store.ts b/front2/src/utils/data-store.ts index 801fd08..274365b 100644 --- a/front2/src/utils/data-store.ts +++ b/front2/src/utils/data-store.ts @@ -23,10 +23,12 @@ export const useDataStore = ( { primaryKey = 'id', restApiName, + available = true, getsCall, }: { restApiName?: string; primaryKey?: string; + available?: boolean; getsCall: () => Promise; }, deps: DependencyList = [] @@ -38,9 +40,13 @@ export const useDataStore = ( // on instantiation ==> call the request of the data... useEffect(() => { - console.log(`[${restApiName}] call data ...`); setError(undefined); setIsLoading(true); + if (!available) { + console.log(`[${restApiName}] NOT call data. service not available`); + return; + } + console.log(`[${restApiName}] call data ...`); getsCall() .then((response: TYPE[]) => { /*console.log( diff --git a/front2/src/utils/sso.ts b/front2/src/utils/sso.ts index 68b16a2..e779c36 100644 --- a/front2/src/utils/sso.ts +++ b/front2/src/utils/sso.ts @@ -104,11 +104,17 @@ export function requestSignIn(name?: string): void { * Request SSO Disconnect */ export function requestSignOut(name?: string): void { - window.location.href = environment.ssoSignOut + hashLocalData(name); + const url = environment.ssoSignOut + hashLocalData(name); + console.log(`Request just to the SSO: ${url}`) + // unlog from the SSO + window.location.href = url; } /** * Request SSO signUp */ export function requestSignUp(name?: string): void { - window.location.href = environment.ssoSignUp + hashLocalData(name); + const url = environment.ssoSignUp + hashLocalData(name); + console.log(`Request just to the SSO: ${url}`) + // unlog from the SSO + window.location.href = url; }