Skip to content

Instantly share code, notes, and snippets.

@deltaepsilon
Last active October 13, 2020 18:08
Show Gist options
  • Select an option

  • Save deltaepsilon/00f9b1076689a2a5c27d4616a93495ee to your computer and use it in GitHub Desktop.

Select an option

Save deltaepsilon/00f9b1076689a2a5c27d4616a93495ee to your computer and use it in GitHub Desktop.
// Authenticate with the first user then save the currentUser to a local variable
var previousUser = firebase.auth().currentUser;
// Authenticate with a second method and get a credential
// This example shows an email/password credential, but you can get credentials from any auth provider
// Note that using an OAuth provider as your se
var credential = firebase.auth.EmailPasswordAuthProvider.credential(email, password);
previousUser.link(credential)
 .catch(function (error) {
  // Linking will often fail if the account has already been linked. Handle these cases manually.
 });
// OAuth providers authenticate in an asynchronous manner, so you’ll want to perform the link account link in the callback.
var previousUser = firebase.auth().currentUser;
firebase.auth().signInWithPopup(new firebase.auth.GoogleAuthProvider())
 .then(function (result) {
 return previousUser.link(result.credential);
 })
 .catch(function (err) {
  // Handle error
 });
@madhusudanbabar
Copy link
Copy Markdown

there is a period (.) missing on line no. 15
firebase.auth().signInWithPopup(new firebase.authGoogleAuthProvider())
firebase.auth().signInWithPopup(new firebase.auth.GoogleAuthProvider())

@deltaepsilon
Copy link
Copy Markdown
Author

Thanks for the heads up @madhusudanbabar!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment