0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-30 20:33:54 -05:00

fix(console): use correct sign-out redirect uri for api hooks

This commit is contained in:
Gao Sun 2023-08-24 14:54:08 +08:00
parent 53486f27ad
commit ab8c75efa8
No known key found for this signature in database
GPG key ID: 13EBE123E4773688
2 changed files with 6 additions and 7 deletions

View file

@ -6,13 +6,13 @@ import ky from 'ky';
import { useCallback, useContext, useMemo } from 'react';
import { toast } from 'react-hot-toast';
import { useTranslation } from 'react-i18next';
import { useHref } from 'react-router-dom';
import { requestTimeout } from '@/consts';
import { AppDataContext } from '@/contexts/AppDataProvider';
import { TenantsContext } from '@/contexts/TenantsProvider';
import { useConfirmModal } from './use-confirm-modal';
import useRedirectUri from './use-redirect-uri';
export class RequestError extends Error {
constructor(
@ -33,7 +33,7 @@ export const useStaticApi = ({ prefixUrl, hideErrorToast, resourceIndicator }: S
const { isAuthenticated, getAccessToken, signOut } = useLogto();
const { t, i18n } = useTranslation(undefined, { keyPrefix: 'admin_console' });
const { show } = useConfirmModal();
const href = useHref('/');
const postSignOutRedirectUri = useRedirectUri('signOut');
const toastError = useCallback(
async (response: Response) => {
@ -51,7 +51,7 @@ export const useStaticApi = ({ prefixUrl, hideErrorToast, resourceIndicator }: S
cancelButtonText: 'general.got_it',
});
await signOut(href);
await signOut(postSignOutRedirectUri.href);
return;
}
@ -60,7 +60,7 @@ export const useStaticApi = ({ prefixUrl, hideErrorToast, resourceIndicator }: S
toast.error(httpCodeToMessage[response.status] ?? fallbackErrorMessage);
}
},
[show, signOut, t, href]
[show, signOut, t, postSignOutRedirectUri]
);
const api = useMemo(
@ -73,7 +73,6 @@ export const useStaticApi = ({ prefixUrl, hideErrorToast, resourceIndicator }: S
!hideErrorToast &&
(async (error) => {
await toastError(error.response);
return error;
})
),

View file

@ -1,5 +1,5 @@
import { ossConsolePath } from '@logto/schemas';
import { conditionalArray } from '@silverhand/essentials';
import { conditionalArray, joinPath } from '@silverhand/essentials';
import { useHref } from 'react-router-dom';
import { isCloud } from '@/consts/env';
@ -11,7 +11,7 @@ import { isCloud } from '@/consts/env';
*/
const useRedirectUri = (flow: 'signIn' | 'signOut' = 'signIn') => {
const path = useHref(
conditionalArray(!isCloud && ossConsolePath, flow === 'signIn' && '/callback').join('')
joinPath(...conditionalArray(!isCloud && ossConsolePath, flow === 'signIn' ? '/callback' : '/'))
);
return new URL(path, window.location.origin);