Skip to content

Commit 584c0fc

Browse files
authored
Show how to create a credential
Getting a credential for reauthentication is a real head-scratcher since Firebase documentation does not clarify how to do it. Many people [complain about it:](https://stackoverflow.com/questions/37811684/how-to-create-credential-object-needed-by-firebase-web-user-reauthenticatewith) Read the comments. By adding just a few lines of code we can save many people a lot of trouble.
1 parent 509769a commit 584c0fc

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

snippets/auth-next/manage/auth_reauth_with_credential.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@
55
// 'npm run snippets'.
66

77
// [START auth_reauth_with_credential_modular]
8-
import { getAuth, reauthenticateWithCredential } from "firebase/auth";
8+
import { getAuth, reauthenticateWithCredential, EmailAuthProvider} from "firebase/auth";
99

1010
const auth = getAuth();
1111
const user = auth.currentUser;
1212

13-
// TODO(you): prompt the user to re-provide their sign-in credentials
13+
// prompt the user to re-provide their sign-in credentials
14+
const promptForCredentials = (userProvidedPassword) => {
15+
return EmailAuthProvider.credential(user.email, userProvidedPassword);
16+
}
17+
1418
const credential = promptForCredentials();
1519

1620
reauthenticateWithCredential(user, credential).then(() => {
@@ -19,4 +23,4 @@ reauthenticateWithCredential(user, credential).then(() => {
1923
// An error ocurred
2024
// ...
2125
});
22-
// [END auth_reauth_with_credential_modular]
26+
// [END auth_reauth_with_credential_modular]

0 commit comments

Comments
 (0)