axios now gets token from useSession
This commit is contained in:
parent
b64392431f
commit
f6d75ec944
17
src/main.ts
17
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);
|
||||
}
|
||||
);
|
||||
|
|
|
@ -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({
|
||||
|
|
Loading…
Reference in New Issue