Move setup stuff to separate functions
This commit is contained in:
parent
d43c16e654
commit
00d1f9b784
58
src/App.vue
58
src/App.vue
|
@ -46,49 +46,18 @@ export default {
|
||||||
Notification,
|
Notification,
|
||||||
},
|
},
|
||||||
beforeMount() {
|
beforeMount() {
|
||||||
// Check if the user is offline, show a message then
|
this.setupOnlineStatus()
|
||||||
this.$store.commit(ONLINE, navigator.onLine)
|
this.setupPasswortResetRedirect()
|
||||||
window.addEventListener('online', () => this.$store.commit(ONLINE, navigator.onLine))
|
this.setupEmailVerificationRedirect()
|
||||||
window.addEventListener('offline', () => this.$store.commit(ONLINE, navigator.onLine))
|
|
||||||
|
|
||||||
// Password reset
|
|
||||||
if (this.$route.query.userPasswordReset !== undefined) {
|
|
||||||
localStorage.removeItem('passwordResetToken') // Delete an eventually preexisting old token
|
|
||||||
localStorage.setItem('passwordResetToken', this.$route.query.userPasswordReset)
|
|
||||||
this.$router.push({name: 'user.password-reset.reset'})
|
|
||||||
}
|
|
||||||
// Email verification
|
|
||||||
if (this.$route.query.userEmailConfirm !== undefined) {
|
|
||||||
localStorage.removeItem('emailConfirmToken') // Delete an eventually preexisting old token
|
|
||||||
localStorage.setItem('emailConfirmToken', this.$route.query.userEmailConfirm)
|
|
||||||
this.$router.push({name: 'user.login'})
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
beforeCreate() {
|
beforeCreate() {
|
||||||
this.$store.dispatch('config/update')
|
this.$store.dispatch('config/update')
|
||||||
this.$store.dispatch('auth/checkAuth')
|
|
||||||
.then(() => {
|
|
||||||
// Check if the user is already logged in, if so, redirect them to the homepage
|
|
||||||
if (
|
|
||||||
!this.userAuthenticated &&
|
|
||||||
this.$route.name !== 'user.login' &&
|
|
||||||
this.$route.name !== 'user.password-reset.request' &&
|
|
||||||
this.$route.name !== 'user.password-reset.reset' &&
|
|
||||||
this.$route.name !== 'user.register' &&
|
|
||||||
this.$route.name !== 'link-share.auth'
|
|
||||||
) {
|
|
||||||
this.$router.push({name: 'user.login'})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
|
|
||||||
// Make sure to always load the home route when running with electron
|
// Make sure to always load the home route when running with electron
|
||||||
if (this.$route.fullPath.endsWith('frontend/index.html')) {
|
if (this.$route.fullPath.endsWith('frontend/index.html')) {
|
||||||
this.$router.push({name: 'home'})
|
this.$router.push({name: 'home'})
|
||||||
}
|
}
|
||||||
|
|
||||||
this.renewTokenOnFocus()
|
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
authUser() {
|
authUser() {
|
||||||
|
@ -104,5 +73,26 @@ export default {
|
||||||
keyboardShortcutsActive: KEYBOARD_SHORTCUTS_ACTIVE,
|
keyboardShortcutsActive: KEYBOARD_SHORTCUTS_ACTIVE,
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
|
methods: {
|
||||||
|
setupOnlineStatus() {
|
||||||
|
this.$store.commit(ONLINE, navigator.onLine)
|
||||||
|
window.addEventListener('online', () => this.$store.commit(ONLINE, navigator.onLine))
|
||||||
|
window.addEventListener('offline', () => this.$store.commit(ONLINE, navigator.onLine))
|
||||||
|
},
|
||||||
|
setupPasswortResetRedirect() {
|
||||||
|
if (this.$route.query.userPasswordReset !== undefined) {
|
||||||
|
localStorage.removeItem('passwordResetToken') // Delete an eventually preexisting old token
|
||||||
|
localStorage.setItem('passwordResetToken', this.$route.query.userPasswordReset)
|
||||||
|
this.$router.push({name: 'user.password-reset.reset'})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
setupEmailVerificationRedirect() {
|
||||||
|
if (this.$route.query.userEmailConfirm !== undefined) {
|
||||||
|
localStorage.removeItem('emailConfirmToken') // Delete an eventually preexisting old token
|
||||||
|
localStorage.setItem('emailConfirmToken', this.$route.query.userEmailConfirm)
|
||||||
|
this.$router.push({name: 'user.login'})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
Reference in New Issue