latest
This commit is contained in:
1 parent
d0834df8df
commit
6dc35134fa
171 files changed
+19241
-49
No files matched your search
@@ -0,0 +1,24 @@
|
||||
import axios from 'axios'
|
||||
|
||||
export const apiClient = axios.create({
|
||||
baseURL: '/api/v1',
|
||||
withCredentials: true,
|
||||
withXSRFToken: true,
|
||||
headers: { Accept: 'application/json' },
|
||||
})
|
||||
|
||||
export async function ensureCsrfCookie() {
|
||||
await axios.get('/sanctum/csrf-cookie', { baseURL: '/', withCredentials: true, withXSRFToken: true })
|
||||
}
|
||||
|
||||
export const UNAUTHORIZED_EVENT = 'auth:unauthorized'
|
||||
|
||||
apiClient.interceptors.response.use(
|
||||
(response) => response,
|
||||
(error) => {
|
||||
if (error.response?.status === 401) {
|
||||
window.dispatchEvent(new CustomEvent(UNAUTHORIZED_EVENT))
|
||||
}
|
||||
return Promise.reject(error)
|
||||
},
|
||||
)
|
||||
Reference in new issue
Block a user