forked from github/plane
fix: sign in redirection flicker (#4245)
This commit is contained in:
parent
beff8536c9
commit
270f7c4503
@ -1,9 +1,9 @@
|
||||
import { useCallback, useState } from "react";
|
||||
import { useRouter } from "next/router";
|
||||
// hooks
|
||||
import { useUser } from "@/hooks/store";
|
||||
// types
|
||||
import { IUser, IUserSettings } from "@plane/types";
|
||||
import { IUser, IUserSettings, IWorkspace } from "@plane/types";
|
||||
// hooks
|
||||
import { useUser, useWorkspace } from "@/hooks/store";
|
||||
|
||||
type UseSignInRedirectionProps = {
|
||||
error: any | null;
|
||||
@ -20,6 +20,7 @@ const useSignInRedirection = (): UseSignInRedirectionProps => {
|
||||
const { next_path } = router.query;
|
||||
// mobx store
|
||||
const { fetchCurrentUser, fetchCurrentUserSettings } = useUser();
|
||||
const { fetchWorkspaces } = useWorkspace();
|
||||
|
||||
const isValidURL = (url: string): boolean => {
|
||||
const disallowedSchemes = /^(https?|ftp):\/\//i;
|
||||
@ -47,20 +48,26 @@ const useSignInRedirection = (): UseSignInRedirectionProps => {
|
||||
|
||||
// Fetch the current user settings
|
||||
const userSettings: IUserSettings = await fetchCurrentUserSettings();
|
||||
const workspacesList: IWorkspace[] = await fetchWorkspaces();
|
||||
|
||||
// Extract workspace details
|
||||
const workspaceSlug =
|
||||
userSettings?.workspace?.last_workspace_slug || userSettings?.workspace?.fallback_workspace_slug;
|
||||
|
||||
// Redirect based on workspace details or to profile if not available
|
||||
if (workspaceSlug) router.push(`/${workspaceSlug}`);
|
||||
if (
|
||||
workspaceSlug &&
|
||||
workspacesList &&
|
||||
workspacesList.filter((workspace) => workspace.slug === workspaceSlug).length > 0
|
||||
)
|
||||
router.push(`/${workspaceSlug}`);
|
||||
else router.push("/profile");
|
||||
} catch (error) {
|
||||
console.error("Error in handleSignInRedirection:", error);
|
||||
setError(error);
|
||||
}
|
||||
},
|
||||
[fetchCurrentUserSettings, router, next_path]
|
||||
[fetchCurrentUserSettings, fetchWorkspaces, router, next_path]
|
||||
);
|
||||
|
||||
const updateUserInfo = useCallback(async () => {
|
||||
|
Loading…
Reference in New Issue
Block a user