1
0

feat: redirect the user to the last page they were on before logging in after login

This commit is contained in:
kolaente
2021-10-13 21:53:39 +02:00
parent 97dd55d946
commit 9a2f95ecc6
5 changed files with 44 additions and 5 deletions

View File

@ -104,13 +104,13 @@
<script>
import {mapState} from 'vuex'
import router from '../../router'
import {HTTPFactory} from '@/http-common'
import {ERROR_MESSAGE, LOADING} from '@/store/mutation-types'
import legal from '../../components/misc/legal'
import ApiConfig from '@/components/misc/api-config.vue'
import {getErrorText} from '@/message'
import {redirectToProvider} from '../../helpers/redirectToProvider'
import {getLastVisited, clearLastVisited} from '../../helpers/saveLastVisited'
export default {
components: {
@ -142,9 +142,18 @@ export default {
})
}
// Check if the user is already logged in, if so, redirect him to the homepage
// Check if the user is already logged in, if so, redirect them to the homepage
if (this.authenticated) {
router.push({name: 'home'})
const last = getLastVisited()
if (last !== null) {
this.$router.push({
name: last.name,
params: last.params,
})
clearLastVisited()
} else {
this.$router.push({name: 'home'})
}
}
},
created() {

View File

@ -14,6 +14,7 @@ import {mapState} from 'vuex'
import {ERROR_MESSAGE, LOADING} from '@/store/mutation-types'
import {getErrorText} from '@/message'
import {clearLastVisited, getLastVisited} from '../../helpers/saveLastVisited'
export default {
name: 'Auth',
@ -63,7 +64,16 @@ export default {
code: this.$route.query.code,
})
.then(() => {
this.$router.push({name: 'home'})
const last = getLastVisited()
if (last !== null) {
this.$router.push({
name: last.name,
params: last.params,
})
clearLastVisited()
} else {
this.$router.push({name: 'home'})
}
})
.catch(e => {
const err = getErrorText(e, p => this.$t(p))

View File

@ -116,7 +116,7 @@ export default {
}
},
beforeMount() {
// Check if the user is already logged in, if so, redirect him to the homepage
// Check if the user is already logged in, if so, redirect them to the homepage
if (this.authenticated) {
router.push({name: 'home'})
}