mirror of
https://github.com/logto-io/logto.git
synced 2024-12-30 20:33:54 -05:00
Merge pull request #4387 from logto-io/gao-fix-sign-out-redirect-for-api
fix(console): use correct sign-out redirect uri for api hooks
This commit is contained in:
commit
dcff078d68
2 changed files with 6 additions and 7 deletions
|
@ -6,13 +6,13 @@ import ky from 'ky';
|
||||||
import { useCallback, useContext, useMemo } from 'react';
|
import { useCallback, useContext, useMemo } from 'react';
|
||||||
import { toast } from 'react-hot-toast';
|
import { toast } from 'react-hot-toast';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { useHref } from 'react-router-dom';
|
|
||||||
|
|
||||||
import { requestTimeout } from '@/consts';
|
import { requestTimeout } from '@/consts';
|
||||||
import { AppDataContext } from '@/contexts/AppDataProvider';
|
import { AppDataContext } from '@/contexts/AppDataProvider';
|
||||||
import { TenantsContext } from '@/contexts/TenantsProvider';
|
import { TenantsContext } from '@/contexts/TenantsProvider';
|
||||||
|
|
||||||
import { useConfirmModal } from './use-confirm-modal';
|
import { useConfirmModal } from './use-confirm-modal';
|
||||||
|
import useRedirectUri from './use-redirect-uri';
|
||||||
|
|
||||||
export class RequestError extends Error {
|
export class RequestError extends Error {
|
||||||
constructor(
|
constructor(
|
||||||
|
@ -33,7 +33,7 @@ export const useStaticApi = ({ prefixUrl, hideErrorToast, resourceIndicator }: S
|
||||||
const { isAuthenticated, getAccessToken, signOut } = useLogto();
|
const { isAuthenticated, getAccessToken, signOut } = useLogto();
|
||||||
const { t, i18n } = useTranslation(undefined, { keyPrefix: 'admin_console' });
|
const { t, i18n } = useTranslation(undefined, { keyPrefix: 'admin_console' });
|
||||||
const { show } = useConfirmModal();
|
const { show } = useConfirmModal();
|
||||||
const href = useHref('/');
|
const postSignOutRedirectUri = useRedirectUri('signOut');
|
||||||
|
|
||||||
const toastError = useCallback(
|
const toastError = useCallback(
|
||||||
async (response: Response) => {
|
async (response: Response) => {
|
||||||
|
@ -51,7 +51,7 @@ export const useStaticApi = ({ prefixUrl, hideErrorToast, resourceIndicator }: S
|
||||||
cancelButtonText: 'general.got_it',
|
cancelButtonText: 'general.got_it',
|
||||||
});
|
});
|
||||||
|
|
||||||
await signOut(href);
|
await signOut(postSignOutRedirectUri.href);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ export const useStaticApi = ({ prefixUrl, hideErrorToast, resourceIndicator }: S
|
||||||
toast.error(httpCodeToMessage[response.status] ?? fallbackErrorMessage);
|
toast.error(httpCodeToMessage[response.status] ?? fallbackErrorMessage);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[show, signOut, t, href]
|
[show, signOut, t, postSignOutRedirectUri]
|
||||||
);
|
);
|
||||||
|
|
||||||
const api = useMemo(
|
const api = useMemo(
|
||||||
|
@ -73,7 +73,6 @@ export const useStaticApi = ({ prefixUrl, hideErrorToast, resourceIndicator }: S
|
||||||
!hideErrorToast &&
|
!hideErrorToast &&
|
||||||
(async (error) => {
|
(async (error) => {
|
||||||
await toastError(error.response);
|
await toastError(error.response);
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
})
|
})
|
||||||
),
|
),
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { ossConsolePath } from '@logto/schemas';
|
import { ossConsolePath } from '@logto/schemas';
|
||||||
import { conditionalArray } from '@silverhand/essentials';
|
import { conditionalArray, joinPath } from '@silverhand/essentials';
|
||||||
import { useHref } from 'react-router-dom';
|
import { useHref } from 'react-router-dom';
|
||||||
|
|
||||||
import { isCloud } from '@/consts/env';
|
import { isCloud } from '@/consts/env';
|
||||||
|
@ -11,7 +11,7 @@ import { isCloud } from '@/consts/env';
|
||||||
*/
|
*/
|
||||||
const useRedirectUri = (flow: 'signIn' | 'signOut' = 'signIn') => {
|
const useRedirectUri = (flow: 'signIn' | 'signOut' = 'signIn') => {
|
||||||
const path = useHref(
|
const path = useHref(
|
||||||
conditionalArray(!isCloud && ossConsolePath, flow === 'signIn' && '/callback').join('')
|
joinPath(...conditionalArray(!isCloud && ossConsolePath, flow === 'signIn' ? '/callback' : '/'))
|
||||||
);
|
);
|
||||||
|
|
||||||
return new URL(path, window.location.origin);
|
return new URL(path, window.location.origin);
|
||||||
|
|
Loading…
Reference in a new issue