diff --git a/backend/onyx/auth/users.py b/backend/onyx/auth/users.py index 47e3b2da6a9..1481e141a20 100644 --- a/backend/onyx/auth/users.py +++ b/backend/onyx/auth/users.py @@ -473,10 +473,12 @@ async def on_after_forgot_password( ) -> None: if not EMAIL_CONFIGURED: logger.error( - "User forgot their password but email is not configured.", - extra={"user_email": user.email}, + "Email is not configured. Please configure email in the admin panel" + ) + raise HTTPException( + status.HTTP_500_INTERNAL_SERVER_ERROR, + "Your admin has not enbaled this feature.", ) - return send_forgot_password_email(user.email, token) async def on_after_request_verify( diff --git a/backend/onyx/configs/app_configs.py b/backend/onyx/configs/app_configs.py index 0828cf3208d..628e5a3a06e 100644 --- a/backend/onyx/configs/app_configs.py +++ b/backend/onyx/configs/app_configs.py @@ -92,9 +92,7 @@ SMTP_PORT = int(os.environ.get("SMTP_PORT") or "587") SMTP_USER = os.environ.get("SMTP_USER", "your-email@gmail.com") SMTP_PASS = os.environ.get("SMTP_PASS", "your-gmail-password") -EMAIL_CONFIGURED = ( - SMTP_SERVER is not None and SMTP_USER is not None and SMTP_PASS is not None -) +EMAIL_CONFIGURED = bool(SMTP_SERVER) and bool(SMTP_USER) and bool(SMTP_PASS) EMAIL_FROM = os.environ.get("EMAIL_FROM") or SMTP_USER # If set, Onyx will listen to the `expires_at` returned by the identity diff --git a/web/src/app/auth/forgot-password/page.tsx b/web/src/app/auth/forgot-password/page.tsx index e2c3db1ede0..aac32e29acb 100644 --- a/web/src/app/auth/forgot-password/page.tsx +++ b/web/src/app/auth/forgot-password/page.tsx @@ -27,6 +27,7 @@ const ForgotPasswordPage: React.FC = () => {
+ {" "}
Forgot Password
@@ -49,9 +50,13 @@ const ForgotPasswordPage: React.FC = () => { "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: "An error occurred. Please try again.", + message: errorMessage, }); } finally { setIsWorking(false); diff --git a/web/src/app/auth/forgot-password/utils.ts b/web/src/app/auth/forgot-password/utils.ts index fd201e42dc4..fc5176633fc 100644 --- a/web/src/app/auth/forgot-password/utils.ts +++ b/web/src/app/auth/forgot-password/utils.ts @@ -8,7 +8,10 @@ export const forgotPassword = async (email: string): Promise => { }); if (!response.ok) { - throw new Error("Failed to send password reset email"); + const error = await response.json(); + const errorMessage = + error?.detail || "An error occurred during password reset."; + throw new Error(errorMessage); } }; diff --git a/web/src/app/auth/login/EmailPasswordForm.tsx b/web/src/app/auth/login/EmailPasswordForm.tsx index 61b8116db20..89829a20543 100644 --- a/web/src/app/auth/login/EmailPasswordForm.tsx +++ b/web/src/app/auth/login/EmailPasswordForm.tsx @@ -10,6 +10,8 @@ import { requestEmailVerification } from "../lib"; import { useState } from "react"; import { Spinner } from "@/components/Spinner"; import { set } from "lodash"; +import { NEXT_PUBLIC_FORGOT_PASSWORD_ENABLED } from "@/lib/constants"; +import Link from "next/link"; export function EmailPasswordForm({ isSignup = false, @@ -110,15 +112,21 @@ export function EmailPasswordForm({ placeholder="**************" /> -
- -
+ Forgot Password? + + )} + )} diff --git a/web/src/app/auth/login/page.tsx b/web/src/app/auth/login/page.tsx index 9ad5716fbd0..6722f85eb8f 100644 --- a/web/src/app/auth/login/page.tsx +++ b/web/src/app/auth/login/page.tsx @@ -132,7 +132,7 @@ const Page = async (props: {
-
+
Don't have an account?{" "} - {NEXT_PUBLIC_FORGOT_PASSWORD_ENABLED && ( - - Forgot password?{" "} - - Reset Password - - - )}
)} diff --git a/web/src/app/auth/reset-password/page.tsx b/web/src/app/auth/reset-password/page.tsx index 350c866a80a..a18cc92f5c4 100644 --- a/web/src/app/auth/reset-password/page.tsx +++ b/web/src/app/auth/reset-password/page.tsx @@ -59,8 +59,11 @@ const ResetPasswordPage: React.FC = () => { setPopup({ type: "success", message: - "Password reset successfully. You can now log in with your new password.", + "Password reset successfully. Redirecting to login...", }); + setTimeout(() => { + redirect("/auth/login"); + }, 1000); } catch (error) { setPopup({ type: "error",