fix(core): should log in before accepting the invitation (#9150)

This commit is contained in:
JimmFly 2024-12-13 09:44:32 +00:00
parent 293a155977
commit 0de7782c9b
No known key found for this signature in database
GPG Key ID: 126E0320FEB0D05C

View File

@ -25,50 +25,44 @@ const AcceptInvite = ({
}: { }: {
inviteInfo: GetInviteInfoQuery['getInviteInfo']; inviteInfo: GetInviteInfoQuery['getInviteInfo'];
}) => { }) => {
const authService = useService(AuthService);
const isRevalidating = useLiveData(authService.session.isRevalidating$);
const loginStatus = useLiveData(authService.session.status$);
useEffect(() => {
authService.session.revalidate();
}, [authService]);
const { jumpToSignIn } = useNavigateHelper();
const { jumpToPage } = useNavigateHelper(); const { jumpToPage } = useNavigateHelper();
const openWorkspace = useCallback(() => { const openWorkspace = useCallback(() => {
jumpToPage(inviteInfo.workspace.id, 'all', RouteLogic.REPLACE); jumpToPage(inviteInfo.workspace.id, 'all', RouteLogic.REPLACE);
}, [inviteInfo.workspace.id, jumpToPage]); }, [inviteInfo.workspace.id, jumpToPage]);
return (
<AcceptInvitePage inviteInfo={inviteInfo} onOpenWorkspace={openWorkspace} />
);
};
export const Component = () => {
const authService = useService(AuthService);
const isRevalidating = useLiveData(authService.session.isRevalidating$);
const loginStatus = useLiveData(authService.session.status$);
const params = useParams<{ inviteId: string }>();
useEffect(() => {
authService.session.revalidate();
}, [authService]);
const { jumpToSignIn } = useNavigateHelper();
useEffect(() => { useEffect(() => {
if (loginStatus === 'unauthenticated' && !isRevalidating) { if (loginStatus === 'unauthenticated' && !isRevalidating) {
// We can not pass function to navigate state, so we need to save it in atom // We can not pass function to navigate state, so we need to save it in atom
jumpToSignIn( jumpToSignIn(`/invite/${params.inviteId}`, RouteLogic.REPLACE);
`/workspace/${inviteInfo.workspace.id}/all`,
RouteLogic.REPLACE
);
} }
}, [ }, [isRevalidating, jumpToSignIn, loginStatus, params.inviteId]);
inviteInfo.workspace.id,
isRevalidating,
jumpToSignIn,
loginStatus,
openWorkspace,
]);
if (loginStatus === 'authenticated') { if (loginStatus === 'authenticated') {
return ( return <Middle />;
<AcceptInvitePage
inviteInfo={inviteInfo}
onOpenWorkspace={openWorkspace}
/>
);
} }
return null; return null;
}; };
export const Component = () => { export const Middle = () => {
const graphqlService = useService(GraphQLService); const graphqlService = useService(GraphQLService);
const params = useParams<{ inviteId: string }>(); const params = useParams<{ inviteId: string }>();
const navigateHelper = useNavigateHelper(); const navigateHelper = useNavigateHelper();