0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00

refactor(console): redirect to sign-up page on clicking invitation links (#5669)

This commit is contained in:
Charles Zhao 2024-04-10 14:53:50 +08:00 committed by GitHub
parent 637c971eb0
commit b33de029e2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,7 +1,7 @@
import { useLogto } from '@logto/react';
import { yes, conditional } from '@silverhand/essentials';
import { useContext, useEffect } from 'react';
import { Outlet, useSearchParams } from 'react-router-dom';
import { Outlet, useMatch, useSearchParams } from 'react-router-dom';
import { useCloudApi } from '@/cloud/hooks/use-cloud-api';
import AppLoading from '@/components/AppLoading';
@ -35,14 +35,16 @@ export default function ProtectedRoutes() {
const { isAuthenticated, isLoading, signIn } = useLogto();
const { isInitComplete, resetTenants } = useContext(TenantsContext);
const redirectUri = useRedirectUri();
const match = useMatch('/accept/:invitationId');
useEffect(() => {
if (!isLoading && !isAuthenticated) {
saveRedirect();
const isSignUpMode = yes(searchParameters.get(searchKeys.signUp));
const isInvitationLink = Boolean(match?.pathname.startsWith('/accept/'));
const isSignUpMode = yes(searchParameters.get(searchKeys.signUp)) || isInvitationLink;
void signIn(redirectUri.href, conditional(isSignUpMode && 'signUp'));
}
}, [redirectUri, isAuthenticated, isLoading, searchParameters, signIn]);
}, [redirectUri, isAuthenticated, isLoading, searchParameters, signIn, match?.pathname]);
useEffect(() => {
if (isAuthenticated && !isInitComplete) {