Skip to content

Commit

Permalink
refactor(console): redirect to sign-up page on clicking invitation li…
Browse files Browse the repository at this point in the history
…nks (#5669)
  • Loading branch information
charIeszhao authored Apr 10, 2024
1 parent 637c971 commit b33de02
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/console/src/containers/ProtectedRoutes/index.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit b33de02

Please sign in to comment.