forked from github/plane
fix: weird redirection in index page (#801)
This commit is contained in:
parent
9196fb4562
commit
db488338fb
@ -67,19 +67,17 @@ export const WorkspaceSidebarDropdown = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleSignOut = async () => {
|
const handleSignOut = async () => {
|
||||||
await authenticationService
|
router.push("/signin").then(() => {
|
||||||
.signOut()
|
mutateUser();
|
||||||
.catch(() =>
|
});
|
||||||
|
|
||||||
|
await authenticationService.signOut().catch(() =>
|
||||||
setToastAlert({
|
setToastAlert({
|
||||||
type: "error",
|
type: "error",
|
||||||
title: "Error!",
|
title: "Error!",
|
||||||
message: "Failed to sign out. Please try again.",
|
message: "Failed to sign out. Please try again.",
|
||||||
})
|
})
|
||||||
)
|
);
|
||||||
.finally(() => {
|
|
||||||
router.push("/signin");
|
|
||||||
mutateUser();
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -19,46 +19,55 @@ import { USER_WORKSPACE_INVITATIONS } from "constants/fetch-keys";
|
|||||||
const Home: NextPage = () => {
|
const Home: NextPage = () => {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const { user } = useUser();
|
const { user, isUserLoading } = useUser();
|
||||||
const { workspaces } = useWorkspaces();
|
const { workspaces, error: workspacesError } = useWorkspaces();
|
||||||
|
|
||||||
const lastActiveWorkspace =
|
const lastActiveWorkspace =
|
||||||
user && workspaces.find((workspace) => workspace.id === user.last_workspace_id);
|
user && workspaces.find((workspace) => workspace.id === user.last_workspace_id);
|
||||||
|
|
||||||
const { data: invitations } = useSWR(USER_WORKSPACE_INVITATIONS, () =>
|
const { data: invitations, error: invitationsError } = useSWR(USER_WORKSPACE_INVITATIONS, () =>
|
||||||
workspaceService.userWorkspaceInvitations()
|
workspaceService.userWorkspaceInvitations()
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (isUserLoading) return;
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
router.push("/signin");
|
router.push("/signin");
|
||||||
return;
|
return;
|
||||||
}
|
} else if (!user.is_onboarded) {
|
||||||
|
|
||||||
if (!user.is_onboarded) {
|
|
||||||
router.push("/onboarding");
|
router.push("/onboarding");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!user || (!workspaces && !workspacesError)) return;
|
||||||
|
|
||||||
if (lastActiveWorkspace) {
|
if (lastActiveWorkspace) {
|
||||||
router.push(`/${lastActiveWorkspace.slug}`);
|
router.push(`/${lastActiveWorkspace.slug}`);
|
||||||
return;
|
return;
|
||||||
} else if (workspaces.length > 0) {
|
} else if (workspaces.length > 0) {
|
||||||
router.push(`/${workspaces[0].slug}`);
|
router.push(`/${workspaces[0].slug}`);
|
||||||
return;
|
return;
|
||||||
}
|
} else if (!invitationsError && invitations && invitations.length > 0) {
|
||||||
|
|
||||||
if (invitations && invitations.length > 0) {
|
|
||||||
router.push("/invitations");
|
router.push("/invitations");
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
router.push("/create-workspace");
|
router.push("/create-workspace");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}, [user, router, lastActiveWorkspace, workspaces, invitations]);
|
}, [
|
||||||
|
invitations,
|
||||||
|
invitationsError,
|
||||||
|
isUserLoading,
|
||||||
|
lastActiveWorkspace,
|
||||||
|
user,
|
||||||
|
workspaces,
|
||||||
|
router,
|
||||||
|
workspacesError,
|
||||||
|
]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="h-screen grid place-items-center">
|
<div className="grid h-screen place-items-center">
|
||||||
<Spinner />
|
<Spinner />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user