mirror of
https://github.com/chinchang/web-maker.git
synced 2025-07-13 10:06:23 +02:00
44 lines
1.1 KiB
JavaScript
44 lines
1.1 KiB
JavaScript
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'
|
|
);
|
|
}
|
|
});
|
|
}
|
|
}
|