forked from verdnatura/salix-front
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');
|
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);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -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({
|
||||||
|
|
Loading…
Reference in New Issue