mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
chore: removed old auth hook
This commit is contained in:
parent
57da79392a
commit
b87a43c8fe
@ -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 (
|
||||
<div className="grid h-screen place-items-center">
|
||||
<Spinner />
|
||||
</div>
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="relative">
|
||||
|
@ -34,10 +34,14 @@ export const AuthenticationWrapper: FC<TAuthenticationWrapper> = (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<TAuthenticationWrapper> = (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<TAuthenticationWrapper> = (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<TAuthenticationWrapper> = (props) => {
|
||||
}
|
||||
|
||||
if (pageType === EPageTypes.AUTHENTICATED) {
|
||||
if (currentUser) {
|
||||
if (currentUser?.id) {
|
||||
if (currentUserProfile?.is_onboarded) {
|
||||
return <>{children}</>;
|
||||
} else {
|
||||
|
@ -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 (
|
||||
<div className="grid h-screen place-items-center">
|
||||
<Spinner />
|
||||
</div>
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="relative">
|
||||
<PageHead title="Forgot Password" />
|
||||
|
@ -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 (
|
||||
<div className="grid h-screen place-items-center">
|
||||
<Spinner />
|
||||
</div>
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="relative">
|
||||
<PageHead title="Reset Password" />
|
||||
|
@ -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<string | undefined>(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 (
|
||||
<div className="grid h-screen place-items-center">
|
||||
<Spinner />
|
||||
</div>
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="relative">
|
||||
<PageHead title="Reset Password" />
|
||||
|
@ -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 (
|
||||
<div className="grid h-screen place-items-center">
|
||||
<Spinner />
|
||||
</div>
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="relative">
|
||||
|
Loading…
Reference in New Issue
Block a user