Initial commit: Nexus Mission Control Platform
- ASP.NET Core 10 Backend (JWT Auth, Agent config API) - Vue 3 Frontend (Dashboard, Team, Agents, Config Editor) - PostgreSQL Database - Docker Compose setup - Mission Control Dashboard redesign
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import { useAuthStore } from '../stores/auth'
|
||||
|
||||
export async function apiFetch(input: RequestInfo | URL, init: RequestInit = {}) {
|
||||
const auth = useAuthStore()
|
||||
if (!auth.initialized) await auth.initialize()
|
||||
|
||||
const send = () => {
|
||||
const headers = new Headers(init.headers)
|
||||
if (auth.accessToken) headers.set('Authorization', `Bearer ${auth.accessToken}`)
|
||||
return fetch(input, { ...init, headers, credentials: 'include' })
|
||||
}
|
||||
|
||||
let response = await send()
|
||||
if (response.status !== 401) return response
|
||||
|
||||
const refreshed = await auth.refresh()
|
||||
if (!refreshed) {
|
||||
if (window.location.pathname !== '/login') window.location.assign('/login')
|
||||
return response
|
||||
}
|
||||
|
||||
response = await send()
|
||||
return response
|
||||
}
|
||||
Reference in New Issue
Block a user