chore: removed old auth hook

This commit is contained in:
gurusainath 2024-05-01 18:58:01 +05:30
parent 57da79392a
commit b87a43c8fe
6 changed files with 17 additions and 99 deletions

View File

@ -1,19 +1,16 @@
import React, { useEffect } from "react"; import React from "react";
import { observer } from "mobx-react"; import { observer } from "mobx-react";
import Image from "next/image"; import Image from "next/image";
import Link from "next/link"; import Link from "next/link";
// ui // ui
import { useTheme } from "next-themes"; import { useTheme } from "next-themes";
import { Spinner } from "@plane/ui";
// components // components
import { SignUpAuthRoot } from "@/components/account"; import { SignUpAuthRoot } from "@/components/account";
import { PageHead } from "@/components/core"; import { PageHead } from "@/components/core";
// constants // constants
import { NAVIGATE_TO_SIGNIN } from "@/constants/event-tracker"; import { NAVIGATE_TO_SIGNIN } from "@/constants/event-tracker";
// hooks // hooks
import { useEventTracker, useInstance, useUser } from "@/hooks/store"; import { useEventTracker } from "@/hooks/store";
import useAuthRedirection from "@/hooks/use-auth-redirection";
// types
// assets // assets
import PlaneBackgroundPatternDark from "public/onboarding/background-pattern-dark.svg"; import PlaneBackgroundPatternDark from "public/onboarding/background-pattern-dark.svg";
import PlaneBackgroundPattern from "public/onboarding/background-pattern.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(() => { export const SignUpView = observer(() => {
// store hooks // store hooks
const { instance } = useInstance();
const { data: currentUser } = useUser();
const { captureEvent } = useEventTracker(); const { captureEvent } = useEventTracker();
// hooks // hooks
const { resolvedTheme } = useTheme(); const { resolvedTheme } = useTheme();
// login redirection hook // login redirection hook
const { isRedirecting, handleRedirection } = useAuthRedirection();
useEffect(() => {
handleRedirection();
}, [handleRedirection]);
if (isRedirecting || currentUser || !instance?.config)
return (
<div className="grid h-screen place-items-center">
<Spinner />
</div>
);
return ( return (
<div className="relative"> <div className="relative">

View File

@ -34,10 +34,14 @@ export const AuthenticationWrapper: FC<TAuthenticationWrapper> = (props) => {
} = useUser(); } = useUser();
const { loader: workspaceLoader, workspaces, fetchWorkspaces } = useWorkspace(); const { loader: workspaceLoader, workspaces, fetchWorkspaces } = useWorkspace();
useSWR("USER_INFORMATION", () => fetchCurrentUser(), {
revalidateOnFocus: false,
shouldRetryOnError: false,
});
useSWR( useSWR(
"USER_PROFILE_SETTINGS_INFORMATION", currentUser && currentUser?.id ? "USER_PROFILE_SETTINGS_INFORMATION" : null,
async () => { async () => {
await fetchCurrentUser();
if (currentUser) { if (currentUser) {
fetchCurrentUserSettings(); fetchCurrentUserSettings();
fetchUserProfile(); fetchUserProfile();
@ -80,7 +84,7 @@ export const AuthenticationWrapper: FC<TAuthenticationWrapper> = (props) => {
if (pageType === EPageTypes.PUBLIC) return <>{children}</>; if (pageType === EPageTypes.PUBLIC) return <>{children}</>;
if (pageType === EPageTypes.NON_AUTHENTICATED) { if (pageType === EPageTypes.NON_AUTHENTICATED) {
if (!currentUser) return <>{children}</>; if (!currentUser?.id) return <>{children}</>;
else { else {
if (currentUserProfile?.is_onboarded) { if (currentUserProfile?.is_onboarded) {
const currentRedirectRoute = getWorkspaceRedirectionUrl(); const currentRedirectRoute = getWorkspaceRedirectionUrl();
@ -94,7 +98,7 @@ export const AuthenticationWrapper: FC<TAuthenticationWrapper> = (props) => {
} }
if (pageType === EPageTypes.ONBOARDING) { if (pageType === EPageTypes.ONBOARDING) {
if (!currentUser) { if (!currentUser?.id) {
router.push("/accounts/sign-in"); router.push("/accounts/sign-in");
return; return;
} else { } else {
@ -107,7 +111,7 @@ export const AuthenticationWrapper: FC<TAuthenticationWrapper> = (props) => {
} }
if (pageType === EPageTypes.AUTHENTICATED) { if (pageType === EPageTypes.AUTHENTICATED) {
if (currentUser) { if (currentUser?.id) {
if (currentUserProfile?.is_onboarded) { if (currentUserProfile?.is_onboarded) {
return <>{children}</>; return <>{children}</>;
} else { } else {

View File

@ -1,4 +1,4 @@
import { ReactElement, useEffect } from "react"; import { ReactElement } from "react";
import Image from "next/image"; import Image from "next/image";
import Link from "next/link"; import Link from "next/link";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
@ -7,7 +7,7 @@ import { Controller, useForm } from "react-hook-form";
// icons // icons
import { CircleCheck } from "lucide-react"; import { CircleCheck } from "lucide-react";
// ui // ui
import { Button, Input, Spinner, TOAST_TYPE, getButtonStyling, setToast } from "@plane/ui"; import { Button, Input, TOAST_TYPE, getButtonStyling, setToast } from "@plane/ui";
// components // components
import { PageHead } from "@/components/core"; import { PageHead } from "@/components/core";
// constants // constants
@ -18,7 +18,6 @@ import { cn } from "@/helpers/common.helper";
import { checkEmailValidity } from "@/helpers/string.helper"; import { checkEmailValidity } from "@/helpers/string.helper";
// hooks // hooks
import { useEventTracker } from "@/hooks/store"; import { useEventTracker } from "@/hooks/store";
import useAuthRedirection from "@/hooks/use-auth-redirection";
import useTimer from "@/hooks/use-timer"; import useTimer from "@/hooks/use-timer";
// layouts // layouts
import DefaultLayout from "@/layouts/default-layout"; import DefaultLayout from "@/layouts/default-layout";
@ -54,11 +53,7 @@ const ForgotPasswordPage: NextPageWithLayout = () => {
const { resolvedTheme } = useTheme(); const { resolvedTheme } = useTheme();
// timer // timer
const { timer: resendTimerCode, setTimer: setResendCodeTimer } = useTimer(0); const { timer: resendTimerCode, setTimer: setResendCodeTimer } = useTimer(0);
const { isRedirecting, handleRedirection } = useAuthRedirection();
useEffect(() => {
handleRedirection();
}, [handleRedirection]);
// form info // form info
const { const {
control, control,
@ -100,13 +95,6 @@ const ForgotPasswordPage: NextPageWithLayout = () => {
}); });
}; };
if (isRedirecting)
return (
<div className="grid h-screen place-items-center">
<Spinner />
</div>
);
return ( return (
<div className="relative"> <div className="relative">
<PageHead title="Forgot Password" /> <PageHead title="Forgot Password" />

View File

@ -5,7 +5,7 @@ import { useRouter } from "next/router";
import { useTheme } from "next-themes"; import { useTheme } from "next-themes";
import { Eye, EyeOff } from "lucide-react"; import { Eye, EyeOff } from "lucide-react";
// ui // ui
import { Button, Input, Spinner } from "@plane/ui"; import { Button, Input } from "@plane/ui";
// components // components
import { PasswordStrengthMeter } from "@/components/account"; import { PasswordStrengthMeter } from "@/components/account";
import { PageHead } from "@/components/core"; import { PageHead } from "@/components/core";
@ -13,8 +13,6 @@ import { PageHead } from "@/components/core";
import { EPageTypes } from "@/helpers/authentication.helper"; import { EPageTypes } from "@/helpers/authentication.helper";
import { API_BASE_URL } from "@/helpers/common.helper"; import { API_BASE_URL } from "@/helpers/common.helper";
import { getPasswordStrength } from "@/helpers/password.helper"; import { getPasswordStrength } from "@/helpers/password.helper";
// hooks
import useAuthRedirection from "@/hooks/use-auth-redirection";
// layouts // layouts
import DefaultLayout from "@/layouts/default-layout"; import DefaultLayout from "@/layouts/default-layout";
// lib // lib
@ -56,14 +54,6 @@ const ResetPasswordPage: NextPageWithLayout = () => {
const [isPasswordInputFocused, setIsPasswordInputFocused] = useState(false); const [isPasswordInputFocused, setIsPasswordInputFocused] = useState(false);
// hooks // hooks
const { resolvedTheme } = useTheme(); 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) => const handleFormChange = (key: keyof TResetPasswordFormValues, value: string) =>
setResetFormData((prev) => ({ ...prev, [key]: value })); setResetFormData((prev) => ({ ...prev, [key]: value }));
@ -83,13 +73,6 @@ const ResetPasswordPage: NextPageWithLayout = () => {
[resetFormData] [resetFormData]
); );
if (isRedirecting)
return (
<div className="grid h-screen place-items-center">
<Spinner />
</div>
);
return ( return (
<div className="relative"> <div className="relative">
<PageHead title="Reset Password" /> <PageHead title="Reset Password" />

View File

@ -2,11 +2,10 @@ import { FormEvent, ReactElement, useEffect, useMemo, useState } from "react";
import { observer } from "mobx-react-lite"; import { observer } from "mobx-react-lite";
import Image from "next/image"; import Image from "next/image";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
import useSWR from "swr";
// icons // icons
import { Eye, EyeOff } from "lucide-react"; import { Eye, EyeOff } from "lucide-react";
// ui // ui
import { Button, Input, Spinner, TOAST_TYPE, setToast } from "@plane/ui"; import { Button, Input, TOAST_TYPE, setToast } from "@plane/ui";
// components // components
import { PasswordStrengthMeter } from "@/components/account"; import { PasswordStrengthMeter } from "@/components/account";
import { PageHead } from "@/components/core"; import { PageHead } from "@/components/core";
@ -14,7 +13,6 @@ import { PageHead } from "@/components/core";
import { getPasswordStrength } from "@/helpers/password.helper"; import { getPasswordStrength } from "@/helpers/password.helper";
// hooks // hooks
import { useUser } from "@/hooks/store"; import { useUser } from "@/hooks/store";
import useAuthRedirection from "@/hooks/use-auth-redirection";
// layouts // layouts
import { UserAuthWrapper } from "@/layouts/auth-layout"; import { UserAuthWrapper } from "@/layouts/auth-layout";
import DefaultLayout from "@/layouts/default-layout"; import DefaultLayout from "@/layouts/default-layout";
@ -53,19 +51,7 @@ const SetPasswordPage: NextPageWithLayout = observer(() => {
const [csrfToken, setCsrfToken] = useState<string | undefined>(undefined); const [csrfToken, setCsrfToken] = useState<string | undefined>(undefined);
const [isPasswordInputFocused, setIsPasswordInputFocused] = useState(false); const [isPasswordInputFocused, setIsPasswordInputFocused] = useState(false);
const { data: user, fetchCurrentUser } = useUser(); const { data: user } = 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]);
useEffect(() => { useEffect(() => {
if (csrfToken === undefined) if (csrfToken === undefined)
@ -94,7 +80,6 @@ const SetPasswordPage: NextPageWithLayout = observer(() => {
try { try {
e.preventDefault(); e.preventDefault();
await handleSetPassword(passwordFormData.password); await handleSetPassword(passwordFormData.password);
await handleRedirection();
} catch (err: any) { } catch (err: any) {
setToast({ setToast({
type: TOAST_TYPE.ERROR, type: TOAST_TYPE.ERROR,
@ -104,13 +89,6 @@ const SetPasswordPage: NextPageWithLayout = observer(() => {
} }
}; };
if (isRedirecting || isLoading)
return (
<div className="grid h-screen place-items-center">
<Spinner />
</div>
);
return ( return (
<div className="relative"> <div className="relative">
<PageHead title="Reset Password" /> <PageHead title="Reset Password" />

View File

@ -1,10 +1,8 @@
import { useEffect } from "react";
import { observer } from "mobx-react"; import { observer } from "mobx-react";
import Image from "next/image"; import Image from "next/image";
import Link from "next/link"; import Link from "next/link";
// ui // ui
import { useTheme } from "next-themes"; import { useTheme } from "next-themes";
import { Spinner } from "@plane/ui";
// components // components
import { SignInAuthRoot } from "@/components/account"; import { SignInAuthRoot } from "@/components/account";
import { PageHead } from "@/components/core"; import { PageHead } from "@/components/core";
@ -13,8 +11,7 @@ import { NAVIGATE_TO_SIGNUP } from "@/constants/event-tracker";
// helpers // helpers
import { EPageTypes } from "@/helpers/authentication.helper"; import { EPageTypes } from "@/helpers/authentication.helper";
// hooks // hooks
import { useEventTracker, useInstance, useUser } from "@/hooks/store"; import { useEventTracker } from "@/hooks/store";
import useAuthRedirection from "@/hooks/use-auth-redirection";
// layouts // layouts
import DefaultLayout from "@/layouts/default-layout"; import DefaultLayout from "@/layouts/default-layout";
// types // types
@ -30,24 +27,9 @@ export type AuthType = "sign-in" | "sign-up";
const SignInPage: NextPageWithLayout = observer(() => { const SignInPage: NextPageWithLayout = observer(() => {
// store hooks // store hooks
const { instance } = useInstance();
const { data: currentUser } = useUser();
const { captureEvent } = useEventTracker(); const { captureEvent } = useEventTracker();
// hooks // hooks
const { resolvedTheme } = useTheme(); const { resolvedTheme } = useTheme();
// login redirection hook
const { isRedirecting, handleRedirection } = useAuthRedirection();
useEffect(() => {
handleRedirection();
}, [handleRedirection]);
if (isRedirecting || currentUser || !instance?.config)
return (
<div className="grid h-screen place-items-center">
<Spinner />
</div>
);
return ( return (
<div className="relative"> <div className="relative">