From 8f418cd5daa64b698e41277792bf0ce60b7a4ba1 Mon Sep 17 00:00:00 2001 From: Agate Date: Sat, 18 Jul 2020 17:07:05 +0200 Subject: [PATCH] Added login redirection if needed on oauth Authorize --- front/src/components/auth/Authorize.vue | 2 ++ front/src/components/favorites/List.vue | 5 ++--- front/src/utils.js | 7 +++++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/front/src/components/auth/Authorize.vue b/front/src/components/auth/Authorize.vue index 9cd4754dd..2b7c823c2 100644 --- a/front/src/components/auth/Authorize.vue +++ b/front/src/components/auth/Authorize.vue @@ -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() } diff --git a/front/src/components/favorites/List.vue b/front/src/components/favorites/List.vue index 5766a219b..6aabb8817 100644 --- a/front/src/components/favorites/List.vue +++ b/front/src/components/favorites/List.vue @@ -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) }, diff --git a/front/src/utils.js b/front/src/utils.js index 50d308288..380f13e95 100644 --- a/front/src/utils.js +++ b/front/src/utils.js @@ -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}}) + } +}