chore: handled next_url redirection issue (#2562)

This commit is contained in:
guru_sainath 2023-10-31 12:04:36 +05:30 committed by GitHub
parent dcf81e28e4
commit 52474715de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -32,6 +32,8 @@ export const SignInView = observer(() => {
const { fetchCurrentUserSettings } = userStore; const { fetchCurrentUserSettings } = userStore;
// router // router
const router = useRouter(); const router = useRouter();
const { next: next_url } = router.query as { next: string };
// states // states
const [isLoading, setLoading] = useState(false); const [isLoading, setLoading] = useState(false);
// toast // toast
@ -46,15 +48,17 @@ export const SignInView = observer(() => {
useEffect(() => { useEffect(() => {
fetchCurrentUserSettings().then((settings) => { fetchCurrentUserSettings().then((settings) => {
setLoading(true); setLoading(true);
router.push( if (next_url) router.push(next_url);
`/${ else
settings.workspace.last_workspace_slug router.push(
? settings.workspace.last_workspace_slug `/${
: settings.workspace.fallback_workspace_slug settings.workspace.last_workspace_slug
}` ? settings.workspace.last_workspace_slug
); : settings.workspace.fallback_workspace_slug
}`
);
}); });
}, [fetchCurrentUserSettings, router]); }, [fetchCurrentUserSettings, router, next_url]);
const handleLoginRedirection = () => { const handleLoginRedirection = () => {
userStore.fetchCurrentUser().then((user) => { userStore.fetchCurrentUser().then((user) => {
@ -65,7 +69,8 @@ export const SignInView = observer(() => {
.then((userSettings: IUserSettings) => { .then((userSettings: IUserSettings) => {
const workspaceSlug = const workspaceSlug =
userSettings?.workspace?.last_workspace_slug || userSettings?.workspace?.fallback_workspace_slug; 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 if (userSettings.workspace.invites > 0) router.push("/invitations");
else router.push("/create-workspace"); else router.push("/create-workspace");
}) })