This commit is contained in:
fro1991
2025-02-01 19:49:27 +07:00
parent 42c2a8e481
commit 13a2c4d42c
57 changed files with 159 additions and 295 deletions

View File

@ -1,11 +1,10 @@
import { User as Auth0UserModel } from '@auth0/auth0-spa-js';
import { getData, setData } from '@/utils';
import { type AuthModel } from './_models';
// import https from 'https'
const AUTH_LOCAL_STORAGE_KEY = `${import.meta.env.VITE_APP_NAME}-auth-v${
import.meta.env.VITE_APP_VERSION
}`;
const AUTH_LOCAL_STORAGE_KEY = `${import.meta.env.VITE_APP_NAME}-auth-v${import.meta.env.VITE_APP_VERSION
}`;
const getAuth = (): AuthModel | undefined => {
try {
@ -40,25 +39,12 @@ const removeAuth = () => {
export function setupAxios(axios: any) {
axios.defaults.headers.Accept = 'application/json';
axios.interceptors.request.use(
(config: { headers: { Authorization: string }; params?: any; url?: any }) => {
(config: { headers: { Authorization: string }; params?: any; url?: any; httpsAgent: any }) => {
const auth = getAuth();
if (auth?.access_token) {
config.headers.Authorization = `Bearer ${auth.access_token}`;
if (
config.url &&
!config.url.includes('api/b/') &&
!config.url.includes('api/bg/') &&
!config.url.includes('api/c/')
) {
config.params = {
...config.params,
token: auth.access_token || ''
};
}
}
return config;
},
async (err: any) => await Promise.reject(err)