fix: fixing the CORS issues
This commit is contained in:
@@ -1,6 +1,10 @@
|
|||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
|
|
||||||
const API_BASE_URL = process.env.VUE_APP_API_URL || 'http://127.0.0.1:5000'
|
// In production, use relative path to hit the proxy
|
||||||
|
// In development, use the env variable for dev server proxy
|
||||||
|
const API_BASE_URL = process.env.NODE_ENV === 'production'
|
||||||
|
? '/api'
|
||||||
|
: process.env.VUE_APP_API_URL || 'http://127.0.0.1:5000'
|
||||||
|
|
||||||
const api = axios.create({
|
const api = axios.create({
|
||||||
baseURL: API_BASE_URL,
|
baseURL: API_BASE_URL,
|
||||||
@@ -36,11 +40,14 @@ api.interceptors.response.use(
|
|||||||
throw new Error('No refresh token')
|
throw new Error('No refresh token')
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note: You'll need to implement this endpoint on the backend
|
// Use relative path in production, full URL in development
|
||||||
const { data } = await axios.post(
|
const refreshUrl = process.env.NODE_ENV === 'production'
|
||||||
`${API_BASE_URL}/api/refresh-token`,
|
? '/api/refresh-token'
|
||||||
{ refresh_token: refreshToken }
|
: `${API_BASE_URL}/api/refresh-token`
|
||||||
)
|
|
||||||
|
const { data } = await axios.post(refreshUrl, {
|
||||||
|
refresh_token: refreshToken
|
||||||
|
})
|
||||||
|
|
||||||
localStorage.setItem('access_token', data.access_token)
|
localStorage.setItem('access_token', data.access_token)
|
||||||
originalRequest.headers.Authorization = `Bearer ${data.access_token}`
|
originalRequest.headers.Authorization = `Bearer ${data.access_token}`
|
||||||
|
|||||||
Reference in New Issue
Block a user