Skip to content

Commit cc386c1

Browse files
authored
Merge pull request #217 from mparsakia/master
pr request for useSendPasswordResetEmail hook + docs
2 parents 33738ae + 4a72705 commit cc386c1

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

auth/README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ The `useSendPasswordResetEmail` hook takes the following parameters:
646646

647647
Returns:
648648

649-
- `sendPasswordResetEmail(email: string)`: a function you can call to send a password reset emaail
649+
- `sendPasswordResetEmail(email: string, actionCodeSettings?:ActionCodeSettings)`: a function you can call to send a password reset email. Optionally accepts an [actionCodeSettings](https://firebase.google.com/docs/reference/js/auth.actioncodesettings.md#actioncodesettings_interface) object as well.
650650
- `sending`: A `boolean` to indicate whether the email is being sent
651651
- `error`: Any `Error` returned by Firebase when trying to send the email, or `undefined` if there is no error
652652

@@ -660,6 +660,10 @@ const SendPasswordReset = () => {
660660
const [sendPasswordResetEmail, sending, error] = useSendPasswordResetEmail(
661661
auth
662662
);
663+
664+
const actionCodeSettings = {
665+
url: 'https://www.example.com/login'
666+
}
663667

664668
if (error) {
665669
return (
@@ -680,7 +684,7 @@ const SendPasswordReset = () => {
680684
/>
681685
<button
682686
onClick={async () => {
683-
await sendPasswordResetEmail(email);
687+
await sendPasswordResetEmail(email, actionCodeSettings);
684688
alert('Sent email');
685689
}}
686690
>
@@ -743,4 +747,4 @@ const SendEmailVerification = () => {
743747
</div>
744748
);
745749
};
746-
```
750+
```

auth/useSendPasswordResetEmail.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import {
22
Auth,
33
AuthError,
4+
ActionCodeSettings,
45
sendPasswordResetEmail as fbSendPasswordResetEmail,
56
} from 'firebase/auth';
67
import { useMemo, useState } from 'react';
78

89
export type SendPasswordResetEmailHook = [
9-
(email: string) => Promise<void>,
10+
(email: string, actionCodeSettings?: ActionCodeSettings) => Promise<void>,
1011
boolean,
1112
AuthError | Error | undefined
1213
];
@@ -15,11 +16,14 @@ export default (auth: Auth): SendPasswordResetEmailHook => {
1516
const [error, setError] = useState<AuthError>();
1617
const [loading, setLoading] = useState<boolean>(false);
1718

18-
const sendPasswordResetEmail = async (email: string) => {
19+
const sendPasswordResetEmail = async (
20+
email: string,
21+
actionCodeSettings?: ActionCodeSettings
22+
) => {
1923
setLoading(true);
2024
setError(undefined);
2125
try {
22-
await fbSendPasswordResetEmail(auth, email);
26+
await fbSendPasswordResetEmail(auth, email, actionCodeSettings);
2327
} catch (err) {
2428
setError(err as AuthError);
2529
} finally {

0 commit comments

Comments
 (0)