@innertia-solutions/innertia-nuxt 0.1.6 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// useTenantStore auto-imported.
|
|
2
|
-
// Server-only: valida el tenant via GET /
|
|
2
|
+
// Server-only: valida el tenant via GET /status con X-Tenant header.
|
|
3
3
|
// Usa la URL interna del backend (apiInternalUrl) para evitar pasar por el proxy de Nitro.
|
|
4
4
|
// Solo activo en mode === 'saas'.
|
|
5
5
|
export default defineNuxtRouteMiddleware(async (to) => {
|
|
@@ -31,13 +31,22 @@ export default defineNuxtRouteMiddleware(async (to) => {
|
|
|
31
31
|
// URL interna del backend (no pasa por el proxy Nitro — no existe en SSR)
|
|
32
32
|
const config = useRuntimeConfig()
|
|
33
33
|
const internalUrl = (config as any).apiInternalUrl || 'http://api:80'
|
|
34
|
-
const
|
|
34
|
+
const statusUrl = `${internalUrl}/status`
|
|
35
35
|
|
|
36
|
-
console.log(`[tenant:validate]
|
|
36
|
+
console.log(`[tenant:validate] status → ${statusUrl} (X-Tenant: ${tenantSlug})`)
|
|
37
37
|
|
|
38
38
|
try {
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
// Shape esperado:
|
|
40
|
+
// { ok, tenant: { id, key, name, status, isActive },
|
|
41
|
+
// features: { organizations, teams, twoFactor, oauth: [] },
|
|
42
|
+
// branding: { demo } }
|
|
43
|
+
const data = await $fetch<{
|
|
44
|
+
ok: boolean
|
|
45
|
+
tenant: { id: number; key: string; name: string; status: string; isActive: boolean }
|
|
46
|
+
features?: Record<string, any>
|
|
47
|
+
branding?: Record<string, any>
|
|
48
|
+
}>(
|
|
49
|
+
statusUrl,
|
|
41
50
|
{
|
|
42
51
|
headers: { 'X-Tenant': tenantSlug, 'Accept': 'application/json' },
|
|
43
52
|
timeout: 5000,
|
|
@@ -51,8 +60,17 @@ export default defineNuxtRouteMiddleware(async (to) => {
|
|
|
51
60
|
return navigateTo('/tenant-error?reason=inactive')
|
|
52
61
|
}
|
|
53
62
|
|
|
63
|
+
// tenantStore.setTenant expects (id, config). Combinamos features + branding como config
|
|
64
|
+
// para compatibilidad con consumidores existentes que leen tenantStore.config.
|
|
54
65
|
const tenantStore = useTenantStore()
|
|
55
|
-
tenantStore.setTenant(data.tenant.id,
|
|
66
|
+
tenantStore.setTenant(data.tenant.id, {
|
|
67
|
+
...(data.tenant ?? {}),
|
|
68
|
+
features: data.features ?? {},
|
|
69
|
+
branding: data.branding ?? {},
|
|
70
|
+
// Compatibilidad con código viejo que lee config.demo y config.oauthProviders directo
|
|
71
|
+
demo: data.branding?.demo ?? null,
|
|
72
|
+
oauthProviders: data.features?.oauth ?? [],
|
|
73
|
+
})
|
|
56
74
|
console.log(`[tenant:validate] OK — tenant id=${data.tenant.id} status=${data.tenant.status}`)
|
|
57
75
|
} catch (e: any) {
|
|
58
76
|
const status = e?.response?.status
|