fix: sign in redirection flicker (#4245)

This commit is contained in:
Anmol Singh Bhatia 2024-04-23 12:57:10 +05:30 committed by GitHub
parent beff8536c9
commit 270f7c4503
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,9 +1,9 @@
import { useCallback, useState } from "react"; import { useCallback, useState } from "react";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
// hooks
import { useUser } from "@/hooks/store";
// types // types
import { IUser, IUserSettings } from "@plane/types"; import { IUser, IUserSettings, IWorkspace } from "@plane/types";
// hooks
import { useUser, useWorkspace } from "@/hooks/store";
type UseSignInRedirectionProps = { type UseSignInRedirectionProps = {
error: any | null; error: any | null;
@ -20,6 +20,7 @@ const useSignInRedirection = (): UseSignInRedirectionProps => {
const { next_path } = router.query; const { next_path } = router.query;
// mobx store // mobx store
const { fetchCurrentUser, fetchCurrentUserSettings } = useUser(); const { fetchCurrentUser, fetchCurrentUserSettings } = useUser();
const { fetchWorkspaces } = useWorkspace();
const isValidURL = (url: string): boolean => { const isValidURL = (url: string): boolean => {
const disallowedSchemes = /^(https?|ftp):\/\//i; const disallowedSchemes = /^(https?|ftp):\/\//i;
@ -47,20 +48,26 @@ const useSignInRedirection = (): UseSignInRedirectionProps => {
// Fetch the current user settings // Fetch the current user settings
const userSettings: IUserSettings = await fetchCurrentUserSettings(); const userSettings: IUserSettings = await fetchCurrentUserSettings();
const workspacesList: IWorkspace[] = await fetchWorkspaces();
// Extract workspace details // Extract workspace details
const workspaceSlug = const workspaceSlug =
userSettings?.workspace?.last_workspace_slug || userSettings?.workspace?.fallback_workspace_slug; userSettings?.workspace?.last_workspace_slug || userSettings?.workspace?.fallback_workspace_slug;
// Redirect based on workspace details or to profile if not available // 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"); else router.push("/profile");
} catch (error) { } catch (error) {
console.error("Error in handleSignInRedirection:", error); console.error("Error in handleSignInRedirection:", error);
setError(error); setError(error);
} }
}, },
[fetchCurrentUserSettings, router, next_path] [fetchCurrentUserSettings, fetchWorkspaces, router, next_path]
); );
const updateUserInfo = useCallback(async () => { const updateUserInfo = useCallback(async () => {