[FEAT] correct some connection/disconnection of SSO

This commit is contained in:
Edouard DUPIN 2024-09-15 15:37:10 +02:00
parent a6fe889d4c
commit f0b2a859db
8 changed files with 38 additions and 9 deletions

View File

@ -38,6 +38,7 @@ import { SessionState } from '@/service/SessionState';
import { colors } from '@/theme/foundations/colors'; import { colors } from '@/theme/foundations/colors';
import { requestSignIn, requestSignOut, requestSignUp } from '@/utils/sso'; import { requestSignIn, requestSignOut, requestSignUp } from '@/utils/sso';
import { useThemeMode } from '@/utils/theme-tools'; import { useThemeMode } from '@/utils/theme-tools';
import { useSessionService } from '@/service/session';
export const TOP_BAR_HEIGHT = '50px'; export const TOP_BAR_HEIGHT = '50px';
@ -53,6 +54,7 @@ export type TopBarProps = {
export const TopBar = ({ title, children }: TopBarProps) => { export const TopBar = ({ title, children }: TopBarProps) => {
const { mode, colorMode, toggleColorMode } = useThemeMode(); const { mode, colorMode, toggleColorMode } = useThemeMode();
const { clearToken } = useSessionService();
const { session } = useServiceContext(); const { session } = useServiceContext();
const backColor = mode('back.100', 'back.800'); const backColor = mode('back.100', 'back.800');
@ -62,17 +64,26 @@ export const TopBar = ({ title, children }: TopBarProps) => {
}; };
const navigate = useNavigate(); const navigate = useNavigate();
const onSignIn = (): void => { const onSignIn = (): void => {
clearToken();
requestSignIn(); requestSignIn();
}; };
const onSignUp = (): void => { const onSignUp = (): void => {
clearToken();
requestSignUp(); requestSignUp();
}; };
const onSignOut = (): void => { const onSignOut = (): void => {
clearToken();
requestSignOut(); requestSignOut();
}; };
const onSelectHome = () => { const onSelectHome = () => {
navigate('/'); navigate('/');
}; };
const onHelp = () => {
navigate('/help');
};
const onSettings = () => {
navigate('/settings');
};
return ( return (
<Flex <Flex
position="absolute" position="absolute"
@ -140,9 +151,9 @@ export const TopBar = ({ title, children }: TopBarProps) => {
<MenuItem _hover={{}} color={mode('brand.800', 'brand.200')}> <MenuItem _hover={{}} color={mode('brand.800', 'brand.200')}>
Sign in as {session?.login ?? 'Fail'} Sign in as {session?.login ?? 'Fail'}
</MenuItem> </MenuItem>
<MenuItem icon={<LuSettings />}>Settings</MenuItem> <MenuItem icon={<LuSettings />} onClick={onSettings}>Settings</MenuItem>
<MenuItem icon={<LuHelpCircle />}>Help</MenuItem> <MenuItem icon={<LuHelpCircle />} onClick={onHelp}>Help</MenuItem>
<MenuItem icon={<LuLogOut onClick={onSignOut} />}> <MenuItem icon={<LuLogOut />} onClick={onSignOut}>
Sign-out Sign-out
</MenuItem> </MenuItem>
{colorMode === 'light' ? ( {colorMode === 'light' ? (

View File

@ -1,3 +1,5 @@
export * from './AudioPlayer';
export * from './Icons'; export * from './Cover';
export * from './EmptyEnd';
export * from './Icon';
export * from './SearchInput';

View File

@ -23,6 +23,7 @@ export const useAlbumServiceWrapped = (
{ {
restApiName: 'ALBUM', restApiName: 'ALBUM',
primaryKey: 'id', primaryKey: 'id',
available: session.token !== undefined,
getsCall: () => { getsCall: () => {
return AlbumResource.gets({ return AlbumResource.gets({
restConfig: session.getRestConfig(), restConfig: session.getRestConfig(),

View File

@ -23,6 +23,7 @@ export const useArtistServiceWrapped = (
{ {
restApiName: 'ARTIST', restApiName: 'ARTIST',
primaryKey: 'id', primaryKey: 'id',
available: session.token !== undefined,
getsCall: () => { getsCall: () => {
return ArtistResource.gets({ return ArtistResource.gets({
restConfig: session.getRestConfig(), restConfig: session.getRestConfig(),

View File

@ -23,6 +23,7 @@ export const useGenderServiceWrapped = (
{ {
restApiName: 'GENDER', restApiName: 'GENDER',
primaryKey: 'id', primaryKey: 'id',
available: session.token !== undefined,
getsCall: () => { getsCall: () => {
return GenderResource.gets({ return GenderResource.gets({
restConfig: session.getRestConfig(), restConfig: session.getRestConfig(),

View File

@ -23,6 +23,7 @@ export const useTrackServiceWrapped = (
{ {
restApiName: 'TRACK', restApiName: 'TRACK',
primaryKey: 'id', primaryKey: 'id',
available: session.token !== undefined,
getsCall: () => { getsCall: () => {
return TrackResource.gets({ return TrackResource.gets({
restConfig: session.getRestConfig(), restConfig: session.getRestConfig(),

View File

@ -23,10 +23,12 @@ export const useDataStore = <TYPE>(
{ {
primaryKey = 'id', primaryKey = 'id',
restApiName, restApiName,
available = true,
getsCall, getsCall,
}: { }: {
restApiName?: string; restApiName?: string;
primaryKey?: string; primaryKey?: string;
available?: boolean;
getsCall: () => Promise<TYPE[]>; getsCall: () => Promise<TYPE[]>;
}, },
deps: DependencyList = [] deps: DependencyList = []
@ -38,9 +40,13 @@ export const useDataStore = <TYPE>(
// on instantiation ==> call the request of the data... // on instantiation ==> call the request of the data...
useEffect(() => { useEffect(() => {
console.log(`[${restApiName}] call data ...`);
setError(undefined); setError(undefined);
setIsLoading(true); setIsLoading(true);
if (!available) {
console.log(`[${restApiName}] NOT call data. service not available`);
return;
}
console.log(`[${restApiName}] call data ...`);
getsCall() getsCall()
.then((response: TYPE[]) => { .then((response: TYPE[]) => {
/*console.log( /*console.log(

View File

@ -104,11 +104,17 @@ export function requestSignIn(name?: string): void {
* Request SSO Disconnect * Request SSO Disconnect
*/ */
export function requestSignOut(name?: string): void { 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 * Request SSO signUp
*/ */
export function requestSignUp(name?: string): void { 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;
} }