From 52474715de2b5edaa4d74f8279aff9106568d06d Mon Sep 17 00:00:00 2001 From: guru_sainath Date: Tue, 31 Oct 2023 12:04:36 +0530 Subject: [PATCH] chore: handled next_url redirection issue (#2562) --- web/components/page-views/signin.tsx | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/web/components/page-views/signin.tsx b/web/components/page-views/signin.tsx index 23a1ea634..e0be15e31 100644 --- a/web/components/page-views/signin.tsx +++ b/web/components/page-views/signin.tsx @@ -32,6 +32,8 @@ export const SignInView = observer(() => { const { fetchCurrentUserSettings } = userStore; // router const router = useRouter(); + const { next: next_url } = router.query as { next: string }; + // states const [isLoading, setLoading] = useState(false); // toast @@ -46,15 +48,17 @@ export const SignInView = observer(() => { useEffect(() => { fetchCurrentUserSettings().then((settings) => { setLoading(true); - router.push( - `/${ - settings.workspace.last_workspace_slug - ? settings.workspace.last_workspace_slug - : settings.workspace.fallback_workspace_slug - }` - ); + if (next_url) router.push(next_url); + else + router.push( + `/${ + settings.workspace.last_workspace_slug + ? settings.workspace.last_workspace_slug + : settings.workspace.fallback_workspace_slug + }` + ); }); - }, [fetchCurrentUserSettings, router]); + }, [fetchCurrentUserSettings, router, next_url]); const handleLoginRedirection = () => { userStore.fetchCurrentUser().then((user) => { @@ -65,7 +69,8 @@ export const SignInView = observer(() => { .then((userSettings: IUserSettings) => { const workspaceSlug = userSettings?.workspace?.last_workspace_slug || userSettings?.workspace?.fallback_workspace_slug; - if (workspaceSlug) router.push(`/${workspaceSlug}`); + if (next_url) router.push(next_url); + else if (workspaceSlug) router.push(`/${workspaceSlug}`); else if (userSettings.workspace.invites > 0) router.push("/invitations"); else router.push("/create-workspace"); })