fix(): sleep before redirect (#9079)
## Summary This Pull Request centralizes the redirection logic by introducing a reusable `useRedirect` hook, which replaces direct usage of `window.location.href` with more standardized and testable functionality across multiple modules. - Introduced a new `useRedirect` hook for handling redirection logic with optional controlled delays. - Refactored redirection implementations in various modules (`useAuth`, workspace, and settings-related hooks, etc.) to use the newly introduced `useRedirect` or related high-level hooks. - Updated API and documentation to include or improve support for SSO, particularly OIDC and SAML setup processes in server logic. - Enhanced frontend and backend configurability with new environment variable settings for SSO. --------- Co-authored-by: Félix Malfait <felix@twenty.com>
This commit is contained in:
@ -7,6 +7,7 @@ import {
|
||||
MessageChannelVisibility,
|
||||
useGenerateTransientTokenMutation,
|
||||
} from '~/generated/graphql';
|
||||
import { useRedirect } from '@/domain-manager/hooks/useRedirect';
|
||||
|
||||
const getProviderUrl = (provider: string) => {
|
||||
switch (provider) {
|
||||
@ -21,6 +22,7 @@ const getProviderUrl = (provider: string) => {
|
||||
|
||||
export const useTriggerApisOAuth = () => {
|
||||
const [generateTransientToken] = useGenerateTransientTokenMutation();
|
||||
const { redirect } = useRedirect();
|
||||
|
||||
const triggerApisOAuth = useCallback(
|
||||
async (
|
||||
@ -60,9 +62,9 @@ export const useTriggerApisOAuth = () => {
|
||||
|
||||
params += loginHint ? `&loginHint=${loginHint}` : '';
|
||||
|
||||
window.location.href = `${authServerUrl}/auth/${getProviderUrl(provider)}?${params}`;
|
||||
redirect(`${authServerUrl}/auth/${getProviderUrl(provider)}?${params}`);
|
||||
},
|
||||
[generateTransientToken],
|
||||
[generateTransientToken, redirect],
|
||||
);
|
||||
|
||||
return { triggerApisOAuth };
|
||||
|
||||
Reference in New Issue
Block a user