mirror of
https://github.com/r-ca/kidshift-web.git
synced 2024-10-25 16:34:01 +00:00
インターセプタ追加
This commit is contained in:
parent
983e5976f5
commit
39a62ab55a
|
@ -1,6 +1,7 @@
|
|||
import { boot } from 'quasar/wrappers';
|
||||
import axios, { AxiosInstance } from 'axios';
|
||||
import { API_BASE_URL } from 'src/const';
|
||||
import useStore from 'src/store';
|
||||
|
||||
declare module '@vue/runtime-core' {
|
||||
interface ComponentCustomProperties {
|
||||
|
@ -15,8 +16,20 @@ declare module '@vue/runtime-core' {
|
|||
// good idea to move this instance creation inside of the
|
||||
// "export default () => {}" function below (which runs individually
|
||||
// for each client)
|
||||
|
||||
const store = useStore();
|
||||
|
||||
const api = axios.create({ baseURL: API_BASE_URL })
|
||||
|
||||
// トークン付与
|
||||
api.interceptors.request.use((config) => {
|
||||
const token = store.state.account.token;
|
||||
if (token) {
|
||||
config.headers.Authorization = `Bearer ${token}`;
|
||||
}
|
||||
return config;
|
||||
});
|
||||
|
||||
export default boot(({ app }) => {
|
||||
// for use inside Vue files (Options API) through this.$axios and this.$api
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user