fix(dashboard): fix properties freeze, category/feature list views, and auth interceptor
deploy-chabokan / deploy (push) Canceled after 0s
deploy-chabokan / deploy (push) Canceled after 0s
This commit is contained in:
+29
-2
@@ -1,6 +1,33 @@
|
||||
<script setup>
|
||||
import axios from 'axios'
|
||||
axios.defaults.baseURL = import.meta.env.VITE_API_URL
|
||||
import axios from 'axios';
|
||||
import Cookies from 'js-cookie';
|
||||
|
||||
axios.defaults.baseURL = import.meta.env.VITE_API_URL;
|
||||
axios.defaults.withCredentials = true;
|
||||
|
||||
// Global Axios Request Interceptor for Authentication
|
||||
axios.interceptors.request.use((config) => {
|
||||
config.withCredentials = true;
|
||||
|
||||
// Resolve token from Cookies, localStorage, or document.cookie
|
||||
let token = Cookies.get('bm-token') || (typeof localStorage !== 'undefined' ? localStorage.getItem('bm-token') : null);
|
||||
|
||||
if (!token && typeof document !== 'undefined') {
|
||||
token = document.cookie
|
||||
.split('; ')
|
||||
.find((row) => row.startsWith('bm-token='))
|
||||
?.split('=')[1];
|
||||
}
|
||||
|
||||
if (token && token !== 'undefined' && token !== 'null' && token.trim() !== '') {
|
||||
config.headers = config.headers || {};
|
||||
config.headers.Authorization = `Bearer ${token.trim()}`;
|
||||
}
|
||||
|
||||
return config;
|
||||
}, (error) => {
|
||||
return Promise.reject(error);
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
Reference in New Issue
Block a user