10e140495c
After investiagting the different options ([see related issue](https://github.com/twentyhq/core-team-issues/issues/660#issuecomment-2766030972)) I decided to add a "Verify Component" and a to build a custom Layout for this route. Reason I cannot use the default one is to have all preloaded once the user changes website and lands on the verify route. Reason I did not modify the DefaultLayout to match our need is that is would require many changes in order to avoid preloading states for our specific usecase. Fixes https://github.com/twentyhq/core-team-issues/issues/660 --------- Co-authored-by: Charles Bochet <charles@twenty.com>
42 lines
1.4 KiB
TypeScript
42 lines
1.4 KiB
TypeScript
import { useEffect } from 'react';
|
|
import { useSearchParams } from 'react-router-dom';
|
|
|
|
import { useIsLogged } from '@/auth/hooks/useIsLogged';
|
|
import { useVerifyLogin } from '@/auth/hooks/useVerifyLogin';
|
|
import { AppPath } from '@/types/AppPath';
|
|
import { SnackBarVariant } from '@/ui/feedback/snack-bar-manager/components/SnackBar';
|
|
import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar';
|
|
import { isDefined } from 'twenty-shared/utils';
|
|
import { useNavigateApp } from '~/hooks/useNavigateApp';
|
|
import { SignInUpLoading } from '~/pages/auth/SignInUpLoading';
|
|
|
|
export const Verify = () => {
|
|
const [searchParams] = useSearchParams();
|
|
const loginToken = searchParams.get('loginToken');
|
|
const errorMessage = searchParams.get('errorMessage');
|
|
|
|
const { enqueueSnackBar } = useSnackBar();
|
|
const isLogged = useIsLogged();
|
|
const navigate = useNavigateApp();
|
|
const { verifyLoginToken } = useVerifyLogin();
|
|
|
|
useEffect(() => {
|
|
if (isDefined(errorMessage)) {
|
|
enqueueSnackBar(errorMessage, {
|
|
dedupeKey: 'get-auth-tokens-from-login-token-failed-dedupe-key',
|
|
variant: SnackBarVariant.Error,
|
|
});
|
|
}
|
|
|
|
if (isDefined(loginToken)) {
|
|
verifyLoginToken(loginToken);
|
|
} else if (!isLogged) {
|
|
navigate(AppPath.SignInUp);
|
|
}
|
|
// Verify only needs to run once at mount
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, []);
|
|
|
|
return <SignInUpLoading />;
|
|
};
|