0
0
Fork 0

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'); app.mount('#app');
import axios from 'axios'; import axios from 'axios';
axios.interceptors.request.use(
function (config) {
const token = localStorage.getItem('token');
if (token && config.headers) { import { useSession } from '@/core/composables/useSession';
config.headers.Authorization = token; 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) { function (error) {
// Do something with request error
return Promise.reject(error); return Promise.reject(error);
} }
); );

View File

@ -70,7 +70,7 @@ const { t, locale } = useI18n();
let username = ref(''); let username = ref('');
let password = ref(''); let password = ref('');
let keepLogin = true; let keepLogin = ref(true);
const darkMode = computed({ const darkMode = computed({
get(): boolean { get(): boolean {
@ -90,7 +90,7 @@ function onSubmit(): void {
.then((response) => { .then((response) => {
session.setToken({ session.setToken({
token: response.data.token, token: response.data.token,
keepLogin: keepLogin, keepLogin: keepLogin.value,
}); });
quasar.notify({ quasar.notify({