WIP - BFF
This commit is contained in:
@@ -1,40 +1,25 @@
|
||||
export const useApi = () => {
|
||||
const config = useRuntimeConfig()
|
||||
const router = useRouter()
|
||||
const { toast } = useToast()
|
||||
const { isLoggedIn, logout } = useAuth()
|
||||
|
||||
// Use current domain for API calls (same subdomain routing)
|
||||
/**
|
||||
* API calls now go through the Nitro BFF proxy at /api/*
|
||||
* The proxy handles:
|
||||
* - Auth token injection from HTTP-only cookies
|
||||
* - Tenant subdomain extraction and forwarding
|
||||
* - Forwarding requests to the NestJS backend
|
||||
*/
|
||||
const getApiBaseUrl = () => {
|
||||
if (import.meta.client) {
|
||||
// In browser, use current hostname but with port 3000 for API
|
||||
const currentHost = window.location.hostname
|
||||
const protocol = window.location.protocol
|
||||
//return `${protocol}//${currentHost}:3000`
|
||||
return `${protocol}//${currentHost}`
|
||||
}
|
||||
// Fallback for SSR
|
||||
return config.public.apiBaseUrl
|
||||
// All API calls go through Nitro proxy - works for both SSR and client
|
||||
return ''
|
||||
}
|
||||
|
||||
const getHeaders = () => {
|
||||
// Headers are now minimal - auth and tenant are handled by the Nitro proxy
|
||||
const headers: Record<string, string> = {
|
||||
'Content-Type': 'application/json',
|
||||
}
|
||||
|
||||
// Add tenant ID from localStorage or state
|
||||
if (import.meta.client) {
|
||||
const tenantId = localStorage.getItem('tenantId')
|
||||
if (tenantId) {
|
||||
headers['x-tenant-id'] = tenantId
|
||||
}
|
||||
|
||||
const token = localStorage.getItem('token')
|
||||
if (token) {
|
||||
headers['Authorization'] = `Bearer ${token}`
|
||||
}
|
||||
}
|
||||
|
||||
return headers
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user