From 680ab9ea30d415b64b454f78f5d765965e2897ac Mon Sep 17 00:00:00 2001 From: pablodanswer Date: Thu, 19 Dec 2024 20:09:14 -0800 Subject: [PATCH] updated logic --- web/src/app/auth/forgot-password/page.tsx | 126 +++++++------- web/src/app/auth/login/EmailPasswordForm.tsx | 25 ++- web/src/app/auth/login/page.tsx | 146 ++++++++-------- web/src/app/auth/reset-password/page.tsx | 157 +++++++++--------- web/src/app/auth/signup/page.tsx | 17 +- web/src/components/admin/connectors/Field.tsx | 13 +- web/src/components/auth/AuthFlowContainer.tsx | 29 +++- 7 files changed, 259 insertions(+), 254 deletions(-) diff --git a/web/src/app/auth/forgot-password/page.tsx b/web/src/app/auth/forgot-password/page.tsx index aac32e29a..c97e1db3e 100644 --- a/web/src/app/auth/forgot-password/page.tsx +++ b/web/src/app/auth/forgot-password/page.tsx @@ -26,72 +26,68 @@ const ForgotPasswordPage: React.FC = () => { return (
- - {" "} -
- Forgot Password -
- {isWorking && } - {popup} - { - setIsWorking(true); - try { - await forgotPassword(values.email); - setPopup({ - type: "success", - message: - "Password reset email sent. Please check your inbox.", - }); - } catch (error) { - const errorMessage = - error instanceof Error - ? error.message - : "An error occurred. Please try again."; - setPopup({ - type: "error", - message: errorMessage, - }); - } finally { - setIsWorking(false); - } - }} - > - {({ isSubmitting }) => ( -
- +
+ Forgot Password +
+ {isWorking && } + {popup} + { + setIsWorking(true); + try { + await forgotPassword(values.email); + setPopup({ + type: "success", + message: "Password reset email sent. Please check your inbox.", + }); + } catch (error) { + const errorMessage = + error instanceof Error + ? error.message + : "An error occurred. Please try again."; + setPopup({ + type: "error", + message: errorMessage, + }); + } finally { + setIsWorking(false); + } + }} + > + {({ isSubmitting }) => ( + + -
- -
- - )} -
-
- - - Back to Login - - -
-
+
+ +
+ + )} + +
+ + + Back to Login + + +
); diff --git a/web/src/app/auth/login/EmailPasswordForm.tsx b/web/src/app/auth/login/EmailPasswordForm.tsx index aa79a32f9..97b494dc2 100644 --- a/web/src/app/auth/login/EmailPasswordForm.tsx +++ b/web/src/app/auth/login/EmailPasswordForm.tsx @@ -12,6 +12,7 @@ import { Spinner } from "@/components/Spinner"; import { set } from "lodash"; import { NEXT_PUBLIC_FORGOT_PASSWORD_ENABLED } from "@/lib/constants"; import Link from "next/link"; +import { useUser } from "@/components/user/UserProvider"; export function EmailPasswordForm({ isSignup = false, @@ -24,6 +25,7 @@ export function EmailPasswordForm({ referralSource?: string; nextUrl?: string | null; }) { + const { user } = useUser(); const { popup, setPopup } = usePopup(); const [isWorking, setIsWorking] = useState(false); return ( @@ -116,24 +118,29 @@ export function EmailPasswordForm({ name="password" label="Password" type="password" + includeForgotPassword={ + NEXT_PUBLIC_FORGOT_PASSWORD_ENABLED && !isSignup + } placeholder="**************" /> - {NEXT_PUBLIC_FORGOT_PASSWORD_ENABLED && !isSignup && ( - - Forgot Password? - - )} + {user?.is_anonymous_user && ( + + + or continue as guest + + + )} )} diff --git a/web/src/app/auth/login/page.tsx b/web/src/app/auth/login/page.tsx index 5b1c4e80b..405e99daf 100644 --- a/web/src/app/auth/login/page.tsx +++ b/web/src/app/auth/login/page.tsx @@ -77,67 +77,36 @@ const Page = async (props: { } return ( - -
- -
+
+ +
+ +
-
- {authUrl && authTypeMetadata && ( - <> -

- -

- - - - )} - - {authTypeMetadata?.authType === "cloud" && ( -
-
-
- or -
-
- - -
- - Create an account - - - {NEXT_PUBLIC_FORGOT_PASSWORD_ENABLED && ( - - Reset Password - - )} -
-
- )} - - {authTypeMetadata?.authType === "basic" && ( - -
- + <div className="flex flex-col w-full justify-center"> + {authUrl && authTypeMetadata && ( + <> + <h2 className="text-center text-xl text-strong font-bold"> <LoginText /> - -
- -
- - Don't have an account?{" "} + + + + + )} + + {authTypeMetadata?.authType === "cloud" && ( +
+
+
+ or +
+
+ + +
Create an account - + + {NEXT_PUBLIC_FORGOT_PASSWORD_ENABLED && ( + + Reset Password + + )} +
- - )} - {currentUser?.is_anonymous_user && ( -
- - You are currently logged in as an anonymous user. You can access - the chat experience{" "} - - here - - . - -
- )} -
- + )} + + {authTypeMetadata?.authType === "basic" && ( + <> +
+ + <LoginText /> + +
+ +
+ + )} +
+
+ + Don't have an account?{" "} + + Create an account + + +
); }; diff --git a/web/src/app/auth/reset-password/page.tsx b/web/src/app/auth/reset-password/page.tsx index a18cc92f5..e96d3051d 100644 --- a/web/src/app/auth/reset-password/page.tsx +++ b/web/src/app/auth/reset-password/page.tsx @@ -28,87 +28,84 @@ const ResetPasswordPage: React.FC = () => { return (
- -
- Reset Password -
- {isWorking && } - {popup} - { - if (!token) { - setPopup({ - type: "error", - message: "Invalid or missing reset token.", - }); - return; - } - setIsWorking(true); - try { - await resetPassword(token, values.password); - setPopup({ - type: "success", - message: - "Password reset successfully. Redirecting to login...", - }); - setTimeout(() => { - redirect("/auth/login"); - }, 1000); - } catch (error) { - setPopup({ - type: "error", - message: "An error occurred. Please try again.", - }); - } finally { - setIsWorking(false); - } - }} - > - {({ isSubmitting }) => ( -
- - +
+ Reset Password +
+ {isWorking && } + {popup} + { + if (!token) { + setPopup({ + type: "error", + message: "Invalid or missing reset token.", + }); + return; + } + setIsWorking(true); + try { + await resetPassword(token, values.password); + setPopup({ + type: "success", + message: "Password reset successfully. Redirecting to login...", + }); + setTimeout(() => { + redirect("/auth/login"); + }, 1000); + } catch (error) { + setPopup({ + type: "error", + message: "An error occurred. Please try again.", + }); + } finally { + setIsWorking(false); + } + }} + > + {({ isSubmitting }) => ( + + + -
- -
- - )} -
-
- - - Back to Login - - -
-
+
+ +
+ + )} + +
+ + + Back to Login + + +
); diff --git a/web/src/app/auth/signup/page.tsx b/web/src/app/auth/signup/page.tsx index cf27564fe..9c339c554 100644 --- a/web/src/app/auth/signup/page.tsx +++ b/web/src/app/auth/signup/page.tsx @@ -61,7 +61,7 @@ const Page = async (props: { } return ( - + <> @@ -94,21 +94,6 @@ const Page = async (props: { shouldVerify={authTypeMetadata?.requiresVerification} nextUrl={nextUrl} /> - -
- - Already have an account?{" "} - - Log In - - -
diff --git a/web/src/components/admin/connectors/Field.tsx b/web/src/components/admin/connectors/Field.tsx index c7032fdd3..e91a4a608 100644 --- a/web/src/components/admin/connectors/Field.tsx +++ b/web/src/components/admin/connectors/Field.tsx @@ -29,6 +29,7 @@ import { useRef, useState } from "react"; import remarkGfm from "remark-gfm"; import { EditIcon } from "@/components/icons/icons"; import { Button } from "@/components/ui/button"; +import Link from "next/link"; export function SectionHeader({ children, @@ -143,6 +144,7 @@ export function TextFormField({ small, removeLabel, min, + includeForgotPassword, onChange, width, vertical, @@ -169,6 +171,7 @@ export function TextFormField({ explanationLink?: string; small?: boolean; min?: number; + includeForgotPassword?: boolean; onChange?: (e: React.ChangeEvent) => void; width?: string; vertical?: boolean; @@ -238,7 +241,7 @@ export function TextFormField({ )} {subtext && {subtext}} -
+
+ {includeForgotPassword && ( + + Forgot password? + + )}
{explanationText && ( diff --git a/web/src/components/auth/AuthFlowContainer.tsx b/web/src/components/auth/AuthFlowContainer.tsx index 248320607..f9fb38eec 100644 --- a/web/src/components/auth/AuthFlowContainer.tsx +++ b/web/src/components/auth/AuthFlowContainer.tsx @@ -1,16 +1,41 @@ +import Link from "next/link"; import { Logo } from "../logo/Logo"; export default function AuthFlowContainer({ children, + authState, }: { children: React.ReactNode; + authState?: "signup" | "login"; }) { return ( -
-
+
+
{children}
+ {authState === "login" && ( +
+ Don't have an account?{" "} + + Create one + +
+ )} + {authState === "signup" && ( +
+ Already have an account?{" "} + + Log In + +
+ )}
); }