Files
twenty/front/src/pages/auth/Verify.tsx
T
Jérémy M 51cfc0d82c feat: refactoring casl permission checks for recursive nested operations (#778)
* feat: nested casl abilities

* fix: remove unused packages

* Fixes

* Fix createMany broken

* Fix lint

* Fix lint

* Fix lint

* Fix lint

* Fixes

* Fix CommentThread

* Fix bugs

* Fix lint

* Fix bugs

* Fixed auto routing

* Fixed app path

---------

Co-authored-by: Charles Bochet <charles@twenty.com>
Co-authored-by: Lucas Bordeau <bordeau.lucas@gmail.com>
2023-07-25 16:37:22 -07:00

47 lines
1.2 KiB
TypeScript

import { useEffect } from 'react';
import { useNavigate, useSearchParams } from 'react-router-dom';
import { useAuth } from '@/auth/hooks/useAuth';
import { useIsLogged } from '@/auth/hooks/useIsLogged';
import { AppPath } from '../../modules/types/AppPath';
import { isNonEmptyString } from '../../utils/isNonEmptyString';
export function Verify() {
const [searchParams] = useSearchParams();
const loginToken = searchParams.get('loginToken');
const isLogged = useIsLogged();
const navigate = useNavigate();
const { verify } = useAuth();
useEffect(() => {
async function getTokens() {
if (!loginToken) {
navigate(AppPath.SignIn);
} else {
const verifyResponse = await verify(loginToken);
if (
isNonEmptyString(
verifyResponse.user.workspaceMember?.workspace.displayName,
)
) {
navigate(AppPath.Index);
} else {
navigate(AppPath.CreateWorkspace);
}
}
}
if (!isLogged) {
getTokens();
}
// Verify only needs to run once at mount
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
return <></>;
}