From 0522e787cd957d808060c2580a4be0c5f8de7737 Mon Sep 17 00:00:00 2001 From: MartinBraquet Date: Fri, 31 Oct 2025 20:41:57 +0100 Subject: [PATCH] Add Forgot Password? --- web/lib/firebase/password.ts | 25 +++++++++++++++++++++++++ web/pages/settings.tsx | 24 +++--------------------- web/pages/signin.tsx | 24 +++++++++++++++++++++++- 3 files changed, 51 insertions(+), 22 deletions(-) create mode 100644 web/lib/firebase/password.ts diff --git a/web/lib/firebase/password.ts b/web/lib/firebase/password.ts new file mode 100644 index 00000000..f6778f5e --- /dev/null +++ b/web/lib/firebase/password.ts @@ -0,0 +1,25 @@ +import {sendPasswordResetEmail} from "firebase/auth"; +import toast from "react-hot-toast"; +import {auth} from "web/lib/firebase/users"; + +export const sendPasswordReset = async (email: string | undefined) => { + if (!email) { + toast.error('No email found on your account.') + return + } + toast.promise( + sendPasswordResetEmail(auth, email), + { + loading: 'Sending password reset email...', + success: 'Password reset email sent — check your inbox and spam.', + error: 'Failed to send password reset email.', + } + ) + .catch((e) => { + if (e.code === 'auth/user-not-found') { + toast.error('No account found with that email.') + return + } + console.log("Failed to send password reset email", e) + }) +} \ No newline at end of file diff --git a/web/pages/settings.tsx b/web/pages/settings.tsx index bd87757c..da928d3b 100644 --- a/web/pages/settings.tsx +++ b/web/pages/settings.tsx @@ -12,11 +12,12 @@ import {useRedirectIfSignedOut} from "web/hooks/use-redirect-if-signed-out"; import {deleteAccount} from "web/lib/util/delete"; import router from "next/router"; import {Button} from "web/components/buttons/button"; -import {getAuth, sendEmailVerification, sendPasswordResetEmail, updateEmail} from 'firebase/auth'; +import {sendEmailVerification, updateEmail} from 'firebase/auth'; import {auth} from "web/lib/firebase/users"; import {NotificationSettings} from "web/components/notifications"; import ThemeIcon from "web/components/theme-icon"; import {WithPrivateUser} from "web/components/user/with-user"; +import {sendPasswordReset} from "web/lib/firebase/password"; export default function NotificationsPage() { useRedirectIfSignedOut() @@ -74,25 +75,6 @@ const LoadedGeneralSettings = (props: { } } - const sendPasswordReset = async () => { - if (!privateUser?.email) { - toast.error('No email found on your account.') - return - } - const auth = getAuth() - toast.promise( - sendPasswordResetEmail(auth, privateUser.email), - { - loading: 'Sending password reset email...', - success: 'Password reset email sent — check your inbox and spam.', - error: 'Failed to send password reset email.', - } - ) - .catch(() => { - console.log("Failed to send password reset email") - }) - } - const changeUserEmail = async (newEmail: string) => { if (!user) return @@ -195,7 +177,7 @@ const LoadedGeneralSettings = (props: {
Password
+