Skip to content

Commit cb05679

Browse files
committed
sending forgot password link to email
1 parent 97d8d16 commit cb05679

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

server/api/controllers/UserController.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,11 @@ export class UserController {
9696
this.userService.deleteUser(user);
9797
return { error: null };
9898
}
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+
99106
}

server/services/UserService.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
sendEmailVerification,
77
signInWithCustomToken,
88
signInWithEmailAndPassword,
9+
sendPasswordResetEmail
910
} from 'firebase/auth';
1011
import { FirebaseAuthError } from 'firebase-admin/auth';
1112
import {
@@ -173,4 +174,16 @@ export class UserService {
173174
const userCredential = await signInWithCustomToken(auth, customToken);
174175
await sendEmailVerification(userCredential.user);
175176
}
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+
}
176189
}

0 commit comments

Comments
 (0)