From 8d5ff1a62879770946c9af020f5a61ac2d2c3489 Mon Sep 17 00:00:00 2001 From: Aaryan Khandelwal Date: Tue, 5 Sep 2023 16:12:17 +0530 Subject: [PATCH] fix: redirection after signing in on space --- space/components/accounts/sign-in.tsx | 7 ++++--- space/store/user.ts | 12 ++++-------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/space/components/accounts/sign-in.tsx b/space/components/accounts/sign-in.tsx index 50d9c7da0..661675e07 100644 --- a/space/components/accounts/sign-in.tsx +++ b/space/components/accounts/sign-in.tsx @@ -19,7 +19,6 @@ export const SignInView = observer(() => { const { user: userStore } = useMobxStore(); const router = useRouter(); - const { next_path } = router.query; const { setToastAlert } = useToast(); @@ -34,13 +33,15 @@ export const SignInView = observer(() => { const onSignInSuccess = (response: any) => { const isOnboarded = response?.user?.onboarding_step?.profile_complete || false; + const nextPath = router.asPath.includes("next_path") ? router.asPath.split("/?next_path=")[1] : "/"; + userStore.setCurrentUser(response?.user); if (!isOnboarded) { - router.push(`/onboarding?next_path=${next_path}`); + router.push(`/onboarding?next_path=${nextPath}`); return; } - router.push((next_path ?? "/").toString()); + router.push((nextPath ?? "/").toString()); }; const handleGoogleSignIn = async ({ clientId, credential }: any) => { diff --git a/space/store/user.ts b/space/store/user.ts index 8d34b0bdc..3a76c2111 100644 --- a/space/store/user.ts +++ b/space/store/user.ts @@ -62,17 +62,13 @@ class UserStore implements IUserStore { return; } + const currentPath = window.location.pathname + window.location.search; this.fetchCurrentUser() .then(() => { - if (!this.currentUser) { - const currentPath = window.location.pathname; - window.location.href = `/?next_path=${currentPath}`; - } else callback(); + if (!this.currentUser) window.location.href = `/?next_path=${currentPath}`; + else callback(); }) - .catch(() => { - const currentPath = window.location.pathname; - window.location.href = `/?next_path=${currentPath}`; - }); + .catch(() => (window.location.href = `/?next_path=${currentPath}`)); }; fetchCurrentUser = async () => {