File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -96,4 +96,11 @@ export class UserController {
96
96
this . userService . deleteUser ( user ) ;
97
97
return { error : null } ;
98
98
}
99
+
100
+ @Post ( '/forgot-password' )
101
+ async forgotPassword ( @Body ( ) body : { email : string } ) : Promise < { message : string } > {
102
+ await this . userService . sendPasswordResetEmail ( body . email ) ;
103
+ return { message : 'Password reset email sent successfully.' } ;
104
+ }
105
+
99
106
}
Original file line number Diff line number Diff line change 6
6
sendEmailVerification ,
7
7
signInWithCustomToken ,
8
8
signInWithEmailAndPassword ,
9
+ sendPasswordResetEmail
9
10
} from 'firebase/auth' ;
10
11
import { FirebaseAuthError } from 'firebase-admin/auth' ;
11
12
import {
@@ -173,4 +174,16 @@ export class UserService {
173
174
const userCredential = await signInWithCustomToken ( auth , customToken ) ;
174
175
await sendEmailVerification ( userCredential . user ) ;
175
176
}
177
+
178
+ public async sendPasswordResetEmail ( email : string ) : Promise < void > {
179
+ try {
180
+ const firebaseRecord = await adminAuth . getUserByEmail ( email ) ;
181
+ if ( ! firebaseRecord ) {
182
+ throw new NotFoundError ( 'No user found with the provided email address.' ) ;
183
+ }
184
+ await sendPasswordResetEmail ( auth , email ) ;
185
+ } catch ( error ) {
186
+ throw error ;
187
+ }
188
+ }
176
189
}
You can’t perform that action at this time.
0 commit comments