Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show how to create a credential #266

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions snippets/auth-next/manage/auth_reauth_with_credential.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,22 @@
// '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
const credential = promptForCredentials();
// prompt the user to re-provide their sign-in credentials
const promptForCredentials = (userProvidedPassword) => {
return EmailAuthProvider.credential(user.email, userProvidedPassword);
}

const credential = promptForCredentials(userProvidedPassword);

reauthenticateWithCredential(user, credential).then(() => {
// User re-authenticated.
}).catch((error) => {
// An error ocurred
// ...
});
// [END auth_reauth_with_credential_modular]
// [END auth_reauth_with_credential_modular]