Skip to content

Instantly share code, notes, and snippets.

@zenorocha
Last active March 26, 2023 09:00
Show Gist options
  • Save zenorocha/9282426622fc8f46a6caeff40008de75 to your computer and use it in GitHub Desktop.
Save zenorocha/9282426622fc8f46a6caeff40008de75 to your computer and use it in GitHub Desktop.
New Firebase Auth vs Old Firebase Auth

Basic Auth

Create account

New API

firebase.auth().createUserWithEmailAndPassword(email, password).catch(function(error) {
	console.log(error);
});

Old API

firebase.createUser({
  email    : "bobtony@firebase.com",
  password : "correcthorsebatterystaple"
}, function(error, userData) {
  if (error) {
    console.log("Error creating user:", error);
  } else {
    console.log("Successfully created user account with uid:", userData.uid);
  }
});

Sign in

New API

firebase.auth().signInWithEmailAndPassword(email, password).catch(function(error) {
	console.log(error);
});

Old API

firebase.authWithPassword({
  email    : "bobtony@firebase.com",
  password : "correcthorsebatterystaple"
}, function(error, authData) {
  if (error) {
    console.log("Login Failed!", error);
  } else {
    console.log("Authenticated successfully with payload:", authData);
  }
});

Sign out

New API

firebase.auth().signOut().then(function() {
  // Sign-out successful.
}, function(error) {
	console.log(error);
});

Old API

firebase.unauth();

Delete user

New API

?

Old API

firebase.removeUser({
  email    : "bobtony@firebase.com",
  password : "correcthorsebatterystaple"
}, function(error) {
  if (error === null) {
    console.log("User removed successfully");
  } else {
    console.log("Error removing user:", error);
  }
});

Facebook OAuth

Sign In with Popup

New API

var provider = new firebase.auth.FacebookAuthProvider();

provider.addScope('user_birthday');

firebase.auth().signInWithPopup(provider).then(function(authData) {
	console.log(authData);
}).catch(function(error) {
	console.log(error);
});

Old API

firebase.authWithOAuthPopup("facebook", function(error, authData) {
  if (error) {
    console.log(error);
  } else {
    console.log(authData);
  }
}, {
  scope: 'user_birthday'
});

Sign In with Redirect

New API

var provider = new firebase.auth.FacebookAuthProvider();

provider.addScope('user_birthday');

firebase.auth().signInWithRedirect(provider);

firebase.auth().getRedirectResult().then(function(authData) {
	console.log(authData);
}).catch(function(error) {
	console.log(error);
});

Old API

firebase.authWithOAuthRedirect("facebook", function(error) {
  if (error) {
    console.log(error);
  } else {
    // We'll never get here, as the page will redirect on success.
  }
}, {
  scope: 'user_birthday'
});

Sign Out

New API

firebase.auth().signOut().then(function() {
  // Sign-out successful.
}, function(error) {
  console.log(error);
});

Github OAuth

Sign In with Popup

New API

var provider = new firebase.auth.GithubAuthProvider();

provider.addScope('repo');

firebase.auth().signInWithPopup(provider).then(function(result) {
	console.log(result);
}).catch(function(error) {
	console.log(error);
});

Sign In with Redirect

New API

var provider = new firebase.auth.GithubAuthProvider();

provider.addScope('repo');

firebase.auth().signInWithRedirect(provider);

firebase.auth().getRedirectResult().then(function(authData) {
	console.log(authData);
}).catch(function(error) {
	console.log(error);
});

Sign Out

New API

firebase.auth().signOut().then(function() {
  // Sign-out successful.
}, function(error) {
  console.log(error);
});

Google OAuth

Sign In with Popup

New API

var provider = new firebase.auth.GoogleAuthProvider();

provider.addScope('https://www.googleapis.com/auth/plus.login');

firebase.auth().signInWithPopup(provider).then(function(authData) {
	console.log(authData);
}).catch(function(error) {
	console.log(error);
});

Sign In with Redirect

New API

var provider = new firebase.auth.GoogleAuthProvider();

provider.addScope('https://www.googleapis.com/auth/plus.login');

firebase.auth().signInWithRedirect(provider);

firebase.auth().getRedirectResult().then(function(authData) {
	console.log(authData);
}).catch(function(error) {
	console.log(error);
});

Sign Out

New API

firebase.auth().signOut().then(function() {
  // Sign-out successful.
}, function(error) {
  console.log(error);
});

Twitter OAuth

Sign In with Popup

New API

var provider = new firebase.auth.TwitterAuthProvider();

firebase.auth().signInWithPopup(provider).then(function(authData) {
	console.log(authData);
}).catch(function(error) {
	console.log(error);
});

Sign In with Redirect

New API

var provider = new firebase.auth.TwitterAuthProvider();

firebase.auth().signInWithRedirect(provider);

firebase.auth().getRedirectResult().then(function(authData) {
	console.log(authData);
}).catch(function(error) {
	console.log(error);
});

Sign Out

New API

firebase.auth().signOut().then(function() {
  // Sign-out successful.
}, function(error) {
  console.log(error);
});
@franva
Copy link

franva commented Aug 7, 2017

This is really helpful~! Thank you!

@tgdev
Copy link

tgdev commented Sep 24, 2017

This is great. Thanks!

@haeke
Copy link

haeke commented Dec 4, 2017

Extremely helpful, thank you very much.

@gleidiin
Copy link

gleidiin commented Apr 4, 2018

You saved my day thx <3

@imran-ib
Copy link

imran-ib commented Oct 29, 2018

Thank You. Very helpful indeed

@maysam
Copy link

maysam commented Jul 22, 2019

how do we call firebase.createUser with google signup?

@ferhatkorkmaz11
Copy link

Is there any version of this for firestore as well? The original documentation does not work for me.

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