Fix scoping and toast notifications for auth/settings page
This commit is contained in:
@@ -50,31 +50,37 @@ export default {
|
||||
fb,
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
showLoginSuccess() {
|
||||
this.$toast.info(this.$t("login_success"), {
|
||||
icon: "vpn_key",
|
||||
})
|
||||
},
|
||||
signInWithGoogle() {
|
||||
const provider = new firebase.auth.GoogleAuthProvider()
|
||||
const self = this
|
||||
firebase
|
||||
.auth()
|
||||
.signInWithPopup(provider)
|
||||
.then(({ additionalUserInfo }) => {
|
||||
if (additionalUserInfo.isNewUser) {
|
||||
this.$toast.info(`${this.$t("turn_on")} ${this.$t("sync")}`, {
|
||||
self.$toast.info(`${self.$t("turn_on")} ${self.$t("sync")}`, {
|
||||
icon: "sync",
|
||||
duration: null,
|
||||
closeOnSwipe: false,
|
||||
action: {
|
||||
text: this.$t("yes"),
|
||||
text: self.$t("yes"),
|
||||
onClick: (e, toastObject) => {
|
||||
fb.writeSettings("syncHistory", true)
|
||||
fb.writeSettings("syncCollections", true)
|
||||
fb.writeSettings("syncEnvironments", true)
|
||||
this.$router.push({ path: "/settings" })
|
||||
self.$router.push({ path: "/settings" })
|
||||
toastObject.remove()
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
self.showLoginSuccess()
|
||||
})
|
||||
.catch(err => {
|
||||
// An error happened.
|
||||
@@ -86,7 +92,10 @@ export default {
|
||||
// The provider account's email address.
|
||||
var email = err.email
|
||||
// Get sign-in methods for this email.
|
||||
auth.fetchSignInMethodsForEmail(email).then(function(methods) {
|
||||
firebase
|
||||
.auth()
|
||||
.fetchSignInMethodsForEmail(email)
|
||||
.then(function(methods) {
|
||||
// Step 3.
|
||||
// If the user has several sign-in methods,
|
||||
// the first method in the list will be the "recommended" method to use.
|
||||
@@ -102,17 +111,17 @@ export default {
|
||||
})
|
||||
.then(function() {
|
||||
// Google account successfully linked to the existing Firebase user.
|
||||
goToApp()
|
||||
self.showLoginSuccess()
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
this.$toast.info(`${this.$t("login_with")}`, {
|
||||
self.$toast.info(`${self.$t("login_with")}`, {
|
||||
icon: "vpn_key",
|
||||
duration: null,
|
||||
closeOnSwipe: false,
|
||||
action: {
|
||||
text: this.$t("yes"),
|
||||
text: self.$t("yes"),
|
||||
onClick: (e, toastObject) => {
|
||||
// All the other cases are external providers.
|
||||
// Construct provider object for that provider.
|
||||
@@ -124,7 +133,10 @@ export default {
|
||||
// Sign in to provider. Note: browsers usually block popup triggered asynchronously,
|
||||
// so in real scenario you should ask the user to click on a "continue" button
|
||||
// that will trigger the signInWithPopup.
|
||||
auth.signInWithPopup(provider).then(function(result) {
|
||||
firebase
|
||||
.auth()
|
||||
.signInWithPopup(provider)
|
||||
.then(function(result) {
|
||||
// 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.
|
||||
@@ -135,7 +147,7 @@ export default {
|
||||
.linkAndRetrieveDataWithCredential(pendingCred)
|
||||
.then(function(usercred) {
|
||||
// Google account successfully linked to the existing Firebase user.
|
||||
goToApp()
|
||||
self.showLoginSuccess()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -149,27 +161,29 @@ export default {
|
||||
},
|
||||
signInWithGithub() {
|
||||
const provider = new firebase.auth.GithubAuthProvider()
|
||||
const self = this
|
||||
firebase
|
||||
.auth()
|
||||
.signInWithPopup(provider)
|
||||
.then(({ additionalUserInfo }) => {
|
||||
if (additionalUserInfo.isNewUser) {
|
||||
this.$toast.info(`${this.$t("turn_on")} ${this.$t("sync")}`, {
|
||||
self.$toast.info(`${self.$t("turn_on")} ${self.$t("sync")}`, {
|
||||
icon: "sync",
|
||||
duration: null,
|
||||
closeOnSwipe: false,
|
||||
action: {
|
||||
text: this.$t("yes"),
|
||||
text: self.$t("yes"),
|
||||
onClick: (e, toastObject) => {
|
||||
fb.writeSettings("syncHistory", true)
|
||||
fb.writeSettings("syncCollections", true)
|
||||
fb.writeSettings("syncEnvironments", true)
|
||||
this.$router.push({ path: "/settings" })
|
||||
self.$router.push({ path: "/settings" })
|
||||
toastObject.remove()
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
self.showLoginSuccess()
|
||||
})
|
||||
.catch(err => {
|
||||
// An error happened.
|
||||
@@ -181,7 +195,10 @@ export default {
|
||||
// The provider account's email address.
|
||||
var email = err.email
|
||||
// Get sign-in methods for this email.
|
||||
auth.fetchSignInMethodsForEmail(email).then(function(methods) {
|
||||
firebase
|
||||
.auth()
|
||||
.fetchSignInMethodsForEmail(email)
|
||||
.then(function(methods) {
|
||||
// Step 3.
|
||||
// If the user has several sign-in methods,
|
||||
// the first method in the list will be the "recommended" method to use.
|
||||
@@ -189,7 +206,8 @@ export default {
|
||||
// Asks the user their password.
|
||||
// In real scenario, you should handle this asynchronously.
|
||||
var password = promptUserForPassword() // TODO: implement promptUserForPassword.
|
||||
auth
|
||||
firebase
|
||||
.auth()
|
||||
.signInWithEmailAndPassword(email, password)
|
||||
.then(function(user) {
|
||||
// Step 4a.
|
||||
@@ -197,17 +215,17 @@ export default {
|
||||
})
|
||||
.then(function() {
|
||||
// Google account successfully linked to the existing Firebase user.
|
||||
goToApp()
|
||||
self.showLoginSuccess()
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
this.$toast.info(`${this.$t("login_with")}`, {
|
||||
self.$toast.info(`${self.$t("login_with")}`, {
|
||||
icon: "vpn_key",
|
||||
duration: null,
|
||||
closeOnSwipe: false,
|
||||
action: {
|
||||
text: this.$t("yes"),
|
||||
text: self.$t("yes"),
|
||||
onClick: (e, toastObject) => {
|
||||
// All the other cases are external providers.
|
||||
// Construct provider object for that provider.
|
||||
@@ -219,7 +237,10 @@ export default {
|
||||
// Sign in to provider. Note: browsers usually block popup triggered asynchronously,
|
||||
// so in real scenario you should ask the user to click on a "continue" button
|
||||
// that will trigger the signInWithPopup.
|
||||
auth.signInWithPopup(provider).then(function(result) {
|
||||
firebase
|
||||
.auth()
|
||||
.signInWithPopup(provider)
|
||||
.then(function(result) {
|
||||
// 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.
|
||||
@@ -229,8 +250,7 @@ export default {
|
||||
result.user
|
||||
.linkAndRetrieveDataWithCredential(pendingCred)
|
||||
.then(function(usercred) {
|
||||
// Google account successfully linked to the existing Firebase user.
|
||||
goToApp()
|
||||
self.showLoginSuccess()
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -258,6 +258,7 @@ export default {
|
||||
installed: "Installed",
|
||||
login_with: "Login with",
|
||||
logged_out: "Logged out",
|
||||
login_success: "Successfully logged in",
|
||||
logout: "Logout",
|
||||
account: "Account",
|
||||
scrollInto_use_toggle: "Auto scroll",
|
||||
|
||||
@@ -382,6 +382,11 @@ export default {
|
||||
this.applySetting("THEME_COLOR", color.toUpperCase())
|
||||
this.applySetting("THEME_COLOR_VIBRANT", vibrant)
|
||||
},
|
||||
showLoginSuccess() {
|
||||
this.$toast.info(this.$t("login_success"), {
|
||||
icon: "vpn_key",
|
||||
})
|
||||
},
|
||||
getActiveColor() {
|
||||
// This strips extra spaces and # signs from the strings.
|
||||
const strip = str => str.replace(/#/g, "").replace(/ /g, "")
|
||||
@@ -395,12 +400,13 @@ export default {
|
||||
},
|
||||
signInWithGoogle() {
|
||||
const provider = new firebase.auth.GoogleAuthProvider()
|
||||
const self = this
|
||||
firebase
|
||||
.auth()
|
||||
.signInWithPopup(provider)
|
||||
.then(({ additionalUserInfo }) => {
|
||||
if (additionalUserInfo.isNewUser) {
|
||||
this.$toast.info(`${this.$t("turn_on")} ${this.$t("sync")}`, {
|
||||
self.$toast.info(`${this.$t("turn_on")} ${this.$t("sync")}`, {
|
||||
icon: "sync",
|
||||
duration: null,
|
||||
closeOnSwipe: false,
|
||||
@@ -416,6 +422,7 @@ export default {
|
||||
},
|
||||
})
|
||||
}
|
||||
self.showLoginSuccess()
|
||||
})
|
||||
.catch(err => {
|
||||
// An error happened.
|
||||
@@ -427,7 +434,10 @@ export default {
|
||||
// The provider account's email address.
|
||||
var email = err.email
|
||||
// Get sign-in methods for this email.
|
||||
auth.fetchSignInMethodsForEmail(email).then(function(methods) {
|
||||
firebase
|
||||
.auth()
|
||||
.fetchSignInMethodsForEmail(email)
|
||||
.then(function(methods) {
|
||||
// Step 3.
|
||||
// If the user has several sign-in methods,
|
||||
// the first method in the list will be the "recommended" method to use.
|
||||
@@ -435,7 +445,8 @@ export default {
|
||||
// Asks the user their password.
|
||||
// In real scenario, you should handle this asynchronously.
|
||||
var password = promptUserForPassword() // TODO: implement promptUserForPassword.
|
||||
auth
|
||||
firebase
|
||||
.auth()
|
||||
.signInWithEmailAndPassword(email, password)
|
||||
.then(function(user) {
|
||||
// Step 4a.
|
||||
@@ -443,17 +454,17 @@ export default {
|
||||
})
|
||||
.then(function() {
|
||||
// Google account successfully linked to the existing Firebase user.
|
||||
goToApp()
|
||||
self.showLoginSuccess()
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
this.$toast.info(`${this.$t("login_with")}`, {
|
||||
self.$toast.info(`${self.$t("login_with")}`, {
|
||||
icon: "vpn_key",
|
||||
duration: null,
|
||||
closeOnSwipe: false,
|
||||
action: {
|
||||
text: this.$t("yes"),
|
||||
text: self.$t("yes"),
|
||||
onClick: (e, toastObject) => {
|
||||
// All the other cases are external providers.
|
||||
// Construct provider object for that provider.
|
||||
@@ -465,7 +476,10 @@ export default {
|
||||
// Sign in to provider. Note: browsers usually block popup triggered asynchronously,
|
||||
// so in real scenario you should ask the user to click on a "continue" button
|
||||
// that will trigger the signInWithPopup.
|
||||
auth.signInWithPopup(provider).then(function(result) {
|
||||
firebase
|
||||
.auth()
|
||||
.signInWithPopup(provider)
|
||||
.then(function(result) {
|
||||
// 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.
|
||||
@@ -476,7 +490,9 @@ export default {
|
||||
.linkAndRetrieveDataWithCredential(pendingCred)
|
||||
.then(function(usercred) {
|
||||
// Google account successfully linked to the existing Firebase user.
|
||||
goToApp()
|
||||
self.$toast.info(self.$t("login_success"), {
|
||||
icon: "vpn_key",
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -490,27 +506,31 @@ export default {
|
||||
},
|
||||
signInWithGithub() {
|
||||
const provider = new firebase.auth.GithubAuthProvider()
|
||||
const self = this
|
||||
firebase
|
||||
.auth()
|
||||
.signInWithPopup(provider)
|
||||
.then(({ additionalUserInfo }) => {
|
||||
if (additionalUserInfo.isNewUser) {
|
||||
this.$toast.info(`${this.$t("turn_on")} ${this.$t("sync")}`, {
|
||||
self.$toast.info(`${self.$t("turn_on")} ${self.$t("sync")}`, {
|
||||
icon: "sync",
|
||||
duration: null,
|
||||
closeOnSwipe: false,
|
||||
action: {
|
||||
text: this.$t("yes"),
|
||||
text: self.$t("yes"),
|
||||
onClick: (e, toastObject) => {
|
||||
fb.writeSettings("syncHistory", true)
|
||||
fb.writeSettings("syncCollections", true)
|
||||
fb.writeSettings("syncEnvironments", true)
|
||||
this.$router.push({ path: "/settings" })
|
||||
self.$router.push({ path: "/settings" })
|
||||
toastObject.remove()
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
self.$toast.info(self.$t("login_success"), {
|
||||
icon: "vpn_key",
|
||||
})
|
||||
})
|
||||
.catch(err => {
|
||||
// An error happened.
|
||||
@@ -522,7 +542,10 @@ export default {
|
||||
// The provider account's email address.
|
||||
var email = err.email
|
||||
// Get sign-in methods for this email.
|
||||
auth.fetchSignInMethodsForEmail(email).then(function(methods) {
|
||||
firebase
|
||||
.auth()
|
||||
.fetchSignInMethodsForEmail(email)
|
||||
.then(function(methods) {
|
||||
// Step 3.
|
||||
// If the user has several sign-in methods,
|
||||
// the first method in the list will be the "recommended" method to use.
|
||||
@@ -538,17 +561,19 @@ export default {
|
||||
})
|
||||
.then(function() {
|
||||
// Google account successfully linked to the existing Firebase user.
|
||||
goToApp()
|
||||
self.$toast.info(self.$t("login_success"), {
|
||||
icon: "vpn_key",
|
||||
})
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
this.$toast.info(`${this.$t("login_with")}`, {
|
||||
self.$toast.info(`${this.$t("login_with")}`, {
|
||||
icon: "vpn_key",
|
||||
duration: null,
|
||||
closeOnSwipe: false,
|
||||
action: {
|
||||
text: this.$t("yes"),
|
||||
text: self.$t("yes"),
|
||||
onClick: (e, toastObject) => {
|
||||
// All the other cases are external providers.
|
||||
// Construct provider object for that provider.
|
||||
@@ -560,7 +585,10 @@ export default {
|
||||
// Sign in to provider. Note: browsers usually block popup triggered asynchronously,
|
||||
// so in real scenario you should ask the user to click on a "continue" button
|
||||
// that will trigger the signInWithPopup.
|
||||
auth.signInWithPopup(provider).then(function(result) {
|
||||
firebase
|
||||
.auth()
|
||||
.signInWithPopup(provider)
|
||||
.then(function(result) {
|
||||
// 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.
|
||||
@@ -571,7 +599,7 @@ export default {
|
||||
.linkAndRetrieveDataWithCredential(pendingCred)
|
||||
.then(function(usercred) {
|
||||
// Google account successfully linked to the existing Firebase user.
|
||||
goToApp()
|
||||
self.showLoginSuccess()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -589,15 +617,16 @@ export default {
|
||||
},
|
||||
logout() {
|
||||
fb.currentUser = null
|
||||
const self = this
|
||||
firebase
|
||||
.auth()
|
||||
.signOut()
|
||||
.catch(err => {
|
||||
this.$toast.show(err.message || err, {
|
||||
self.$toast.show(err.message || err, {
|
||||
icon: "error",
|
||||
})
|
||||
})
|
||||
this.$toast.info(this.$t("logged_out"), {
|
||||
self.$toast.info(this.$t("logged_out"), {
|
||||
icon: "vpn_key",
|
||||
})
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user