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;
// 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");
})