From f6d75ec9441b6ac8465923d4f148db2daad7d6b9 Mon Sep 17 00:00:00 2001 From: carlosjr Date: Wed, 9 Mar 2022 10:45:48 +0100 Subject: [PATCH] axios now gets token from useSession --- src/main.ts | 17 ++++++++++------- src/views/Login/Login.vue | 4 ++-- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/main.ts b/src/main.ts index 05f02ccc7..d2196221d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -10,18 +10,21 @@ const app = createApp(App).use(i18n).use(Quasar, quasarUserOptions).use(router); app.mount('#app'); import axios from 'axios'; -axios.interceptors.request.use( - function (config) { - const token = localStorage.getItem('token'); - if (token && config.headers) { - config.headers.Authorization = token; +import { useSession } from '@/core/composables/useSession'; +const { getToken } = useSession(); + +axios.interceptors.request.use( + function (context) { + const token = getToken(); + + if (token.length && context.headers) { + context.headers.Authorization = token; } - return config; + return context; }, function (error) { - // Do something with request error return Promise.reject(error); } ); diff --git a/src/views/Login/Login.vue b/src/views/Login/Login.vue index c01c6ff82..fe5f2033f 100644 --- a/src/views/Login/Login.vue +++ b/src/views/Login/Login.vue @@ -70,7 +70,7 @@ const { t, locale } = useI18n(); let username = ref(''); let password = ref(''); -let keepLogin = true; +let keepLogin = ref(true); const darkMode = computed({ get(): boolean { @@ -90,7 +90,7 @@ function onSubmit(): void { .then((response) => { session.setToken({ token: response.data.token, - keepLogin: keepLogin, + keepLogin: keepLogin.value, }); quasar.notify({