mirror of
https://github.com/chinchang/web-maker.git
synced 2025-07-14 02:26:20 +02:00
Firebase is here people!
This commit is contained in:
43
webmaker/src/auth.js
Normal file
43
webmaker/src/auth.js
Normal file
@ -0,0 +1,43 @@
|
||||
import {
|
||||
trackEvent
|
||||
} from './analytics';
|
||||
|
||||
import firebase from 'firebase/app'
|
||||
|
||||
export const auth = {
|
||||
logout() {
|
||||
firebase.auth().signOut();
|
||||
},
|
||||
login(providerName) {
|
||||
var provider;
|
||||
if (providerName === 'facebook') {
|
||||
provider = new firebase.auth.FacebookAuthProvider();
|
||||
} else if (providerName === 'twitter') {
|
||||
provider = new firebase.auth.TwitterAuthProvider();
|
||||
} else if (providerName === 'google') {
|
||||
provider = new firebase.auth.GoogleAuthProvider();
|
||||
provider.addScope('https://www.googleapis.com/auth/userinfo.profile');
|
||||
} else {
|
||||
provider = new firebase.auth.GithubAuthProvider();
|
||||
}
|
||||
|
||||
return firebase
|
||||
.auth()
|
||||
.signInWithPopup(provider)
|
||||
.then(function () {
|
||||
trackEvent('fn', 'loggedIn', providerName);
|
||||
// Save to recommend next time
|
||||
window.db.local.set({
|
||||
lastAuthProvider: providerName
|
||||
});
|
||||
})
|
||||
.catch(function (error) {
|
||||
utils.log(error);
|
||||
if (error.code === 'auth/account-exists-with-different-credential') {
|
||||
alert(
|
||||
'You have already signed up with the same email using different social login'
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user