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:
parent
637c971eb0
commit
b33de029e2
1 changed files with 5 additions and 3 deletions
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue