From f1452ba67e98100d5eaa53e6224447493b8d4839 Mon Sep 17 00:00:00 2001 From: Abubeker Yasin Date: Thu, 9 Jul 2026 09:38:34 +0300 Subject: [PATCH] feat: ( forget password ) add phone number --- .../backoffice/src/app/login/page.tsx | 38 +++++++++---------- .../backoffice/src/lib/api/auth.ts | 6 ++- .../portal/src/app/forgot-password/page.tsx | 22 +++++------ .../portal/src/lib/api/auth.ts | 6 ++- 4 files changed, 38 insertions(+), 34 deletions(-) diff --git a/apps/edr-passenger-web/backoffice/src/app/login/page.tsx b/apps/edr-passenger-web/backoffice/src/app/login/page.tsx index f104db3da..c0d84cae8 100644 --- a/apps/edr-passenger-web/backoffice/src/app/login/page.tsx +++ b/apps/edr-passenger-web/backoffice/src/app/login/page.tsx @@ -29,12 +29,12 @@ export default function LoginPage() { const [emailFocused, setEmailFocused] = useState(false); const [passwordFocused, setPasswordFocused] = useState(false); - const [view, setView] = useState<'login' | 'forgot'>('login'); - const [forgotEmail, setForgotEmail] = useState(''); - const [forgotLoading, setForgotLoading] = useState(false); - const [forgotError, setForgotError] = useState(''); - const [forgotSent, setForgotSent] = useState(false); - const [forgotFocused, setForgotFocused] = useState(false); + const [view, setView] = useState<'login' | 'forgot'>('login'); + const [forgotIdentifier, setForgotIdentifier] = useState(''); + const [forgotLoading, setForgotLoading] = useState(false); + const [forgotError, setForgotError] = useState(''); + const [forgotSent, setForgotSent] = useState(false); + const [forgotFocused, setForgotFocused] = useState(false); const router = useRouter(); const { login } = useAuthStore(); @@ -66,13 +66,13 @@ export default function LoginPage() { setForgotLoading(true); setForgotError(''); try { - await iamAuthApi.forgotPassword(forgotEmail); + await iamAuthApi.forgotPassword(forgotIdentifier.trim()); setForgotSent(true); } catch (err: any) { const msg = err.response?.data?.message || err.message || ''; setForgotError( msg === 'user_not_found' - ? 'No account found with that email address.' + ? 'No account found with that email or phone number.' : msg || 'Failed to send the reset link. Please try again.' ); } finally { @@ -209,7 +209,7 @@ export default function LoginPage() {
@@ -295,10 +295,10 @@ export default function LoginPage() { )}
- {/* Email field */} + {/* Email or phone field */}
{ setForgotEmail(e.target.value); setForgotError(''); }} + type="text" + value={forgotIdentifier} + onChange={(e) => { setForgotIdentifier(e.target.value); setForgotError(''); }} onFocus={() => setForgotFocused(true)} onBlur={() => setForgotFocused(false)} className="w-full px-4 py-3 rounded-xl bg-white dark:bg-gray-900 text-gray-900 dark:text-white placeholder:text-gray-400 dark:placeholder:text-gray-600 text-sm focus:outline-none" - placeholder="name@edr.com" + placeholder="name@edr.com or +251..." required - autoComplete="email" + autoComplete="username" />
@@ -322,9 +322,9 @@ export default function LoginPage() { {/* Submit */}
diff --git a/apps/edr-passenger-web/portal/src/lib/api/auth.ts b/apps/edr-passenger-web/portal/src/lib/api/auth.ts index 14e9a16a1..b37361238 100644 --- a/apps/edr-passenger-web/portal/src/lib/api/auth.ts +++ b/apps/edr-passenger-web/portal/src/lib/api/auth.ts @@ -8,8 +8,10 @@ const API_URL = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:4000'; // current password is wrong on change-password, and OTP failures must surface // as inline errors, not a logout. export const iamAuthApi = { - forgotPassword: (email: string) => - axios.post(`${API_URL}/v1/auth/forgot-password`, { email }), + // `identifier` can be an email address or a phone number — the IAM accepts + // either in the `email` field of the forgot-password body. + forgotPassword: (identifier: string) => + axios.post(`${API_URL}/v1/auth/forgot-password`, { email: identifier }), // Re-sends the registration verification code for a still-pending account. resendRegistrationCode: (data: { email: string; phoneNumber: string }) =>