diff --git a/apps/xi.web/src/pages/__root.tsx b/apps/xi.web/src/pages/__root.tsx index 353c77efc..382206bcf 100644 --- a/apps/xi.web/src/pages/__root.tsx +++ b/apps/xi.web/src/pages/__root.tsx @@ -63,6 +63,14 @@ export const Route = createRootRouteWithContext()({ !location.pathname.includes('/signup') && !location.pathname.includes('/reset-password') ) { + if (location.pathname.startsWith('/invite/') && typeof window !== 'undefined') { + const segments = location.pathname.split('/'); + const inviteId = segments[segments.length - 1]; + if (inviteId) { + localStorage.setItem('invite.pending_code', inviteId); + } + } + throw redirect({ to: '/signin', search: { diff --git a/packages/pages.invites/src/ui/InvitesPage.tsx b/packages/pages.invites/src/ui/InvitesPage.tsx index c172e2396..5434d2f6e 100644 --- a/packages/pages.invites/src/ui/InvitesPage.tsx +++ b/packages/pages.invites/src/ui/InvitesPage.tsx @@ -1,5 +1,6 @@ import { Logo } from 'common.ui'; import { useParams } from '@tanstack/react-router'; +import { useEffect } from 'react'; import { Invite } from './Invite'; import { ErrorInvite } from './ErrorInvite'; import { useInvitePreview } from '../services'; @@ -8,6 +9,10 @@ export const InvitesPage = () => { const { inviteId } = useParams({ strict: false }) as { inviteId: string }; const { data, error, isLoading } = useInvitePreview(inviteId); + useEffect(() => { + localStorage.removeItem('invite.pending_code'); + }, []); + if (isLoading) { return (
diff --git a/packages/pages.welcome/src/hooks/useWelcomeSocialsForm.tsx b/packages/pages.welcome/src/hooks/useWelcomeSocialsForm.tsx index 2b4a007e7..f9c33bafb 100644 --- a/packages/pages.welcome/src/hooks/useWelcomeSocialsForm.tsx +++ b/packages/pages.welcome/src/hooks/useWelcomeSocialsForm.tsx @@ -18,10 +18,18 @@ export const useWelcomeSocialsForm = () => { // Небольшая задержка для обновления данных пользователя await new Promise((resolve) => setTimeout(resolve, 100)); - if (search.invite) { + const storedInviteId = + typeof window !== 'undefined' ? localStorage.getItem('invite.pending_code') : null; + + const inviteId = storedInviteId || search.invite; + + if (inviteId) { + if (storedInviteId) { + localStorage.removeItem('invite.pending_code'); + } navigate({ to: '/invite/$inviteId', - params: { inviteId: search.invite }, + params: { inviteId }, }); } else { navigate({