@bagelink/auth 1.7.96 → 1.7.101
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 +38 -28
- package/dist/index.mjs +38 -28
- package/package.json +1 -1
- package/src/api.ts +30 -28
- 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
|
});
|
|
@@ -101,13 +103,13 @@ class AuthApi {
|
|
|
101
103
|
* Get available authentication methods
|
|
102
104
|
*/
|
|
103
105
|
async getAuthMethods() {
|
|
104
|
-
return this.api.get("
|
|
106
|
+
return this.api.get("authentication/methods");
|
|
105
107
|
}
|
|
106
108
|
/**
|
|
107
109
|
* Register a new account
|
|
108
110
|
*/
|
|
109
111
|
async register(data) {
|
|
110
|
-
return this.api.post("
|
|
112
|
+
return this.api.post("authentication/register", {
|
|
111
113
|
...data,
|
|
112
114
|
email: data.email.toLowerCase()
|
|
113
115
|
});
|
|
@@ -116,7 +118,7 @@ class AuthApi {
|
|
|
116
118
|
* Login with password
|
|
117
119
|
*/
|
|
118
120
|
async login(email, password) {
|
|
119
|
-
return this.api.post("
|
|
121
|
+
return this.api.post("authentication/login/password", {
|
|
120
122
|
email: email.toLowerCase(),
|
|
121
123
|
password
|
|
122
124
|
});
|
|
@@ -125,13 +127,13 @@ class AuthApi {
|
|
|
125
127
|
* Logout and clear session
|
|
126
128
|
*/
|
|
127
129
|
async logout() {
|
|
128
|
-
return this.api.post("
|
|
130
|
+
return this.api.post("authentication/logout", {});
|
|
129
131
|
}
|
|
130
132
|
/**
|
|
131
133
|
* Refresh current session
|
|
132
134
|
*/
|
|
133
135
|
async refreshSession() {
|
|
134
|
-
return this.api.post("
|
|
136
|
+
return this.api.post("authentication/refresh", {});
|
|
135
137
|
}
|
|
136
138
|
// ============================================
|
|
137
139
|
// SSO Authentication Methods
|
|
@@ -141,7 +143,7 @@ class AuthApi {
|
|
|
141
143
|
* Returns authorization URL to redirect user to
|
|
142
144
|
*/
|
|
143
145
|
async initiateSSO(data) {
|
|
144
|
-
return this.api.post(
|
|
146
|
+
return this.api.post(`authentication/sso/${data.provider}/initiate`, {
|
|
145
147
|
redirect_uri: data.redirect_uri,
|
|
146
148
|
state: data.state
|
|
147
149
|
});
|
|
@@ -150,7 +152,7 @@ class AuthApi {
|
|
|
150
152
|
* Complete SSO login after callback from provider
|
|
151
153
|
*/
|
|
152
154
|
async ssoCallback(data) {
|
|
153
|
-
return this.api.post(
|
|
155
|
+
return this.api.post(`authentication/sso/${data.provider}/callback`, {
|
|
154
156
|
code: data.code,
|
|
155
157
|
state: data.state
|
|
156
158
|
});
|
|
@@ -159,7 +161,7 @@ class AuthApi {
|
|
|
159
161
|
* Link an SSO provider to existing account
|
|
160
162
|
*/
|
|
161
163
|
async linkSSOProvider(data) {
|
|
162
|
-
return this.api.post(
|
|
164
|
+
return this.api.post(`authentication/sso/${data.provider}/link`, {
|
|
163
165
|
code: data.code,
|
|
164
166
|
state: data.state
|
|
165
167
|
});
|
|
@@ -168,7 +170,7 @@ class AuthApi {
|
|
|
168
170
|
* Unlink an SSO provider from account
|
|
169
171
|
*/
|
|
170
172
|
async unlinkSSOProvider(provider) {
|
|
171
|
-
return this.api.delete(
|
|
173
|
+
return this.api.delete(`authentication/sso/${provider}/unlink`);
|
|
172
174
|
}
|
|
173
175
|
// ============================================
|
|
174
176
|
// Current User (Me) Methods
|
|
@@ -177,19 +179,19 @@ class AuthApi {
|
|
|
177
179
|
* Get current user account info
|
|
178
180
|
*/
|
|
179
181
|
async getCurrentUser() {
|
|
180
|
-
return this.api.get("
|
|
182
|
+
return this.api.get("authentication/me");
|
|
181
183
|
}
|
|
182
184
|
/**
|
|
183
185
|
* Update current user profile
|
|
184
186
|
*/
|
|
185
187
|
async updateCurrentUser(data) {
|
|
186
|
-
return this.api.patch("
|
|
188
|
+
return this.api.patch("authentication/me", data);
|
|
187
189
|
}
|
|
188
190
|
/**
|
|
189
191
|
* Delete current user account
|
|
190
192
|
*/
|
|
191
193
|
async deleteCurrentUser() {
|
|
192
|
-
return this.api.delete("
|
|
194
|
+
return this.api.delete("authentication/me");
|
|
193
195
|
}
|
|
194
196
|
// ============================================
|
|
195
197
|
// Account Management (Admin)
|
|
@@ -198,31 +200,31 @@ class AuthApi {
|
|
|
198
200
|
* Get account information by ID
|
|
199
201
|
*/
|
|
200
202
|
async getAccount(accountId) {
|
|
201
|
-
return this.api.get(
|
|
203
|
+
return this.api.get(`authentication/account/${accountId}`);
|
|
202
204
|
}
|
|
203
205
|
/**
|
|
204
206
|
* Update account by ID
|
|
205
207
|
*/
|
|
206
208
|
async updateAccount(accountId, data) {
|
|
207
|
-
return this.api.patch(
|
|
209
|
+
return this.api.patch(`authentication/account/${accountId}`, data);
|
|
208
210
|
}
|
|
209
211
|
/**
|
|
210
212
|
* Delete account by ID
|
|
211
213
|
*/
|
|
212
214
|
async deleteAccount(accountId) {
|
|
213
|
-
return this.api.delete(
|
|
215
|
+
return this.api.delete(`authentication/account/${accountId}`);
|
|
214
216
|
}
|
|
215
217
|
/**
|
|
216
218
|
* Activate account by ID
|
|
217
219
|
*/
|
|
218
220
|
async activateAccount(accountId) {
|
|
219
|
-
return this.api.post(
|
|
221
|
+
return this.api.post(`authentication/account/${accountId}/activate`, {});
|
|
220
222
|
}
|
|
221
223
|
/**
|
|
222
224
|
* Deactivate account by ID
|
|
223
225
|
*/
|
|
224
226
|
async deactivateAccount(accountId) {
|
|
225
|
-
return this.api.post(
|
|
227
|
+
return this.api.post(`authentication/account/${accountId}/deactivate`, {});
|
|
226
228
|
}
|
|
227
229
|
// ============================================
|
|
228
230
|
// Password Management
|
|
@@ -231,13 +233,13 @@ class AuthApi {
|
|
|
231
233
|
* Change password (requires current password)
|
|
232
234
|
*/
|
|
233
235
|
async changePassword(data) {
|
|
234
|
-
return this.api.post("
|
|
236
|
+
return this.api.post("authentication/password/change", data);
|
|
235
237
|
}
|
|
236
238
|
/**
|
|
237
239
|
* Initiate forgot password flow
|
|
238
240
|
*/
|
|
239
241
|
async forgotPassword(email) {
|
|
240
|
-
return this.api.post("
|
|
242
|
+
return this.api.post("authentication/password/forgot", {
|
|
241
243
|
email: email.toLowerCase()
|
|
242
244
|
});
|
|
243
245
|
}
|
|
@@ -245,13 +247,13 @@ class AuthApi {
|
|
|
245
247
|
* Verify password reset token
|
|
246
248
|
*/
|
|
247
249
|
async verifyResetToken(token) {
|
|
248
|
-
return this.api.get(
|
|
250
|
+
return this.api.get(`authentication/password/verify-reset-token/${token}`);
|
|
249
251
|
}
|
|
250
252
|
/**
|
|
251
253
|
* Reset password with token
|
|
252
254
|
*/
|
|
253
255
|
async resetPassword(data) {
|
|
254
|
-
return this.api.post("
|
|
256
|
+
return this.api.post("authentication/password/reset", data);
|
|
255
257
|
}
|
|
256
258
|
// ============================================
|
|
257
259
|
// Email Verification
|
|
@@ -260,7 +262,7 @@ class AuthApi {
|
|
|
260
262
|
* Send email verification
|
|
261
263
|
*/
|
|
262
264
|
async sendVerification(data = {}, user) {
|
|
263
|
-
return this.api.post("
|
|
265
|
+
return this.api.post("authentication/verify/send", data, {
|
|
264
266
|
params: user ? { user } : void 0
|
|
265
267
|
});
|
|
266
268
|
}
|
|
@@ -268,7 +270,7 @@ class AuthApi {
|
|
|
268
270
|
* Verify email with token
|
|
269
271
|
*/
|
|
270
272
|
async verifyEmail(token) {
|
|
271
|
-
return this.api.post("
|
|
273
|
+
return this.api.post("authentication/verify/email", { token });
|
|
272
274
|
}
|
|
273
275
|
// ============================================
|
|
274
276
|
// Session Management
|
|
@@ -277,25 +279,25 @@ class AuthApi {
|
|
|
277
279
|
* Get sessions for an account
|
|
278
280
|
*/
|
|
279
281
|
async getSessions(accountId) {
|
|
280
|
-
return this.api.get(
|
|
282
|
+
return this.api.get(`authentication/sessions/${accountId}`);
|
|
281
283
|
}
|
|
282
284
|
/**
|
|
283
285
|
* Revoke a specific session
|
|
284
286
|
*/
|
|
285
287
|
async revokeSession(sessionToken) {
|
|
286
|
-
return this.api.delete(
|
|
288
|
+
return this.api.delete(`authentication/sessions/${sessionToken}`);
|
|
287
289
|
}
|
|
288
290
|
/**
|
|
289
291
|
* Revoke all sessions for an account
|
|
290
292
|
*/
|
|
291
293
|
async revokeAllSessions(accountId) {
|
|
292
|
-
return this.api.delete(
|
|
294
|
+
return this.api.delete(`authentication/sessions/account/${accountId}`);
|
|
293
295
|
}
|
|
294
296
|
/**
|
|
295
297
|
* Cleanup expired sessions (admin)
|
|
296
298
|
*/
|
|
297
299
|
async cleanupSessions() {
|
|
298
|
-
return this.api.post("
|
|
300
|
+
return this.api.post("authentication/cleanup-sessions", {});
|
|
299
301
|
}
|
|
300
302
|
// ============================================
|
|
301
303
|
// Multi-Tenancy Methods
|
|
@@ -304,7 +306,7 @@ class AuthApi {
|
|
|
304
306
|
* Get list of tenants the authenticated user belongs to
|
|
305
307
|
*/
|
|
306
308
|
async getTenants() {
|
|
307
|
-
return this.api.get("
|
|
309
|
+
return this.api.get("tenants");
|
|
308
310
|
}
|
|
309
311
|
}
|
|
310
312
|
const _hoisted_1$8 = { class: "txt20 bold mb-1" };
|
|
@@ -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
|
});
|
|
@@ -99,13 +101,13 @@ class AuthApi {
|
|
|
99
101
|
* Get available authentication methods
|
|
100
102
|
*/
|
|
101
103
|
async getAuthMethods() {
|
|
102
|
-
return this.api.get("
|
|
104
|
+
return this.api.get("authentication/methods");
|
|
103
105
|
}
|
|
104
106
|
/**
|
|
105
107
|
* Register a new account
|
|
106
108
|
*/
|
|
107
109
|
async register(data) {
|
|
108
|
-
return this.api.post("
|
|
110
|
+
return this.api.post("authentication/register", {
|
|
109
111
|
...data,
|
|
110
112
|
email: data.email.toLowerCase()
|
|
111
113
|
});
|
|
@@ -114,7 +116,7 @@ class AuthApi {
|
|
|
114
116
|
* Login with password
|
|
115
117
|
*/
|
|
116
118
|
async login(email, password) {
|
|
117
|
-
return this.api.post("
|
|
119
|
+
return this.api.post("authentication/login/password", {
|
|
118
120
|
email: email.toLowerCase(),
|
|
119
121
|
password
|
|
120
122
|
});
|
|
@@ -123,13 +125,13 @@ class AuthApi {
|
|
|
123
125
|
* Logout and clear session
|
|
124
126
|
*/
|
|
125
127
|
async logout() {
|
|
126
|
-
return this.api.post("
|
|
128
|
+
return this.api.post("authentication/logout", {});
|
|
127
129
|
}
|
|
128
130
|
/**
|
|
129
131
|
* Refresh current session
|
|
130
132
|
*/
|
|
131
133
|
async refreshSession() {
|
|
132
|
-
return this.api.post("
|
|
134
|
+
return this.api.post("authentication/refresh", {});
|
|
133
135
|
}
|
|
134
136
|
// ============================================
|
|
135
137
|
// SSO Authentication Methods
|
|
@@ -139,7 +141,7 @@ class AuthApi {
|
|
|
139
141
|
* Returns authorization URL to redirect user to
|
|
140
142
|
*/
|
|
141
143
|
async initiateSSO(data) {
|
|
142
|
-
return this.api.post(
|
|
144
|
+
return this.api.post(`authentication/sso/${data.provider}/initiate`, {
|
|
143
145
|
redirect_uri: data.redirect_uri,
|
|
144
146
|
state: data.state
|
|
145
147
|
});
|
|
@@ -148,7 +150,7 @@ class AuthApi {
|
|
|
148
150
|
* Complete SSO login after callback from provider
|
|
149
151
|
*/
|
|
150
152
|
async ssoCallback(data) {
|
|
151
|
-
return this.api.post(
|
|
153
|
+
return this.api.post(`authentication/sso/${data.provider}/callback`, {
|
|
152
154
|
code: data.code,
|
|
153
155
|
state: data.state
|
|
154
156
|
});
|
|
@@ -157,7 +159,7 @@ class AuthApi {
|
|
|
157
159
|
* Link an SSO provider to existing account
|
|
158
160
|
*/
|
|
159
161
|
async linkSSOProvider(data) {
|
|
160
|
-
return this.api.post(
|
|
162
|
+
return this.api.post(`authentication/sso/${data.provider}/link`, {
|
|
161
163
|
code: data.code,
|
|
162
164
|
state: data.state
|
|
163
165
|
});
|
|
@@ -166,7 +168,7 @@ class AuthApi {
|
|
|
166
168
|
* Unlink an SSO provider from account
|
|
167
169
|
*/
|
|
168
170
|
async unlinkSSOProvider(provider) {
|
|
169
|
-
return this.api.delete(
|
|
171
|
+
return this.api.delete(`authentication/sso/${provider}/unlink`);
|
|
170
172
|
}
|
|
171
173
|
// ============================================
|
|
172
174
|
// Current User (Me) Methods
|
|
@@ -175,19 +177,19 @@ class AuthApi {
|
|
|
175
177
|
* Get current user account info
|
|
176
178
|
*/
|
|
177
179
|
async getCurrentUser() {
|
|
178
|
-
return this.api.get("
|
|
180
|
+
return this.api.get("authentication/me");
|
|
179
181
|
}
|
|
180
182
|
/**
|
|
181
183
|
* Update current user profile
|
|
182
184
|
*/
|
|
183
185
|
async updateCurrentUser(data) {
|
|
184
|
-
return this.api.patch("
|
|
186
|
+
return this.api.patch("authentication/me", data);
|
|
185
187
|
}
|
|
186
188
|
/**
|
|
187
189
|
* Delete current user account
|
|
188
190
|
*/
|
|
189
191
|
async deleteCurrentUser() {
|
|
190
|
-
return this.api.delete("
|
|
192
|
+
return this.api.delete("authentication/me");
|
|
191
193
|
}
|
|
192
194
|
// ============================================
|
|
193
195
|
// Account Management (Admin)
|
|
@@ -196,31 +198,31 @@ class AuthApi {
|
|
|
196
198
|
* Get account information by ID
|
|
197
199
|
*/
|
|
198
200
|
async getAccount(accountId) {
|
|
199
|
-
return this.api.get(
|
|
201
|
+
return this.api.get(`authentication/account/${accountId}`);
|
|
200
202
|
}
|
|
201
203
|
/**
|
|
202
204
|
* Update account by ID
|
|
203
205
|
*/
|
|
204
206
|
async updateAccount(accountId, data) {
|
|
205
|
-
return this.api.patch(
|
|
207
|
+
return this.api.patch(`authentication/account/${accountId}`, data);
|
|
206
208
|
}
|
|
207
209
|
/**
|
|
208
210
|
* Delete account by ID
|
|
209
211
|
*/
|
|
210
212
|
async deleteAccount(accountId) {
|
|
211
|
-
return this.api.delete(
|
|
213
|
+
return this.api.delete(`authentication/account/${accountId}`);
|
|
212
214
|
}
|
|
213
215
|
/**
|
|
214
216
|
* Activate account by ID
|
|
215
217
|
*/
|
|
216
218
|
async activateAccount(accountId) {
|
|
217
|
-
return this.api.post(
|
|
219
|
+
return this.api.post(`authentication/account/${accountId}/activate`, {});
|
|
218
220
|
}
|
|
219
221
|
/**
|
|
220
222
|
* Deactivate account by ID
|
|
221
223
|
*/
|
|
222
224
|
async deactivateAccount(accountId) {
|
|
223
|
-
return this.api.post(
|
|
225
|
+
return this.api.post(`authentication/account/${accountId}/deactivate`, {});
|
|
224
226
|
}
|
|
225
227
|
// ============================================
|
|
226
228
|
// Password Management
|
|
@@ -229,13 +231,13 @@ class AuthApi {
|
|
|
229
231
|
* Change password (requires current password)
|
|
230
232
|
*/
|
|
231
233
|
async changePassword(data) {
|
|
232
|
-
return this.api.post("
|
|
234
|
+
return this.api.post("authentication/password/change", data);
|
|
233
235
|
}
|
|
234
236
|
/**
|
|
235
237
|
* Initiate forgot password flow
|
|
236
238
|
*/
|
|
237
239
|
async forgotPassword(email) {
|
|
238
|
-
return this.api.post("
|
|
240
|
+
return this.api.post("authentication/password/forgot", {
|
|
239
241
|
email: email.toLowerCase()
|
|
240
242
|
});
|
|
241
243
|
}
|
|
@@ -243,13 +245,13 @@ class AuthApi {
|
|
|
243
245
|
* Verify password reset token
|
|
244
246
|
*/
|
|
245
247
|
async verifyResetToken(token) {
|
|
246
|
-
return this.api.get(
|
|
248
|
+
return this.api.get(`authentication/password/verify-reset-token/${token}`);
|
|
247
249
|
}
|
|
248
250
|
/**
|
|
249
251
|
* Reset password with token
|
|
250
252
|
*/
|
|
251
253
|
async resetPassword(data) {
|
|
252
|
-
return this.api.post("
|
|
254
|
+
return this.api.post("authentication/password/reset", data);
|
|
253
255
|
}
|
|
254
256
|
// ============================================
|
|
255
257
|
// Email Verification
|
|
@@ -258,7 +260,7 @@ class AuthApi {
|
|
|
258
260
|
* Send email verification
|
|
259
261
|
*/
|
|
260
262
|
async sendVerification(data = {}, user) {
|
|
261
|
-
return this.api.post("
|
|
263
|
+
return this.api.post("authentication/verify/send", data, {
|
|
262
264
|
params: user ? { user } : void 0
|
|
263
265
|
});
|
|
264
266
|
}
|
|
@@ -266,7 +268,7 @@ class AuthApi {
|
|
|
266
268
|
* Verify email with token
|
|
267
269
|
*/
|
|
268
270
|
async verifyEmail(token) {
|
|
269
|
-
return this.api.post("
|
|
271
|
+
return this.api.post("authentication/verify/email", { token });
|
|
270
272
|
}
|
|
271
273
|
// ============================================
|
|
272
274
|
// Session Management
|
|
@@ -275,25 +277,25 @@ class AuthApi {
|
|
|
275
277
|
* Get sessions for an account
|
|
276
278
|
*/
|
|
277
279
|
async getSessions(accountId) {
|
|
278
|
-
return this.api.get(
|
|
280
|
+
return this.api.get(`authentication/sessions/${accountId}`);
|
|
279
281
|
}
|
|
280
282
|
/**
|
|
281
283
|
* Revoke a specific session
|
|
282
284
|
*/
|
|
283
285
|
async revokeSession(sessionToken) {
|
|
284
|
-
return this.api.delete(
|
|
286
|
+
return this.api.delete(`authentication/sessions/${sessionToken}`);
|
|
285
287
|
}
|
|
286
288
|
/**
|
|
287
289
|
* Revoke all sessions for an account
|
|
288
290
|
*/
|
|
289
291
|
async revokeAllSessions(accountId) {
|
|
290
|
-
return this.api.delete(
|
|
292
|
+
return this.api.delete(`authentication/sessions/account/${accountId}`);
|
|
291
293
|
}
|
|
292
294
|
/**
|
|
293
295
|
* Cleanup expired sessions (admin)
|
|
294
296
|
*/
|
|
295
297
|
async cleanupSessions() {
|
|
296
|
-
return this.api.post("
|
|
298
|
+
return this.api.post("authentication/cleanup-sessions", {});
|
|
297
299
|
}
|
|
298
300
|
// ============================================
|
|
299
301
|
// Multi-Tenancy Methods
|
|
@@ -302,7 +304,7 @@ class AuthApi {
|
|
|
302
304
|
* Get list of tenants the authenticated user belongs to
|
|
303
305
|
*/
|
|
304
306
|
async getTenants() {
|
|
305
|
-
return this.api.get("
|
|
307
|
+
return this.api.get("tenants");
|
|
306
308
|
}
|
|
307
309
|
}
|
|
308
310
|
const _hoisted_1$8 = { class: "txt20 bold mb-1" };
|
|
@@ -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
|
|
@@ -90,14 +92,14 @@ export class AuthApi {
|
|
|
90
92
|
* Get available authentication methods
|
|
91
93
|
*/
|
|
92
94
|
async getAuthMethods(): Promise<GetMethodsResponse> {
|
|
93
|
-
return this.api.get('
|
|
95
|
+
return this.api.get('authentication/methods')
|
|
94
96
|
}
|
|
95
97
|
|
|
96
98
|
/**
|
|
97
99
|
* Register a new account
|
|
98
100
|
*/
|
|
99
101
|
async register(data: RegisterRequest): Promise<RegisterResponse> {
|
|
100
|
-
return this.api.post('
|
|
102
|
+
return this.api.post('authentication/register', {
|
|
101
103
|
...data,
|
|
102
104
|
email: data.email.toLowerCase(),
|
|
103
105
|
})
|
|
@@ -107,7 +109,7 @@ export class AuthApi {
|
|
|
107
109
|
* Login with password
|
|
108
110
|
*/
|
|
109
111
|
async login(email: string, password: string): Promise<LoginResponse> {
|
|
110
|
-
return this.api.post('
|
|
112
|
+
return this.api.post('authentication/login/password', {
|
|
111
113
|
email: email.toLowerCase(),
|
|
112
114
|
password,
|
|
113
115
|
})
|
|
@@ -117,14 +119,14 @@ export class AuthApi {
|
|
|
117
119
|
* Logout and clear session
|
|
118
120
|
*/
|
|
119
121
|
async logout(): Promise<LogoutResponse> {
|
|
120
|
-
return this.api.post('
|
|
122
|
+
return this.api.post('authentication/logout', {})
|
|
121
123
|
}
|
|
122
124
|
|
|
123
125
|
/**
|
|
124
126
|
* Refresh current session
|
|
125
127
|
*/
|
|
126
128
|
async refreshSession(): Promise<RefreshSessionResponse> {
|
|
127
|
-
return this.api.post('
|
|
129
|
+
return this.api.post('authentication/refresh', {})
|
|
128
130
|
}
|
|
129
131
|
|
|
130
132
|
// ============================================
|
|
@@ -136,7 +138,7 @@ export class AuthApi {
|
|
|
136
138
|
* Returns authorization URL to redirect user to
|
|
137
139
|
*/
|
|
138
140
|
async initiateSSO(data: SSOInitiateRequest): Promise<SSOInitiateResponse> {
|
|
139
|
-
return this.api.post(
|
|
141
|
+
return this.api.post(`authentication/sso/${data.provider}/initiate`, {
|
|
140
142
|
redirect_uri: data.redirect_uri,
|
|
141
143
|
state: data.state,
|
|
142
144
|
})
|
|
@@ -146,7 +148,7 @@ export class AuthApi {
|
|
|
146
148
|
* Complete SSO login after callback from provider
|
|
147
149
|
*/
|
|
148
150
|
async ssoCallback(data: SSOCallbackRequest): Promise<SSOCallbackResponse> {
|
|
149
|
-
return this.api.post(
|
|
151
|
+
return this.api.post(`authentication/sso/${data.provider}/callback`, {
|
|
150
152
|
code: data.code,
|
|
151
153
|
state: data.state,
|
|
152
154
|
})
|
|
@@ -156,7 +158,7 @@ export class AuthApi {
|
|
|
156
158
|
* Link an SSO provider to existing account
|
|
157
159
|
*/
|
|
158
160
|
async linkSSOProvider(data: SSOLinkRequest): Promise<SSOLinkResponse> {
|
|
159
|
-
return this.api.post(
|
|
161
|
+
return this.api.post(`authentication/sso/${data.provider}/link`, {
|
|
160
162
|
code: data.code,
|
|
161
163
|
state: data.state,
|
|
162
164
|
})
|
|
@@ -166,7 +168,7 @@ export class AuthApi {
|
|
|
166
168
|
* Unlink an SSO provider from account
|
|
167
169
|
*/
|
|
168
170
|
async unlinkSSOProvider(provider: SSOProvider): Promise<SSOUnlinkResponse> {
|
|
169
|
-
return this.api.delete(
|
|
171
|
+
return this.api.delete(`authentication/sso/${provider}/unlink`)
|
|
170
172
|
}
|
|
171
173
|
|
|
172
174
|
// ============================================
|
|
@@ -177,21 +179,21 @@ export class AuthApi {
|
|
|
177
179
|
* Get current user account info
|
|
178
180
|
*/
|
|
179
181
|
async getCurrentUser(): Promise<GetMeResponse> {
|
|
180
|
-
return this.api.get('
|
|
182
|
+
return this.api.get('authentication/me')
|
|
181
183
|
}
|
|
182
184
|
|
|
183
185
|
/**
|
|
184
186
|
* Update current user profile
|
|
185
187
|
*/
|
|
186
188
|
async updateCurrentUser(data: UpdateAccountRequest): Promise<UpdateMeResponse> {
|
|
187
|
-
return this.api.patch('
|
|
189
|
+
return this.api.patch('authentication/me', data)
|
|
188
190
|
}
|
|
189
191
|
|
|
190
192
|
/**
|
|
191
193
|
* Delete current user account
|
|
192
194
|
*/
|
|
193
195
|
async deleteCurrentUser(): Promise<DeleteMeResponse> {
|
|
194
|
-
return this.api.delete('
|
|
196
|
+
return this.api.delete('authentication/me')
|
|
195
197
|
}
|
|
196
198
|
|
|
197
199
|
// ============================================
|
|
@@ -202,7 +204,7 @@ export class AuthApi {
|
|
|
202
204
|
* Get account information by ID
|
|
203
205
|
*/
|
|
204
206
|
async getAccount(accountId: string): Promise<GetAccountResponse> {
|
|
205
|
-
return this.api.get(
|
|
207
|
+
return this.api.get(`authentication/account/${accountId}`)
|
|
206
208
|
}
|
|
207
209
|
|
|
208
210
|
/**
|
|
@@ -212,21 +214,21 @@ export class AuthApi {
|
|
|
212
214
|
accountId: string,
|
|
213
215
|
data: UpdateAccountRequest
|
|
214
216
|
): Promise<UpdateAccountResponse> {
|
|
215
|
-
return this.api.patch(
|
|
217
|
+
return this.api.patch(`authentication/account/${accountId}`, data)
|
|
216
218
|
}
|
|
217
219
|
|
|
218
220
|
/**
|
|
219
221
|
* Delete account by ID
|
|
220
222
|
*/
|
|
221
223
|
async deleteAccount(accountId: string): Promise<DeleteAccountResponse> {
|
|
222
|
-
return this.api.delete(
|
|
224
|
+
return this.api.delete(`authentication/account/${accountId}`)
|
|
223
225
|
}
|
|
224
226
|
|
|
225
227
|
/**
|
|
226
228
|
* Activate account by ID
|
|
227
229
|
*/
|
|
228
230
|
async activateAccount(accountId: string): Promise<ActivateAccountResponse> {
|
|
229
|
-
return this.api.post(
|
|
231
|
+
return this.api.post(`authentication/account/${accountId}/activate`, {})
|
|
230
232
|
}
|
|
231
233
|
|
|
232
234
|
/**
|
|
@@ -235,7 +237,7 @@ export class AuthApi {
|
|
|
235
237
|
async deactivateAccount(
|
|
236
238
|
accountId: string
|
|
237
239
|
): Promise<DeactivateAccountResponse> {
|
|
238
|
-
return this.api.post(
|
|
240
|
+
return this.api.post(`authentication/account/${accountId}/deactivate`, {})
|
|
239
241
|
}
|
|
240
242
|
|
|
241
243
|
// ============================================
|
|
@@ -246,14 +248,14 @@ export class AuthApi {
|
|
|
246
248
|
* Change password (requires current password)
|
|
247
249
|
*/
|
|
248
250
|
async changePassword(data: ChangePasswordRequest): Promise<ChangePasswordResponse> {
|
|
249
|
-
return this.api.post('
|
|
251
|
+
return this.api.post('authentication/password/change', data)
|
|
250
252
|
}
|
|
251
253
|
|
|
252
254
|
/**
|
|
253
255
|
* Initiate forgot password flow
|
|
254
256
|
*/
|
|
255
257
|
async forgotPassword(email: string): Promise<ForgotPasswordResponse> {
|
|
256
|
-
return this.api.post('
|
|
258
|
+
return this.api.post('authentication/password/forgot', {
|
|
257
259
|
email: email.toLowerCase(),
|
|
258
260
|
})
|
|
259
261
|
}
|
|
@@ -262,14 +264,14 @@ export class AuthApi {
|
|
|
262
264
|
* Verify password reset token
|
|
263
265
|
*/
|
|
264
266
|
async verifyResetToken(token: string): Promise<VerifyResetTokenResponse> {
|
|
265
|
-
return this.api.get(
|
|
267
|
+
return this.api.get(`authentication/password/verify-reset-token/${token}`)
|
|
266
268
|
}
|
|
267
269
|
|
|
268
270
|
/**
|
|
269
271
|
* Reset password with token
|
|
270
272
|
*/
|
|
271
273
|
async resetPassword(data: ResetPasswordRequest): Promise<ResetPasswordResponse> {
|
|
272
|
-
return this.api.post('
|
|
274
|
+
return this.api.post('authentication/password/reset', data)
|
|
273
275
|
}
|
|
274
276
|
|
|
275
277
|
// ============================================
|
|
@@ -283,7 +285,7 @@ export class AuthApi {
|
|
|
283
285
|
data: SendVerificationRequest = {},
|
|
284
286
|
user?: AuthenticationAccount
|
|
285
287
|
): Promise<SendVerificationResponse> {
|
|
286
|
-
return this.api.post('
|
|
288
|
+
return this.api.post('authentication/verify/send', data, {
|
|
287
289
|
params: user ? { user } : undefined,
|
|
288
290
|
})
|
|
289
291
|
}
|
|
@@ -292,7 +294,7 @@ export class AuthApi {
|
|
|
292
294
|
* Verify email with token
|
|
293
295
|
*/
|
|
294
296
|
async verifyEmail(token: string): Promise<VerifyEmailResponse> {
|
|
295
|
-
return this.api.post('
|
|
297
|
+
return this.api.post('authentication/verify/email', { token })
|
|
296
298
|
}
|
|
297
299
|
|
|
298
300
|
// ============================================
|
|
@@ -303,28 +305,28 @@ export class AuthApi {
|
|
|
303
305
|
* Get sessions for an account
|
|
304
306
|
*/
|
|
305
307
|
async getSessions(accountId: string): Promise<GetSessionsResponse> {
|
|
306
|
-
return this.api.get(
|
|
308
|
+
return this.api.get(`authentication/sessions/${accountId}`)
|
|
307
309
|
}
|
|
308
310
|
|
|
309
311
|
/**
|
|
310
312
|
* Revoke a specific session
|
|
311
313
|
*/
|
|
312
314
|
async revokeSession(sessionToken: string): Promise<DeleteSessionResponse> {
|
|
313
|
-
return this.api.delete(
|
|
315
|
+
return this.api.delete(`authentication/sessions/${sessionToken}`)
|
|
314
316
|
}
|
|
315
317
|
|
|
316
318
|
/**
|
|
317
319
|
* Revoke all sessions for an account
|
|
318
320
|
*/
|
|
319
321
|
async revokeAllSessions(accountId: string): Promise<DeleteAllSessionsResponse> {
|
|
320
|
-
return this.api.delete(
|
|
322
|
+
return this.api.delete(`authentication/sessions/account/${accountId}`)
|
|
321
323
|
}
|
|
322
324
|
|
|
323
325
|
/**
|
|
324
326
|
* Cleanup expired sessions (admin)
|
|
325
327
|
*/
|
|
326
328
|
async cleanupSessions(): Promise<CleanupSessionsResponse> {
|
|
327
|
-
return this.api.post('
|
|
329
|
+
return this.api.post('authentication/cleanup-sessions', {})
|
|
328
330
|
}
|
|
329
331
|
|
|
330
332
|
// ============================================
|
|
@@ -335,6 +337,6 @@ export class AuthApi {
|
|
|
335
337
|
* Get list of tenants the authenticated user belongs to
|
|
336
338
|
*/
|
|
337
339
|
async getTenants(): Promise<GetTenantsResponse> {
|
|
338
|
-
return this.api.get('
|
|
340
|
+
return this.api.get('tenants')
|
|
339
341
|
}
|
|
340
342
|
}
|
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)
|