update auth

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2024-08-28 13:43:21 +07:00
parent 23afdc4df9
commit ff3fb68219
12 changed files with 222 additions and 308 deletions

View file

@ -1,5 +1,5 @@
import Axios, { type AxiosRequestConfig, type AxiosResponse } from 'axios'
import keycloak from './keycloak'
import { getToken } from './auth'
const http = Axios.create({
timeout: 1000000000, // เพิ่มค่า timeout
@ -10,10 +10,9 @@ const http = Axios.create({
http.interceptors.request.use(
async function (config: AxiosRequestConfig<any>) {
// await keycloak.updateToken(1)
config.headers = config.headers ?? {}
const token = keycloak.token
// const token = localStorage.getItem("access_token")
const token = await getToken()
if (token) config.headers.Authorization = `Bearer ${token}`
return config
},