Transpiled ES5 code to ES6/ES7
This commit is contained in:
@@ -77,34 +77,33 @@ export default {
|
||||
}
|
||||
self.showLoginSuccess()
|
||||
})
|
||||
.catch(err => {
|
||||
.catch((err) => {
|
||||
// An error happened.
|
||||
if (err.code === "auth/account-exists-with-different-credential") {
|
||||
// Step 2.
|
||||
// User's email already exists.
|
||||
// The pending Google credential.
|
||||
var pendingCred = err.credential
|
||||
const pendingCred = err.credential
|
||||
// The provider account's email address.
|
||||
var email = err.email
|
||||
const email = err.email
|
||||
// Get sign-in methods for this email.
|
||||
firebase
|
||||
.auth()
|
||||
.fetchSignInMethodsForEmail(email)
|
||||
.then(function(methods) {
|
||||
.then((methods) => {
|
||||
// Step 3.
|
||||
// If the user has several sign-in methods,
|
||||
// the first method in the list will be the "recommended" method to use.
|
||||
if (methods[0] === "password") {
|
||||
// Asks the user their password.
|
||||
// In real scenario, you should handle this asynchronously.
|
||||
var password = promptUserForPassword() // TODO: implement promptUserForPassword.
|
||||
const password = promptUserForPassword() // TODO: implement promptUserForPassword.
|
||||
auth
|
||||
.signInWithEmailAndPassword(email, password)
|
||||
.then(function(user) {
|
||||
// Step 4a.
|
||||
return user.linkWithCredential(pendingCred)
|
||||
})
|
||||
.then(function() {
|
||||
.then((
|
||||
user // Step 4a.
|
||||
) => user.linkWithCredential(pendingCred))
|
||||
.then(() => {
|
||||
// Google account successfully linked to the existing Firebase user.
|
||||
self.showLoginSuccess()
|
||||
})
|
||||
@@ -121,7 +120,7 @@ export default {
|
||||
// All the other cases are external providers.
|
||||
// Construct provider object for that provider.
|
||||
// TODO: implement getProviderForProviderId.
|
||||
var provider = new firebase.auth.GithubAuthProvider()
|
||||
const provider = new firebase.auth.GithubAuthProvider()
|
||||
// At this point, you should let the user know that they already has an account
|
||||
// but with a different provider, and let them validate the fact they want to
|
||||
// sign in with this provider.
|
||||
@@ -131,19 +130,17 @@ export default {
|
||||
firebase
|
||||
.auth()
|
||||
.signInWithPopup(provider)
|
||||
.then(function(result) {
|
||||
.then(({ user }) => {
|
||||
// Remember that the user may have signed in with an account that has a different email
|
||||
// address than the first one. This can happen as Firebase doesn't control the provider's
|
||||
// sign in flow and the user is free to login using whichever account they own.
|
||||
// Step 4b.
|
||||
// Link to Google credential.
|
||||
// As we have access to the pending credential, we can directly call the link method.
|
||||
result.user
|
||||
.linkAndRetrieveDataWithCredential(pendingCred)
|
||||
.then(function(usercred) {
|
||||
// Google account successfully linked to the existing Firebase user.
|
||||
self.showLoginSuccess()
|
||||
})
|
||||
user.linkAndRetrieveDataWithCredential(pendingCred).then((usercred) => {
|
||||
// Google account successfully linked to the existing Firebase user.
|
||||
self.showLoginSuccess()
|
||||
})
|
||||
})
|
||||
|
||||
toastObject.remove()
|
||||
@@ -180,35 +177,34 @@ export default {
|
||||
}
|
||||
self.showLoginSuccess()
|
||||
})
|
||||
.catch(err => {
|
||||
.catch((err) => {
|
||||
// An error happened.
|
||||
if (err.code === "auth/account-exists-with-different-credential") {
|
||||
// Step 2.
|
||||
// User's email already exists.
|
||||
// The pending Google credential.
|
||||
var pendingCred = err.credential
|
||||
const pendingCred = err.credential
|
||||
// The provider account's email address.
|
||||
var email = err.email
|
||||
const email = err.email
|
||||
// Get sign-in methods for this email.
|
||||
firebase
|
||||
.auth()
|
||||
.fetchSignInMethodsForEmail(email)
|
||||
.then(function(methods) {
|
||||
.then((methods) => {
|
||||
// Step 3.
|
||||
// If the user has several sign-in methods,
|
||||
// the first method in the list will be the "recommended" method to use.
|
||||
if (methods[0] === "password") {
|
||||
// Asks the user their password.
|
||||
// In real scenario, you should handle this asynchronously.
|
||||
var password = promptUserForPassword() // TODO: implement promptUserForPassword.
|
||||
const password = promptUserForPassword() // TODO: implement promptUserForPassword.
|
||||
firebase
|
||||
.auth()
|
||||
.signInWithEmailAndPassword(email, password)
|
||||
.then(function(user) {
|
||||
// Step 4a.
|
||||
return user.linkWithCredential(pendingCred)
|
||||
})
|
||||
.then(function() {
|
||||
.then((
|
||||
user // Step 4a.
|
||||
) => user.linkWithCredential(pendingCred))
|
||||
.then(() => {
|
||||
// Google account successfully linked to the existing Firebase user.
|
||||
self.showLoginSuccess()
|
||||
})
|
||||
@@ -225,7 +221,7 @@ export default {
|
||||
// All the other cases are external providers.
|
||||
// Construct provider object for that provider.
|
||||
// TODO: implement getProviderForProviderId.
|
||||
var provider = new firebase.auth.GoogleAuthProvider()
|
||||
const provider = new firebase.auth.GoogleAuthProvider()
|
||||
// At this point, you should let the user know that they already has an account
|
||||
// but with a different provider, and let them validate the fact they want to
|
||||
// sign in with this provider.
|
||||
@@ -235,18 +231,16 @@ export default {
|
||||
firebase
|
||||
.auth()
|
||||
.signInWithPopup(provider)
|
||||
.then(function(result) {
|
||||
.then(({ user }) => {
|
||||
// Remember that the user may have signed in with an account that has a different email
|
||||
// address than the first one. This can happen as Firebase doesn't control the provider's
|
||||
// sign in flow and the user is free to login using whichever account they own.
|
||||
// Step 4b.
|
||||
// Link to Google credential.
|
||||
// As we have access to the pending credential, we can directly call the link method.
|
||||
result.user
|
||||
.linkAndRetrieveDataWithCredential(pendingCred)
|
||||
.then(function(usercred) {
|
||||
self.showLoginSuccess()
|
||||
})
|
||||
user.linkAndRetrieveDataWithCredential(pendingCred).then((usercred) => {
|
||||
self.showLoginSuccess()
|
||||
})
|
||||
})
|
||||
|
||||
toastObject.remove()
|
||||
|
||||
Reference in New Issue
Block a user