Added login redirection if needed on oauth Authorize

This commit is contained in:
Agate 2020-07-18 17:07:05 +02:00
parent 0ffc4dafa8
commit 8f418cd5da
3 changed files with 11 additions and 3 deletions

View File

@ -66,6 +66,7 @@ import TranslationsMixin from "@/components/mixins/Translations"
import axios from 'axios'
import {checkRedirectToLogin} from '@/utils'
export default {
mixins: [TranslationsMixin],
props: [
@ -99,6 +100,7 @@ export default {
}
},
created () {
checkRedirectToLogin(this.$store, this.$router)
if (this.clientId) {
this.fetchApplication()
}

View File

@ -82,6 +82,7 @@ import Pagination from "@/components/Pagination"
import OrderingMixin from "@/components/mixins/Ordering"
import PaginationMixin from "@/components/mixins/Pagination"
import TranslationsMixin from "@/components/mixins/Translations"
import {checkRedirectToLogin} from '@/utils'
const FAVORITES_URL = "tracks/"
export default {
@ -107,9 +108,7 @@ export default {
}
},
created() {
if (!this.$store.state.auth.authenticated) {
this.$router.push({name: 'login', query: {next: this.$router.currentRoute.fullPath}})
}
checkRedirectToLogin(this.$store, this.$router)
this.fetchFavorites(FAVORITES_URL)
},

View File

@ -45,3 +45,10 @@ export function setCsrf(xhr) {
xhr.setRequestHeader('X-CSRFToken', getCookie('csrftoken'))
}
}
export function checkRedirectToLogin (store, router) {
console.log('HELLO', store.state.auth.authenticated, router.currentRoute.fullPath)
if (!store.state.auth.authenticated) {
router.push({name: 'login', query: {next: router.currentRoute.fullPath}})
}
}