diff --git a/web/hooks/use-sign-in-redirection.ts b/web/hooks/use-sign-in-redirection.ts index 0427ee2f5..6a32aa90c 100644 --- a/web/hooks/use-sign-in-redirection.ts +++ b/web/hooks/use-sign-in-redirection.ts @@ -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 () => {