diff --git a/src/App.vue b/src/App.vue index 926c0c5f9..cb15b53b9 100644 --- a/src/App.vue +++ b/src/App.vue @@ -46,49 +46,18 @@ export default { Notification, }, beforeMount() { - // Check if the user is offline, show a message then - this.$store.commit(ONLINE, navigator.onLine) - window.addEventListener('online', () => this.$store.commit(ONLINE, navigator.onLine)) - 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'}) - } + this.setupOnlineStatus() + this.setupPasswortResetRedirect() + this.setupEmailVerificationRedirect() }, beforeCreate() { 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() { - // Make sure to always load the home route when running with electron if (this.$route.fullPath.endsWith('frontend/index.html')) { this.$router.push({name: 'home'}) } - - this.renewTokenOnFocus() }, computed: { authUser() { @@ -104,5 +73,26 @@ export default { 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'}) + } + }, + }, }