diff --git a/web/components/page-views/signup.tsx b/web/components/page-views/signup.tsx index a294a5e0e..15ed20fb1 100644 --- a/web/components/page-views/signup.tsx +++ b/web/components/page-views/signup.tsx @@ -1,19 +1,16 @@ -import React, { useEffect } from "react"; +import React from "react"; import { observer } from "mobx-react"; import Image from "next/image"; import Link from "next/link"; // ui import { useTheme } from "next-themes"; -import { Spinner } from "@plane/ui"; // components import { SignUpAuthRoot } from "@/components/account"; import { PageHead } from "@/components/core"; // constants import { NAVIGATE_TO_SIGNIN } from "@/constants/event-tracker"; // hooks -import { useEventTracker, useInstance, useUser } from "@/hooks/store"; -import useAuthRedirection from "@/hooks/use-auth-redirection"; -// types +import { useEventTracker } from "@/hooks/store"; // assets import PlaneBackgroundPatternDark from "public/onboarding/background-pattern-dark.svg"; import PlaneBackgroundPattern from "public/onboarding/background-pattern.svg"; @@ -21,24 +18,10 @@ import BluePlaneLogoWithoutText from "public/plane-logos/blue-without-text.png"; export const SignUpView = observer(() => { // store hooks - const { instance } = useInstance(); - const { data: currentUser } = useUser(); const { captureEvent } = useEventTracker(); // hooks const { resolvedTheme } = useTheme(); // login redirection hook - const { isRedirecting, handleRedirection } = useAuthRedirection(); - - useEffect(() => { - handleRedirection(); - }, [handleRedirection]); - - if (isRedirecting || currentUser || !instance?.config) - return ( -
- -
- ); return (
diff --git a/web/lib/wrappers/authentication-wrapper.tsx b/web/lib/wrappers/authentication-wrapper.tsx index 62ddcdbc0..b775c87c4 100644 --- a/web/lib/wrappers/authentication-wrapper.tsx +++ b/web/lib/wrappers/authentication-wrapper.tsx @@ -34,10 +34,14 @@ export const AuthenticationWrapper: FC = (props) => { } = useUser(); const { loader: workspaceLoader, workspaces, fetchWorkspaces } = useWorkspace(); + useSWR("USER_INFORMATION", () => fetchCurrentUser(), { + revalidateOnFocus: false, + shouldRetryOnError: false, + }); + useSWR( - "USER_PROFILE_SETTINGS_INFORMATION", + currentUser && currentUser?.id ? "USER_PROFILE_SETTINGS_INFORMATION" : null, async () => { - await fetchCurrentUser(); if (currentUser) { fetchCurrentUserSettings(); fetchUserProfile(); @@ -80,7 +84,7 @@ export const AuthenticationWrapper: FC = (props) => { if (pageType === EPageTypes.PUBLIC) return <>{children}; if (pageType === EPageTypes.NON_AUTHENTICATED) { - if (!currentUser) return <>{children}; + if (!currentUser?.id) return <>{children}; else { if (currentUserProfile?.is_onboarded) { const currentRedirectRoute = getWorkspaceRedirectionUrl(); @@ -94,7 +98,7 @@ export const AuthenticationWrapper: FC = (props) => { } if (pageType === EPageTypes.ONBOARDING) { - if (!currentUser) { + if (!currentUser?.id) { router.push("/accounts/sign-in"); return; } else { @@ -107,7 +111,7 @@ export const AuthenticationWrapper: FC = (props) => { } if (pageType === EPageTypes.AUTHENTICATED) { - if (currentUser) { + if (currentUser?.id) { if (currentUserProfile?.is_onboarded) { return <>{children}; } else { diff --git a/web/pages/accounts/forgot-password.tsx b/web/pages/accounts/forgot-password.tsx index b33fd7a6c..560a61662 100644 --- a/web/pages/accounts/forgot-password.tsx +++ b/web/pages/accounts/forgot-password.tsx @@ -1,4 +1,4 @@ -import { ReactElement, useEffect } from "react"; +import { ReactElement } from "react"; import Image from "next/image"; import Link from "next/link"; import { useRouter } from "next/router"; @@ -7,7 +7,7 @@ import { Controller, useForm } from "react-hook-form"; // icons import { CircleCheck } from "lucide-react"; // ui -import { Button, Input, Spinner, TOAST_TYPE, getButtonStyling, setToast } from "@plane/ui"; +import { Button, Input, TOAST_TYPE, getButtonStyling, setToast } from "@plane/ui"; // components import { PageHead } from "@/components/core"; // constants @@ -18,7 +18,6 @@ import { cn } from "@/helpers/common.helper"; import { checkEmailValidity } from "@/helpers/string.helper"; // hooks import { useEventTracker } from "@/hooks/store"; -import useAuthRedirection from "@/hooks/use-auth-redirection"; import useTimer from "@/hooks/use-timer"; // layouts import DefaultLayout from "@/layouts/default-layout"; @@ -54,11 +53,7 @@ const ForgotPasswordPage: NextPageWithLayout = () => { const { resolvedTheme } = useTheme(); // timer const { timer: resendTimerCode, setTimer: setResendCodeTimer } = useTimer(0); - const { isRedirecting, handleRedirection } = useAuthRedirection(); - useEffect(() => { - handleRedirection(); - }, [handleRedirection]); // form info const { control, @@ -100,13 +95,6 @@ const ForgotPasswordPage: NextPageWithLayout = () => { }); }; - if (isRedirecting) - return ( -
- -
- ); - return (
diff --git a/web/pages/accounts/reset-password.tsx b/web/pages/accounts/reset-password.tsx index a5740a731..6591fa131 100644 --- a/web/pages/accounts/reset-password.tsx +++ b/web/pages/accounts/reset-password.tsx @@ -5,7 +5,7 @@ import { useRouter } from "next/router"; import { useTheme } from "next-themes"; import { Eye, EyeOff } from "lucide-react"; // ui -import { Button, Input, Spinner } from "@plane/ui"; +import { Button, Input } from "@plane/ui"; // components import { PasswordStrengthMeter } from "@/components/account"; import { PageHead } from "@/components/core"; @@ -13,8 +13,6 @@ import { PageHead } from "@/components/core"; import { EPageTypes } from "@/helpers/authentication.helper"; import { API_BASE_URL } from "@/helpers/common.helper"; import { getPasswordStrength } from "@/helpers/password.helper"; -// hooks -import useAuthRedirection from "@/hooks/use-auth-redirection"; // layouts import DefaultLayout from "@/layouts/default-layout"; // lib @@ -56,14 +54,6 @@ const ResetPasswordPage: NextPageWithLayout = () => { const [isPasswordInputFocused, setIsPasswordInputFocused] = useState(false); // hooks const { resolvedTheme } = useTheme(); - // store hooks - //const { captureEvent } = useEventTracker(); - // sign in redirection hook - const { isRedirecting, handleRedirection } = useAuthRedirection(); - - useEffect(() => { - handleRedirection(); - }, [handleRedirection]); const handleFormChange = (key: keyof TResetPasswordFormValues, value: string) => setResetFormData((prev) => ({ ...prev, [key]: value })); @@ -83,13 +73,6 @@ const ResetPasswordPage: NextPageWithLayout = () => { [resetFormData] ); - if (isRedirecting) - return ( -
- -
- ); - return (
diff --git a/web/pages/accounts/set-password.tsx b/web/pages/accounts/set-password.tsx index 8fc7136e8..09c3eedec 100644 --- a/web/pages/accounts/set-password.tsx +++ b/web/pages/accounts/set-password.tsx @@ -2,11 +2,10 @@ import { FormEvent, ReactElement, useEffect, useMemo, useState } from "react"; import { observer } from "mobx-react-lite"; import Image from "next/image"; import { useRouter } from "next/router"; -import useSWR from "swr"; // icons import { Eye, EyeOff } from "lucide-react"; // ui -import { Button, Input, Spinner, TOAST_TYPE, setToast } from "@plane/ui"; +import { Button, Input, TOAST_TYPE, setToast } from "@plane/ui"; // components import { PasswordStrengthMeter } from "@/components/account"; import { PageHead } from "@/components/core"; @@ -14,7 +13,6 @@ import { PageHead } from "@/components/core"; import { getPasswordStrength } from "@/helpers/password.helper"; // hooks import { useUser } from "@/hooks/store"; -import useAuthRedirection from "@/hooks/use-auth-redirection"; // layouts import { UserAuthWrapper } from "@/layouts/auth-layout"; import DefaultLayout from "@/layouts/default-layout"; @@ -53,19 +51,7 @@ const SetPasswordPage: NextPageWithLayout = observer(() => { const [csrfToken, setCsrfToken] = useState(undefined); const [isPasswordInputFocused, setIsPasswordInputFocused] = useState(false); - const { data: user, fetchCurrentUser } = useUser(); - // store hooks - //const { captureEvent } = useEventTracker(); - // sign in redirection hook - const { isRedirecting, handleRedirection } = useAuthRedirection(); - - const { isLoading } = useSWR(`CURRENT_USER_DETAILS`, () => fetchCurrentUser(), { - shouldRetryOnError: false, - }); - - useEffect(() => { - if (user && !user?.is_password_autoset) handleRedirection(); - }, [handleRedirection, user?.is_password_autoset]); + const { data: user } = useUser(); useEffect(() => { if (csrfToken === undefined) @@ -94,7 +80,6 @@ const SetPasswordPage: NextPageWithLayout = observer(() => { try { e.preventDefault(); await handleSetPassword(passwordFormData.password); - await handleRedirection(); } catch (err: any) { setToast({ type: TOAST_TYPE.ERROR, @@ -104,13 +89,6 @@ const SetPasswordPage: NextPageWithLayout = observer(() => { } }; - if (isRedirecting || isLoading) - return ( -
- -
- ); - return (
diff --git a/web/pages/accounts/sign-in.tsx b/web/pages/accounts/sign-in.tsx index 40cad8eff..dc19bde80 100644 --- a/web/pages/accounts/sign-in.tsx +++ b/web/pages/accounts/sign-in.tsx @@ -1,10 +1,8 @@ -import { useEffect } from "react"; import { observer } from "mobx-react"; import Image from "next/image"; import Link from "next/link"; // ui import { useTheme } from "next-themes"; -import { Spinner } from "@plane/ui"; // components import { SignInAuthRoot } from "@/components/account"; import { PageHead } from "@/components/core"; @@ -13,8 +11,7 @@ import { NAVIGATE_TO_SIGNUP } from "@/constants/event-tracker"; // helpers import { EPageTypes } from "@/helpers/authentication.helper"; // hooks -import { useEventTracker, useInstance, useUser } from "@/hooks/store"; -import useAuthRedirection from "@/hooks/use-auth-redirection"; +import { useEventTracker } from "@/hooks/store"; // layouts import DefaultLayout from "@/layouts/default-layout"; // types @@ -30,24 +27,9 @@ export type AuthType = "sign-in" | "sign-up"; const SignInPage: NextPageWithLayout = observer(() => { // store hooks - const { instance } = useInstance(); - const { data: currentUser } = useUser(); const { captureEvent } = useEventTracker(); // hooks const { resolvedTheme } = useTheme(); - // login redirection hook - const { isRedirecting, handleRedirection } = useAuthRedirection(); - - useEffect(() => { - handleRedirection(); - }, [handleRedirection]); - - if (isRedirecting || currentUser || !instance?.config) - return ( -
- -
- ); return (