@bagelink/auth 1.7.98 → 1.7.104
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.
- package/dist/index.cjs +10 -0
- package/dist/index.mjs +10 -0
- package/package.json +1 -1
- package/src/api.ts +2 -0
- package/src/useAuth.ts +15 -2
package/dist/index.cjs
CHANGED
|
@@ -88,8 +88,10 @@ class AuthApi {
|
|
|
88
88
|
if (resetToken !== null) {
|
|
89
89
|
config.headers["X-Reset-Token"] = resetToken;
|
|
90
90
|
}
|
|
91
|
+
console.log("[AuthApi] Interceptor - currentTenantId:", this.currentTenantId);
|
|
91
92
|
if (this.currentTenantId !== null) {
|
|
92
93
|
config.headers["X-Tenant-ID"] = this.currentTenantId;
|
|
94
|
+
console.log("[AuthApi] Added X-Tenant-ID header:", this.currentTenantId);
|
|
93
95
|
}
|
|
94
96
|
return config;
|
|
95
97
|
});
|
|
@@ -2163,6 +2165,9 @@ function useAuth() {
|
|
|
2163
2165
|
await logoutPromise.catch(() => {
|
|
2164
2166
|
});
|
|
2165
2167
|
accountInfo.value = null;
|
|
2168
|
+
tenants.value = [];
|
|
2169
|
+
currentTenant.value = null;
|
|
2170
|
+
api.setTenantId(null);
|
|
2166
2171
|
emitter.emit(AuthState.LOGOUT);
|
|
2167
2172
|
}
|
|
2168
2173
|
async function login(credentials) {
|
|
@@ -2182,6 +2187,8 @@ function useAuth() {
|
|
|
2182
2187
|
accountInfo.value = data;
|
|
2183
2188
|
if (getIsLoggedIn()) {
|
|
2184
2189
|
emitter.emit(AuthState.AUTH_CHECK);
|
|
2190
|
+
await loadTenants().catch(() => {
|
|
2191
|
+
});
|
|
2185
2192
|
}
|
|
2186
2193
|
return true;
|
|
2187
2194
|
} catch {
|
|
@@ -2193,10 +2200,13 @@ function useAuth() {
|
|
|
2193
2200
|
try {
|
|
2194
2201
|
const { data } = await api.getTenants();
|
|
2195
2202
|
tenants.value = data;
|
|
2203
|
+
console.log("[Auth] Loaded tenants:", tenants.value);
|
|
2196
2204
|
if (currentTenant.value === null && tenants.value.length > 0) {
|
|
2197
2205
|
const firstActiveTenant = tenants.value.find((t) => t.status === "active");
|
|
2198
2206
|
if (firstActiveTenant !== void 0) {
|
|
2207
|
+
console.log("[Auth] Auto-selecting tenant:", firstActiveTenant.id);
|
|
2199
2208
|
setTenant(firstActiveTenant.id);
|
|
2209
|
+
console.log("[Auth] Tenant set. Current tenant ID in API:", api.getTenantId());
|
|
2200
2210
|
}
|
|
2201
2211
|
}
|
|
2202
2212
|
return tenants.value;
|
package/dist/index.mjs
CHANGED
|
@@ -86,8 +86,10 @@ class AuthApi {
|
|
|
86
86
|
if (resetToken !== null) {
|
|
87
87
|
config.headers["X-Reset-Token"] = resetToken;
|
|
88
88
|
}
|
|
89
|
+
console.log("[AuthApi] Interceptor - currentTenantId:", this.currentTenantId);
|
|
89
90
|
if (this.currentTenantId !== null) {
|
|
90
91
|
config.headers["X-Tenant-ID"] = this.currentTenantId;
|
|
92
|
+
console.log("[AuthApi] Added X-Tenant-ID header:", this.currentTenantId);
|
|
91
93
|
}
|
|
92
94
|
return config;
|
|
93
95
|
});
|
|
@@ -2161,6 +2163,9 @@ function useAuth() {
|
|
|
2161
2163
|
await logoutPromise.catch(() => {
|
|
2162
2164
|
});
|
|
2163
2165
|
accountInfo.value = null;
|
|
2166
|
+
tenants.value = [];
|
|
2167
|
+
currentTenant.value = null;
|
|
2168
|
+
api.setTenantId(null);
|
|
2164
2169
|
emitter.emit(AuthState.LOGOUT);
|
|
2165
2170
|
}
|
|
2166
2171
|
async function login(credentials) {
|
|
@@ -2180,6 +2185,8 @@ function useAuth() {
|
|
|
2180
2185
|
accountInfo.value = data;
|
|
2181
2186
|
if (getIsLoggedIn()) {
|
|
2182
2187
|
emitter.emit(AuthState.AUTH_CHECK);
|
|
2188
|
+
await loadTenants().catch(() => {
|
|
2189
|
+
});
|
|
2183
2190
|
}
|
|
2184
2191
|
return true;
|
|
2185
2192
|
} catch {
|
|
@@ -2191,10 +2198,13 @@ function useAuth() {
|
|
|
2191
2198
|
try {
|
|
2192
2199
|
const { data } = await api.getTenants();
|
|
2193
2200
|
tenants.value = data;
|
|
2201
|
+
console.log("[Auth] Loaded tenants:", tenants.value);
|
|
2194
2202
|
if (currentTenant.value === null && tenants.value.length > 0) {
|
|
2195
2203
|
const firstActiveTenant = tenants.value.find((t) => t.status === "active");
|
|
2196
2204
|
if (firstActiveTenant !== void 0) {
|
|
2205
|
+
console.log("[Auth] Auto-selecting tenant:", firstActiveTenant.id);
|
|
2197
2206
|
setTenant(firstActiveTenant.id);
|
|
2207
|
+
console.log("[Auth] Tenant set. Current tenant ID in API:", api.getTenantId());
|
|
2198
2208
|
}
|
|
2199
2209
|
}
|
|
2200
2210
|
return tenants.value;
|
package/package.json
CHANGED
package/src/api.ts
CHANGED
|
@@ -74,8 +74,10 @@ export class AuthApi {
|
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
// Add tenant ID header if set
|
|
77
|
+
console.log('[AuthApi] Interceptor - currentTenantId:', this.currentTenantId)
|
|
77
78
|
if (this.currentTenantId !== null) {
|
|
78
79
|
config.headers['X-Tenant-ID'] = this.currentTenantId
|
|
80
|
+
console.log('[AuthApi] Added X-Tenant-ID header:', this.currentTenantId)
|
|
79
81
|
}
|
|
80
82
|
|
|
81
83
|
return config
|
package/src/useAuth.ts
CHANGED
|
@@ -284,6 +284,9 @@ export function useAuth() {
|
|
|
284
284
|
})
|
|
285
285
|
// Clear local state regardless of API result
|
|
286
286
|
accountInfo.value = null
|
|
287
|
+
tenants.value = []
|
|
288
|
+
currentTenant.value = null
|
|
289
|
+
api.setTenantId(null)
|
|
287
290
|
// Emit logout event
|
|
288
291
|
emitter.emit(AuthState.LOGOUT)
|
|
289
292
|
}
|
|
@@ -294,9 +297,10 @@ export function useAuth() {
|
|
|
294
297
|
credentials.password
|
|
295
298
|
)
|
|
296
299
|
|
|
297
|
-
// If successful and not requiring verification, fetch user data
|
|
300
|
+
// If successful and not requiring verification, fetch user data and tenants
|
|
298
301
|
if (data.success === true && data.requires_verification !== true) {
|
|
299
302
|
await checkAuth()
|
|
303
|
+
// checkAuth now calls loadTenants automatically
|
|
300
304
|
}
|
|
301
305
|
|
|
302
306
|
emitter.emit(AuthState.LOGIN)
|
|
@@ -309,6 +313,10 @@ export function useAuth() {
|
|
|
309
313
|
accountInfo.value = data
|
|
310
314
|
if (getIsLoggedIn()) {
|
|
311
315
|
emitter.emit(AuthState.AUTH_CHECK)
|
|
316
|
+
// Auto-load tenants after successful auth check
|
|
317
|
+
await loadTenants().catch(() => {
|
|
318
|
+
// Silently fail if tenants not supported
|
|
319
|
+
})
|
|
312
320
|
}
|
|
313
321
|
return true
|
|
314
322
|
} catch {
|
|
@@ -322,11 +330,15 @@ export function useAuth() {
|
|
|
322
330
|
const { data } = await api.getTenants()
|
|
323
331
|
tenants.value = data
|
|
324
332
|
|
|
333
|
+
console.log('[Auth] Loaded tenants:', tenants.value)
|
|
334
|
+
|
|
325
335
|
// Auto-select first tenant if none selected and tenants available
|
|
326
336
|
if (currentTenant.value === null && tenants.value.length > 0) {
|
|
327
337
|
const firstActiveTenant = tenants.value.find(t => t.status === 'active')
|
|
328
338
|
if (firstActiveTenant !== undefined) {
|
|
339
|
+
console.log('[Auth] Auto-selecting tenant:', firstActiveTenant.id)
|
|
329
340
|
setTenant(firstActiveTenant.id)
|
|
341
|
+
console.log('[Auth] Tenant set. Current tenant ID in API:', api.getTenantId())
|
|
330
342
|
}
|
|
331
343
|
}
|
|
332
344
|
|
|
@@ -492,9 +504,10 @@ export function useAuth() {
|
|
|
492
504
|
async function loginWithSSO(params: SSOCallbackRequest) {
|
|
493
505
|
const { data } = await api.ssoCallback(params)
|
|
494
506
|
|
|
495
|
-
// If successful and not requiring verification, fetch user data
|
|
507
|
+
// If successful and not requiring verification, fetch user data and tenants
|
|
496
508
|
if (data.success === true && data.requires_verification !== true) {
|
|
497
509
|
await checkAuth()
|
|
510
|
+
// checkAuth now calls loadTenants automatically
|
|
498
511
|
}
|
|
499
512
|
|
|
500
513
|
emitter.emit(AuthState.LOGIN)
|