Fix root domain /authorize rendering workspace-scoped consent page (#22641)
<!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/twentyhq/twenty/pull/22641?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="Review in cubic" src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a> <!-- End of auto-generated description by cubic. -->
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
import { createSearchParams, Navigate, useLocation } from 'react-router-dom';
|
||||
import { AppPath } from 'twenty-shared/types';
|
||||
|
||||
export const RootAuthorizeRedirect = () => {
|
||||
const { hash, pathname, search } = useLocation();
|
||||
|
||||
const returnToPath = `${pathname}${search}${hash}`;
|
||||
|
||||
return (
|
||||
<Navigate
|
||||
to={{
|
||||
pathname: AppPath.SignInUp,
|
||||
search: createSearchParams({ returnToPath }).toString(),
|
||||
}}
|
||||
replace
|
||||
/>
|
||||
);
|
||||
};
|
||||
@@ -9,6 +9,7 @@ import { AppPath } from 'twenty-shared/types';
|
||||
|
||||
import { LazyRoute } from '@/app/components/LazyRoute';
|
||||
import { RootAppProviders } from '@/app/components/RootAppProviders';
|
||||
import { RootAuthorizeRedirect } from '@/app/components/RootAuthorizeRedirect';
|
||||
import { VerifyEmail } from '@/auth/components/VerifyEmail';
|
||||
import { OnboardingPageLoader } from '@/onboarding/components/OnboardingPageLoader';
|
||||
import { OnboardingTransitionOutlet } from '@/onboarding/components/OnboardingTransitionOutlet';
|
||||
@@ -21,12 +22,6 @@ const SignInUp = lazy(() =>
|
||||
})),
|
||||
);
|
||||
|
||||
const Authorize = lazy(() =>
|
||||
import('~/pages/auth/Authorize').then((module) => ({
|
||||
default: module.Authorize,
|
||||
})),
|
||||
);
|
||||
|
||||
const PasswordReset = lazy(() =>
|
||||
import('~/pages/auth/PasswordReset').then((module) => ({
|
||||
default: module.PasswordReset,
|
||||
@@ -68,14 +63,7 @@ const createRootAppRouter = () =>
|
||||
}
|
||||
/>
|
||||
</Route>
|
||||
<Route
|
||||
path={AppPath.Authorize}
|
||||
element={
|
||||
<LazyRoute>
|
||||
<Authorize />
|
||||
</LazyRoute>
|
||||
}
|
||||
/>
|
||||
<Route path={AppPath.Authorize} element={<RootAuthorizeRedirect />} />
|
||||
<Route
|
||||
path={AppPath.NotFoundWildcard}
|
||||
element={<Navigate to={AppPath.SignInUp} replace />}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { isAppEffectRedirectEnabledState } from '@/app/states/isAppEffectRedirectEnabledState';
|
||||
import { useAuth } from '@/auth/hooks/useAuth';
|
||||
import { tokenPairState } from '@/auth/states/tokenPairState';
|
||||
import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar';
|
||||
@@ -10,10 +11,15 @@ export const useVerifyLogin = () => {
|
||||
const { enqueueErrorSnackBar } = useSnackBar();
|
||||
const navigate = useNavigateApp();
|
||||
const setTokenPair = useSetAtomState(tokenPairState);
|
||||
const setIsAppEffectRedirectEnabled = useSetAtomState(
|
||||
isAppEffectRedirectEnabledState,
|
||||
);
|
||||
const { getAuthTokensFromLoginToken } = useAuth();
|
||||
const { t } = useLingui();
|
||||
|
||||
const verifyLoginToken = async (loginToken: string) => {
|
||||
// Keeps PageChangeEffect from consuming returnToPath mid token swap
|
||||
setIsAppEffectRedirectEnabled(false);
|
||||
setTokenPair(null);
|
||||
try {
|
||||
await getAuthTokensFromLoginToken(loginToken);
|
||||
@@ -22,6 +28,8 @@ export const useVerifyLogin = () => {
|
||||
message: t`Authentication failed`,
|
||||
});
|
||||
navigate(AppPath.SignInUp);
|
||||
} finally {
|
||||
setIsAppEffectRedirectEnabled(true);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user