Compare commits
2 Commits
4197df2b2f
...
de07ccac8e
| Author | SHA1 | Date | |
|---|---|---|---|
| de07ccac8e | |||
| 853939e8b8 |
@@ -9,6 +9,7 @@ import type { AxiosInstance, InternalAxiosRequestConfig } from 'axios'
|
||||
*/
|
||||
export interface AxiosBindingsDeps {
|
||||
getActiveOrgId: () => string | null
|
||||
getImpersonationTargetUserId: () => string | null
|
||||
notify: (message: string, level: 'error' | 'warning') => void
|
||||
onAuthFail: () => void
|
||||
onImpersonationRevoked: () => void
|
||||
@@ -31,25 +32,16 @@ export function registerInterceptors(client: AxiosInstance, deps: AxiosBindingsD
|
||||
if (orgId)
|
||||
config.headers['X-Organisation-Id'] = orgId
|
||||
|
||||
// Read impersonation header directly from sessionStorage — no store dep.
|
||||
const impersonationData = sessionStorage.getItem('crewli_impersonation')
|
||||
if (impersonationData) {
|
||||
try {
|
||||
const parsed = JSON.parse(impersonationData) as { targetUserId?: string }
|
||||
if (parsed.targetUserId)
|
||||
config.headers['X-Impersonate-User'] = parsed.targetUserId
|
||||
}
|
||||
catch {
|
||||
// Invalid data — ignore
|
||||
}
|
||||
}
|
||||
const impersonationTargetUserId = deps.getImpersonationTargetUserId()
|
||||
if (impersonationTargetUserId)
|
||||
config.headers['X-Impersonate-User'] = impersonationTargetUserId
|
||||
|
||||
if (import.meta.env.DEV)
|
||||
console.log(`🚀 ${config.method?.toUpperCase()} ${config.url}`, config.data)
|
||||
|
||||
return config
|
||||
},
|
||||
async error => { throw error },
|
||||
error => { throw error },
|
||||
)
|
||||
|
||||
client.interceptors.response.use(
|
||||
@@ -59,7 +51,7 @@ export function registerInterceptors(client: AxiosInstance, deps: AxiosBindingsD
|
||||
|
||||
return response
|
||||
},
|
||||
async error => {
|
||||
error => {
|
||||
if (import.meta.env.DEV)
|
||||
console.error(`❌ ${error.response?.status} ${error.config?.url}`, error.response?.data)
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import { useOrganisationStore } from '@/stores/useOrganisationStore'
|
||||
export default function (_: App): void {
|
||||
registerInterceptors(apiClient, {
|
||||
getActiveOrgId: () => useOrganisationStore().activeOrganisationId,
|
||||
getImpersonationTargetUserId: () => useImpersonationStore().targetUserId,
|
||||
notify: (message, level) => useNotificationStore().show(message, level),
|
||||
onAuthFail: () => {
|
||||
const authStore = useAuthStore()
|
||||
|
||||
Reference in New Issue
Block a user