From 584c0fc0fd4e37232eaa0f87765044ff24295a1d Mon Sep 17 00:00:00 2001 From: enamarat <35889708+enamarat@users.noreply.github.com> Date: Mon, 24 Jan 2022 11:57:40 +0300 Subject: [PATCH 1/2] 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. --- .../auth-next/manage/auth_reauth_with_credential.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/snippets/auth-next/manage/auth_reauth_with_credential.js b/snippets/auth-next/manage/auth_reauth_with_credential.js index 74e84732..27d66eaf 100644 --- a/snippets/auth-next/manage/auth_reauth_with_credential.js +++ b/snippets/auth-next/manage/auth_reauth_with_credential.js @@ -5,12 +5,16 @@ // 'npm run snippets'. // [START auth_reauth_with_credential_modular] -import { getAuth, reauthenticateWithCredential } from "firebase/auth"; +import { getAuth, reauthenticateWithCredential, EmailAuthProvider} from "firebase/auth"; const auth = getAuth(); const user = auth.currentUser; -// TODO(you): prompt the user to re-provide their sign-in credentials +// prompt the user to re-provide their sign-in credentials +const promptForCredentials = (userProvidedPassword) => { + return EmailAuthProvider.credential(user.email, userProvidedPassword); +} + const credential = promptForCredentials(); reauthenticateWithCredential(user, credential).then(() => { @@ -19,4 +23,4 @@ reauthenticateWithCredential(user, credential).then(() => { // An error ocurred // ... }); -// [END auth_reauth_with_credential_modular] \ No newline at end of file +// [END auth_reauth_with_credential_modular] From 9ae4a8e99033fa4970b84397bd6b9723e2472981 Mon Sep 17 00:00:00 2001 From: enamarat <35889708+enamarat@users.noreply.github.com> Date: Mon, 24 Jan 2022 12:35:44 +0300 Subject: [PATCH 2/2] Update auth_reauth_with_credential.js --- snippets/auth-next/manage/auth_reauth_with_credential.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snippets/auth-next/manage/auth_reauth_with_credential.js b/snippets/auth-next/manage/auth_reauth_with_credential.js index 27d66eaf..37b02fd1 100644 --- a/snippets/auth-next/manage/auth_reauth_with_credential.js +++ b/snippets/auth-next/manage/auth_reauth_with_credential.js @@ -15,7 +15,7 @@ const promptForCredentials = (userProvidedPassword) => { return EmailAuthProvider.credential(user.email, userProvidedPassword); } -const credential = promptForCredentials(); +const credential = promptForCredentials(userProvidedPassword); reauthenticateWithCredential(user, credential).then(() => { // User re-authenticated.