axios now gets token from useSession

This commit is contained in:
Carlos Jimenez Ruiz 2022-03-09 10:45:48 +01:00
parent b64392431f
commit f6d75ec944
2 changed files with 12 additions and 9 deletions

View File

@ -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);
}
);

View File

@ -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({