@bagelink/auth 1.7.94 → 1.7.98
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/api.d.ts +14 -1
- package/dist/index.cjs +113 -53
- package/dist/index.mjs +113 -53
- package/dist/types.d.ts +30 -18
- package/dist/useAuth.d.ts +85 -25
- package/package.json +1 -1
- package/src/api.ts +60 -27
- package/src/types.ts +58 -49
- package/src/useAuth.ts +69 -8
package/dist/index.mjs
CHANGED
|
@@ -63,9 +63,22 @@ function queryParams() {
|
|
|
63
63
|
class AuthApi {
|
|
64
64
|
constructor(baseURL = "") {
|
|
65
65
|
__publicField(this, "api");
|
|
66
|
+
__publicField(this, "currentTenantId", null);
|
|
66
67
|
this.api = createAxiosInstance(baseURL);
|
|
67
68
|
this.setupInterceptors();
|
|
68
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Set the current tenant ID for multi-tenant requests
|
|
72
|
+
*/
|
|
73
|
+
setTenantId(tenantId) {
|
|
74
|
+
this.currentTenantId = tenantId;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Get the current tenant ID
|
|
78
|
+
*/
|
|
79
|
+
getTenantId() {
|
|
80
|
+
return this.currentTenantId;
|
|
81
|
+
}
|
|
69
82
|
setupInterceptors() {
|
|
70
83
|
this.api.interceptors.request.use((config) => {
|
|
71
84
|
const urlParams = new URLSearchParams(window.location.search);
|
|
@@ -73,6 +86,9 @@ class AuthApi {
|
|
|
73
86
|
if (resetToken !== null) {
|
|
74
87
|
config.headers["X-Reset-Token"] = resetToken;
|
|
75
88
|
}
|
|
89
|
+
if (this.currentTenantId !== null) {
|
|
90
|
+
config.headers["X-Tenant-ID"] = this.currentTenantId;
|
|
91
|
+
}
|
|
76
92
|
return config;
|
|
77
93
|
});
|
|
78
94
|
}
|
|
@@ -83,13 +99,13 @@ class AuthApi {
|
|
|
83
99
|
* Get available authentication methods
|
|
84
100
|
*/
|
|
85
101
|
async getAuthMethods() {
|
|
86
|
-
return this.api.get("
|
|
102
|
+
return this.api.get("authentication/methods");
|
|
87
103
|
}
|
|
88
104
|
/**
|
|
89
105
|
* Register a new account
|
|
90
106
|
*/
|
|
91
107
|
async register(data) {
|
|
92
|
-
return this.api.post("
|
|
108
|
+
return this.api.post("authentication/register", {
|
|
93
109
|
...data,
|
|
94
110
|
email: data.email.toLowerCase()
|
|
95
111
|
});
|
|
@@ -98,7 +114,7 @@ class AuthApi {
|
|
|
98
114
|
* Login with password
|
|
99
115
|
*/
|
|
100
116
|
async login(email, password) {
|
|
101
|
-
return this.api.post("
|
|
117
|
+
return this.api.post("authentication/login/password", {
|
|
102
118
|
email: email.toLowerCase(),
|
|
103
119
|
password
|
|
104
120
|
});
|
|
@@ -107,13 +123,13 @@ class AuthApi {
|
|
|
107
123
|
* Logout and clear session
|
|
108
124
|
*/
|
|
109
125
|
async logout() {
|
|
110
|
-
return this.api.post("
|
|
126
|
+
return this.api.post("authentication/logout", {});
|
|
111
127
|
}
|
|
112
128
|
/**
|
|
113
129
|
* Refresh current session
|
|
114
130
|
*/
|
|
115
131
|
async refreshSession() {
|
|
116
|
-
return this.api.post("
|
|
132
|
+
return this.api.post("authentication/refresh", {});
|
|
117
133
|
}
|
|
118
134
|
// ============================================
|
|
119
135
|
// SSO Authentication Methods
|
|
@@ -123,7 +139,7 @@ class AuthApi {
|
|
|
123
139
|
* Returns authorization URL to redirect user to
|
|
124
140
|
*/
|
|
125
141
|
async initiateSSO(data) {
|
|
126
|
-
return this.api.post(
|
|
142
|
+
return this.api.post(`authentication/sso/${data.provider}/initiate`, {
|
|
127
143
|
redirect_uri: data.redirect_uri,
|
|
128
144
|
state: data.state
|
|
129
145
|
});
|
|
@@ -132,7 +148,7 @@ class AuthApi {
|
|
|
132
148
|
* Complete SSO login after callback from provider
|
|
133
149
|
*/
|
|
134
150
|
async ssoCallback(data) {
|
|
135
|
-
return this.api.post(
|
|
151
|
+
return this.api.post(`authentication/sso/${data.provider}/callback`, {
|
|
136
152
|
code: data.code,
|
|
137
153
|
state: data.state
|
|
138
154
|
});
|
|
@@ -141,7 +157,7 @@ class AuthApi {
|
|
|
141
157
|
* Link an SSO provider to existing account
|
|
142
158
|
*/
|
|
143
159
|
async linkSSOProvider(data) {
|
|
144
|
-
return this.api.post(
|
|
160
|
+
return this.api.post(`authentication/sso/${data.provider}/link`, {
|
|
145
161
|
code: data.code,
|
|
146
162
|
state: data.state
|
|
147
163
|
});
|
|
@@ -150,7 +166,7 @@ class AuthApi {
|
|
|
150
166
|
* Unlink an SSO provider from account
|
|
151
167
|
*/
|
|
152
168
|
async unlinkSSOProvider(provider) {
|
|
153
|
-
return this.api.delete(
|
|
169
|
+
return this.api.delete(`authentication/sso/${provider}/unlink`);
|
|
154
170
|
}
|
|
155
171
|
// ============================================
|
|
156
172
|
// Current User (Me) Methods
|
|
@@ -159,19 +175,19 @@ class AuthApi {
|
|
|
159
175
|
* Get current user account info
|
|
160
176
|
*/
|
|
161
177
|
async getCurrentUser() {
|
|
162
|
-
return this.api.get("
|
|
178
|
+
return this.api.get("authentication/me");
|
|
163
179
|
}
|
|
164
180
|
/**
|
|
165
181
|
* Update current user profile
|
|
166
182
|
*/
|
|
167
183
|
async updateCurrentUser(data) {
|
|
168
|
-
return this.api.patch("
|
|
184
|
+
return this.api.patch("authentication/me", data);
|
|
169
185
|
}
|
|
170
186
|
/**
|
|
171
187
|
* Delete current user account
|
|
172
188
|
*/
|
|
173
189
|
async deleteCurrentUser() {
|
|
174
|
-
return this.api.delete("
|
|
190
|
+
return this.api.delete("authentication/me");
|
|
175
191
|
}
|
|
176
192
|
// ============================================
|
|
177
193
|
// Account Management (Admin)
|
|
@@ -180,31 +196,31 @@ class AuthApi {
|
|
|
180
196
|
* Get account information by ID
|
|
181
197
|
*/
|
|
182
198
|
async getAccount(accountId) {
|
|
183
|
-
return this.api.get(
|
|
199
|
+
return this.api.get(`authentication/account/${accountId}`);
|
|
184
200
|
}
|
|
185
201
|
/**
|
|
186
202
|
* Update account by ID
|
|
187
203
|
*/
|
|
188
204
|
async updateAccount(accountId, data) {
|
|
189
|
-
return this.api.patch(
|
|
205
|
+
return this.api.patch(`authentication/account/${accountId}`, data);
|
|
190
206
|
}
|
|
191
207
|
/**
|
|
192
208
|
* Delete account by ID
|
|
193
209
|
*/
|
|
194
210
|
async deleteAccount(accountId) {
|
|
195
|
-
return this.api.delete(
|
|
211
|
+
return this.api.delete(`authentication/account/${accountId}`);
|
|
196
212
|
}
|
|
197
213
|
/**
|
|
198
214
|
* Activate account by ID
|
|
199
215
|
*/
|
|
200
216
|
async activateAccount(accountId) {
|
|
201
|
-
return this.api.post(
|
|
217
|
+
return this.api.post(`authentication/account/${accountId}/activate`, {});
|
|
202
218
|
}
|
|
203
219
|
/**
|
|
204
220
|
* Deactivate account by ID
|
|
205
221
|
*/
|
|
206
222
|
async deactivateAccount(accountId) {
|
|
207
|
-
return this.api.post(
|
|
223
|
+
return this.api.post(`authentication/account/${accountId}/deactivate`, {});
|
|
208
224
|
}
|
|
209
225
|
// ============================================
|
|
210
226
|
// Password Management
|
|
@@ -213,13 +229,13 @@ class AuthApi {
|
|
|
213
229
|
* Change password (requires current password)
|
|
214
230
|
*/
|
|
215
231
|
async changePassword(data) {
|
|
216
|
-
return this.api.post("
|
|
232
|
+
return this.api.post("authentication/password/change", data);
|
|
217
233
|
}
|
|
218
234
|
/**
|
|
219
235
|
* Initiate forgot password flow
|
|
220
236
|
*/
|
|
221
237
|
async forgotPassword(email) {
|
|
222
|
-
return this.api.post("
|
|
238
|
+
return this.api.post("authentication/password/forgot", {
|
|
223
239
|
email: email.toLowerCase()
|
|
224
240
|
});
|
|
225
241
|
}
|
|
@@ -227,13 +243,13 @@ class AuthApi {
|
|
|
227
243
|
* Verify password reset token
|
|
228
244
|
*/
|
|
229
245
|
async verifyResetToken(token) {
|
|
230
|
-
return this.api.get(
|
|
246
|
+
return this.api.get(`authentication/password/verify-reset-token/${token}`);
|
|
231
247
|
}
|
|
232
248
|
/**
|
|
233
249
|
* Reset password with token
|
|
234
250
|
*/
|
|
235
251
|
async resetPassword(data) {
|
|
236
|
-
return this.api.post("
|
|
252
|
+
return this.api.post("authentication/password/reset", data);
|
|
237
253
|
}
|
|
238
254
|
// ============================================
|
|
239
255
|
// Email Verification
|
|
@@ -242,7 +258,7 @@ class AuthApi {
|
|
|
242
258
|
* Send email verification
|
|
243
259
|
*/
|
|
244
260
|
async sendVerification(data = {}, user) {
|
|
245
|
-
return this.api.post("
|
|
261
|
+
return this.api.post("authentication/verify/send", data, {
|
|
246
262
|
params: user ? { user } : void 0
|
|
247
263
|
});
|
|
248
264
|
}
|
|
@@ -250,7 +266,7 @@ class AuthApi {
|
|
|
250
266
|
* Verify email with token
|
|
251
267
|
*/
|
|
252
268
|
async verifyEmail(token) {
|
|
253
|
-
return this.api.post("
|
|
269
|
+
return this.api.post("authentication/verify/email", { token });
|
|
254
270
|
}
|
|
255
271
|
// ============================================
|
|
256
272
|
// Session Management
|
|
@@ -259,25 +275,34 @@ class AuthApi {
|
|
|
259
275
|
* Get sessions for an account
|
|
260
276
|
*/
|
|
261
277
|
async getSessions(accountId) {
|
|
262
|
-
return this.api.get(
|
|
278
|
+
return this.api.get(`authentication/sessions/${accountId}`);
|
|
263
279
|
}
|
|
264
280
|
/**
|
|
265
281
|
* Revoke a specific session
|
|
266
282
|
*/
|
|
267
283
|
async revokeSession(sessionToken) {
|
|
268
|
-
return this.api.delete(
|
|
284
|
+
return this.api.delete(`authentication/sessions/${sessionToken}`);
|
|
269
285
|
}
|
|
270
286
|
/**
|
|
271
287
|
* Revoke all sessions for an account
|
|
272
288
|
*/
|
|
273
289
|
async revokeAllSessions(accountId) {
|
|
274
|
-
return this.api.delete(
|
|
290
|
+
return this.api.delete(`authentication/sessions/account/${accountId}`);
|
|
275
291
|
}
|
|
276
292
|
/**
|
|
277
293
|
* Cleanup expired sessions (admin)
|
|
278
294
|
*/
|
|
279
295
|
async cleanupSessions() {
|
|
280
|
-
return this.api.post("
|
|
296
|
+
return this.api.post("authentication/cleanup-sessions", {});
|
|
297
|
+
}
|
|
298
|
+
// ============================================
|
|
299
|
+
// Multi-Tenancy Methods
|
|
300
|
+
// ============================================
|
|
301
|
+
/**
|
|
302
|
+
* Get list of tenants the authenticated user belongs to
|
|
303
|
+
*/
|
|
304
|
+
async getTenants() {
|
|
305
|
+
return this.api.get("tenants");
|
|
281
306
|
}
|
|
282
307
|
}
|
|
283
308
|
const _hoisted_1$8 = { class: "txt20 bold mb-1" };
|
|
@@ -1900,35 +1925,24 @@ function accountToUser(account) {
|
|
|
1900
1925
|
if (account === null) {
|
|
1901
1926
|
return null;
|
|
1902
1927
|
}
|
|
1903
|
-
|
|
1928
|
+
const hasPersonLinked = account.person !== void 0 && account.person !== null;
|
|
1929
|
+
if (hasPersonLinked) {
|
|
1904
1930
|
return {
|
|
1905
1931
|
id: account.person.id,
|
|
1906
1932
|
accountId: account.id,
|
|
1907
1933
|
name: account.person.name,
|
|
1908
|
-
email: account.person.email,
|
|
1934
|
+
email: account.person.email ?? void 0,
|
|
1909
1935
|
type: account.account_type,
|
|
1910
1936
|
roles: account.person.roles,
|
|
1911
1937
|
isActive: account.is_active,
|
|
1912
1938
|
isVerified: account.is_verified,
|
|
1913
1939
|
person: account.person,
|
|
1914
|
-
lastLogin: account.last_login
|
|
1915
|
-
|
|
1916
|
-
}
|
|
1917
|
-
if (account.entity !== void 0) {
|
|
1918
|
-
return {
|
|
1919
|
-
id: account.entity.id,
|
|
1920
|
-
accountId: account.id,
|
|
1921
|
-
name: account.entity.name,
|
|
1922
|
-
type: account.account_type,
|
|
1923
|
-
isActive: account.is_active,
|
|
1924
|
-
isVerified: account.is_verified,
|
|
1925
|
-
lastLogin: account.last_login,
|
|
1926
|
-
entityType: account.entity.type,
|
|
1927
|
-
metadata: account.entity.metadata
|
|
1940
|
+
lastLogin: account.last_login ?? void 0,
|
|
1941
|
+
hasPersonLinked: true
|
|
1928
1942
|
};
|
|
1929
1943
|
}
|
|
1930
1944
|
const emailMethod = account.authentication_methods.find(
|
|
1931
|
-
(m) => m.type === "password" || m.type === "email_token"
|
|
1945
|
+
(m) => m.type === "password" || m.type === "email_token" || m.type === "sso"
|
|
1932
1946
|
);
|
|
1933
1947
|
return {
|
|
1934
1948
|
id: account.id,
|
|
@@ -1938,7 +1952,8 @@ function accountToUser(account) {
|
|
|
1938
1952
|
type: account.account_type,
|
|
1939
1953
|
isActive: account.is_active,
|
|
1940
1954
|
isVerified: account.is_verified,
|
|
1941
|
-
lastLogin: account.last_login
|
|
1955
|
+
lastLogin: account.last_login ?? void 0,
|
|
1956
|
+
hasPersonLinked: false
|
|
1942
1957
|
};
|
|
1943
1958
|
}
|
|
1944
1959
|
const DEFAULT_REDIRECT_CONFIG = {
|
|
@@ -1963,6 +1978,8 @@ let redirectConfig = null;
|
|
|
1963
1978
|
let autoRedirectRouter = null;
|
|
1964
1979
|
let cachedAuthGuard = null;
|
|
1965
1980
|
const accountInfo = ref(null);
|
|
1981
|
+
const tenants = ref([]);
|
|
1982
|
+
const currentTenant = ref(null);
|
|
1966
1983
|
function getRedirectConfig() {
|
|
1967
1984
|
if (!redirectConfig) {
|
|
1968
1985
|
throw new Error("Redirect config not initialized. Did you call createAuth with redirect config?");
|
|
@@ -2133,15 +2150,11 @@ function useAuth() {
|
|
|
2133
2150
|
};
|
|
2134
2151
|
const getAccountType = () => {
|
|
2135
2152
|
var _a;
|
|
2136
|
-
return ((_a = user.value) == null ? void 0 : _a.type) ?? "
|
|
2153
|
+
return ((_a = user.value) == null ? void 0 : _a.type) ?? "identity";
|
|
2137
2154
|
};
|
|
2138
2155
|
const isPersonAccount = () => {
|
|
2139
2156
|
var _a;
|
|
2140
|
-
return ((_a = user.value) == null ? void 0 : _a.
|
|
2141
|
-
};
|
|
2142
|
-
const isEntityAccount = () => {
|
|
2143
|
-
var _a;
|
|
2144
|
-
return ((_a = user.value) == null ? void 0 : _a.type) === "entity";
|
|
2157
|
+
return ((_a = user.value) == null ? void 0 : _a.hasPersonLinked) === true;
|
|
2145
2158
|
};
|
|
2146
2159
|
async function logout() {
|
|
2147
2160
|
const logoutPromise = api.logout();
|
|
@@ -2174,6 +2187,45 @@ function useAuth() {
|
|
|
2174
2187
|
return false;
|
|
2175
2188
|
}
|
|
2176
2189
|
}
|
|
2190
|
+
async function loadTenants() {
|
|
2191
|
+
try {
|
|
2192
|
+
const { data } = await api.getTenants();
|
|
2193
|
+
tenants.value = data;
|
|
2194
|
+
if (currentTenant.value === null && tenants.value.length > 0) {
|
|
2195
|
+
const firstActiveTenant = tenants.value.find((t) => t.status === "active");
|
|
2196
|
+
if (firstActiveTenant !== void 0) {
|
|
2197
|
+
setTenant(firstActiveTenant.id);
|
|
2198
|
+
}
|
|
2199
|
+
}
|
|
2200
|
+
return tenants.value;
|
|
2201
|
+
} catch {
|
|
2202
|
+
tenants.value = [];
|
|
2203
|
+
return [];
|
|
2204
|
+
}
|
|
2205
|
+
}
|
|
2206
|
+
function setTenant(tenantId) {
|
|
2207
|
+
if (tenantId === null) {
|
|
2208
|
+
currentTenant.value = null;
|
|
2209
|
+
api.setTenantId(null);
|
|
2210
|
+
return;
|
|
2211
|
+
}
|
|
2212
|
+
const tenant = tenants.value.find((t) => t.id === tenantId);
|
|
2213
|
+
if (tenant !== void 0) {
|
|
2214
|
+
currentTenant.value = tenant;
|
|
2215
|
+
api.setTenantId(tenantId);
|
|
2216
|
+
} else {
|
|
2217
|
+
throw new Error(`Tenant with ID ${tenantId} not found`);
|
|
2218
|
+
}
|
|
2219
|
+
}
|
|
2220
|
+
function switchTenant(tenantId) {
|
|
2221
|
+
setTenant(tenantId);
|
|
2222
|
+
}
|
|
2223
|
+
function getTenants() {
|
|
2224
|
+
return tenants.value;
|
|
2225
|
+
}
|
|
2226
|
+
function getCurrentTenant() {
|
|
2227
|
+
return currentTenant.value;
|
|
2228
|
+
}
|
|
2177
2229
|
async function signup(newUser) {
|
|
2178
2230
|
const hasPassword = newUser.password !== void 0 && newUser.password.length > 0;
|
|
2179
2231
|
if (hasPassword && newUser.password !== newUser.confirmPassword) {
|
|
@@ -2288,6 +2340,9 @@ function useAuth() {
|
|
|
2288
2340
|
accountInfo,
|
|
2289
2341
|
// SSO Providers (ready to use!)
|
|
2290
2342
|
sso,
|
|
2343
|
+
// Multi-Tenancy State
|
|
2344
|
+
tenants,
|
|
2345
|
+
currentTenant,
|
|
2291
2346
|
// Getters
|
|
2292
2347
|
getFullName,
|
|
2293
2348
|
getIsLoggedIn,
|
|
@@ -2295,7 +2350,8 @@ function useAuth() {
|
|
|
2295
2350
|
getRoles,
|
|
2296
2351
|
getAccountType,
|
|
2297
2352
|
isPersonAccount,
|
|
2298
|
-
|
|
2353
|
+
getTenants,
|
|
2354
|
+
getCurrentTenant,
|
|
2299
2355
|
// Authentication Actions
|
|
2300
2356
|
login,
|
|
2301
2357
|
logout,
|
|
@@ -2325,7 +2381,11 @@ function useAuth() {
|
|
|
2325
2381
|
// Session Management
|
|
2326
2382
|
getSessions,
|
|
2327
2383
|
revokeSession,
|
|
2328
|
-
revokeAllSessions
|
|
2384
|
+
revokeAllSessions,
|
|
2385
|
+
// Multi-Tenancy Actions
|
|
2386
|
+
loadTenants,
|
|
2387
|
+
setTenant,
|
|
2388
|
+
switchTenant
|
|
2329
2389
|
};
|
|
2330
2390
|
}
|
|
2331
2391
|
const useAuth$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
package/dist/types.d.ts
CHANGED
|
@@ -22,7 +22,20 @@ export interface AuthEventMap {
|
|
|
22
22
|
[AuthState.EMAIL_VERIFIED]: AuthEventHandler;
|
|
23
23
|
[AuthState.SESSION_REFRESH]: AuthEventHandler;
|
|
24
24
|
}
|
|
25
|
-
export type AuthenticationAccountType = '
|
|
25
|
+
export type AuthenticationAccountType = 'identity' | string;
|
|
26
|
+
export type TenantStatus = 'active' | 'suspended' | 'archived';
|
|
27
|
+
export interface TenantInfo {
|
|
28
|
+
id: string;
|
|
29
|
+
name: string;
|
|
30
|
+
slug: string;
|
|
31
|
+
parent_id: string | null;
|
|
32
|
+
settings: Record<string, any> | null;
|
|
33
|
+
status: TenantStatus;
|
|
34
|
+
suspended_at: string | null;
|
|
35
|
+
suspended_reason: string | null;
|
|
36
|
+
created_at: string;
|
|
37
|
+
updated_at: string;
|
|
38
|
+
}
|
|
26
39
|
export type AuthenticationMethodType = 'password' | 'email_token' | 'sso' | 'otp';
|
|
27
40
|
export type SSOProvider = 'google' | 'microsoft' | 'github' | 'okta' | 'apple' | 'facebook';
|
|
28
41
|
export interface AuthenticationAccount {
|
|
@@ -43,11 +56,11 @@ export interface AuthenticationAccount {
|
|
|
43
56
|
export interface PersonInfo {
|
|
44
57
|
id: string;
|
|
45
58
|
name: string;
|
|
46
|
-
email?: string;
|
|
47
|
-
phone?: string;
|
|
48
|
-
roles: string[];
|
|
49
59
|
first_name: string;
|
|
50
60
|
last_name: string;
|
|
61
|
+
email?: string | null;
|
|
62
|
+
phone_number?: string | null;
|
|
63
|
+
roles: string[];
|
|
51
64
|
}
|
|
52
65
|
export interface AuthMethodInfo {
|
|
53
66
|
id: string;
|
|
@@ -65,10 +78,9 @@ export interface AccountInfo {
|
|
|
65
78
|
display_name: string;
|
|
66
79
|
is_active: boolean;
|
|
67
80
|
is_verified: boolean;
|
|
68
|
-
last_login?: string;
|
|
81
|
+
last_login?: string | null;
|
|
69
82
|
authentication_methods: AuthMethodInfo[];
|
|
70
|
-
person?: PersonInfo;
|
|
71
|
-
entity?: EntityInfo;
|
|
83
|
+
person?: PersonInfo | null;
|
|
72
84
|
}
|
|
73
85
|
export interface EntityInfo {
|
|
74
86
|
id: string;
|
|
@@ -85,21 +97,21 @@ export interface SessionInfo {
|
|
|
85
97
|
is_current?: boolean;
|
|
86
98
|
}
|
|
87
99
|
/**
|
|
88
|
-
* Unified user representation
|
|
89
|
-
*
|
|
100
|
+
* Unified user representation
|
|
101
|
+
* All accounts are "identity" accounts that may be linked to a person
|
|
90
102
|
*/
|
|
91
103
|
export interface User {
|
|
92
|
-
/** Unique identifier (person_id
|
|
104
|
+
/** Unique identifier (person_id if linked, otherwise identity_id) */
|
|
93
105
|
id: string;
|
|
94
|
-
/** Account ID */
|
|
106
|
+
/** Identity/Account ID */
|
|
95
107
|
accountId: string;
|
|
96
108
|
/** Display name */
|
|
97
109
|
name: string;
|
|
98
110
|
/** Email address (from person or authentication methods) */
|
|
99
111
|
email?: string;
|
|
100
|
-
/** Account type
|
|
112
|
+
/** Account type (always 'identity') */
|
|
101
113
|
type: AuthenticationAccountType;
|
|
102
|
-
/** User roles (only
|
|
114
|
+
/** User roles (only when linked to person) */
|
|
103
115
|
roles?: string[];
|
|
104
116
|
/** Is the account active */
|
|
105
117
|
isActive: boolean;
|
|
@@ -107,12 +119,10 @@ export interface User {
|
|
|
107
119
|
isVerified: boolean;
|
|
108
120
|
/** Last login timestamp */
|
|
109
121
|
lastLogin?: string;
|
|
110
|
-
/**
|
|
111
|
-
entityType?: string;
|
|
112
|
-
/** Additional metadata */
|
|
113
|
-
metadata?: Record<string, any>;
|
|
114
|
-
/** Person-specific info (only for person accounts) */
|
|
122
|
+
/** Person info (if identity is linked to a person) */
|
|
115
123
|
person?: PersonInfo;
|
|
124
|
+
/** Whether identity is linked to a person */
|
|
125
|
+
hasPersonLinked: boolean;
|
|
116
126
|
}
|
|
117
127
|
export interface RegisterRequest {
|
|
118
128
|
email: string;
|
|
@@ -248,7 +258,9 @@ export type SSOInitiateResponse = AxiosResponse<{
|
|
|
248
258
|
export type SSOCallbackResponse = AxiosResponse<AuthenticationResponse>;
|
|
249
259
|
export type SSOLinkResponse = AxiosResponse<MessageResponse>;
|
|
250
260
|
export type SSOUnlinkResponse = AxiosResponse<MessageResponse>;
|
|
261
|
+
export type GetTenantsResponse = AxiosResponse<TenantInfo[]>;
|
|
251
262
|
/**
|
|
252
263
|
* Extract unified user from account info
|
|
264
|
+
* All accounts are identities that may be linked to a person
|
|
253
265
|
*/
|
|
254
266
|
export declare function accountToUser(account: AccountInfo | null): User | null;
|
package/dist/useAuth.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { App, ObjectPlugin } from 'vue';
|
|
2
|
-
import { AccountInfo, User, NewUser, UpdatePasswordForm, UpdateAccountRequest, AuthEventMap, SSOProvider, SSOInitiateRequest, SSOCallbackRequest, SSOLinkRequest, AuthState } from './types';
|
|
2
|
+
import { AccountInfo, User, NewUser, UpdatePasswordForm, UpdateAccountRequest, AuthEventMap, SSOProvider, SSOInitiateRequest, SSOCallbackRequest, SSOLinkRequest, TenantInfo, AuthState } from './types';
|
|
3
3
|
import { RedirectConfig, NormalizedRedirectConfig } from './types/redirect';
|
|
4
4
|
interface InitParams {
|
|
5
5
|
baseURL: string;
|
|
@@ -37,7 +37,7 @@ export declare function useAuth(): {
|
|
|
37
37
|
display_name: string;
|
|
38
38
|
is_active: boolean;
|
|
39
39
|
is_verified: boolean;
|
|
40
|
-
last_login?: string | undefined;
|
|
40
|
+
last_login?: string | null | undefined;
|
|
41
41
|
authentication_methods: {
|
|
42
42
|
id: string;
|
|
43
43
|
type: string;
|
|
@@ -51,25 +51,19 @@ export declare function useAuth(): {
|
|
|
51
51
|
person?: {
|
|
52
52
|
id: string;
|
|
53
53
|
name: string;
|
|
54
|
-
email?: string | undefined;
|
|
55
|
-
phone?: string | undefined;
|
|
56
|
-
roles: string[];
|
|
57
54
|
first_name: string;
|
|
58
55
|
last_name: string;
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
type?: string | undefined;
|
|
64
|
-
metadata?: Record<string, any> | undefined;
|
|
65
|
-
} | undefined;
|
|
56
|
+
email?: string | null | undefined;
|
|
57
|
+
phone_number?: string | null | undefined;
|
|
58
|
+
roles: string[];
|
|
59
|
+
} | null | undefined;
|
|
66
60
|
} | null, AccountInfo | {
|
|
67
61
|
id: string;
|
|
68
62
|
account_type: string;
|
|
69
63
|
display_name: string;
|
|
70
64
|
is_active: boolean;
|
|
71
65
|
is_verified: boolean;
|
|
72
|
-
last_login?: string | undefined;
|
|
66
|
+
last_login?: string | null | undefined;
|
|
73
67
|
authentication_methods: {
|
|
74
68
|
id: string;
|
|
75
69
|
type: string;
|
|
@@ -83,27 +77,90 @@ export declare function useAuth(): {
|
|
|
83
77
|
person?: {
|
|
84
78
|
id: string;
|
|
85
79
|
name: string;
|
|
86
|
-
email?: string | undefined;
|
|
87
|
-
phone?: string | undefined;
|
|
88
|
-
roles: string[];
|
|
89
80
|
first_name: string;
|
|
90
81
|
last_name: string;
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
type?: string | undefined;
|
|
96
|
-
metadata?: Record<string, any> | undefined;
|
|
97
|
-
} | undefined;
|
|
82
|
+
email?: string | null | undefined;
|
|
83
|
+
phone_number?: string | null | undefined;
|
|
84
|
+
roles: string[];
|
|
85
|
+
} | null | undefined;
|
|
98
86
|
} | null>;
|
|
99
87
|
sso: import('./sso').SSOObject;
|
|
88
|
+
tenants: import('vue').Ref<{
|
|
89
|
+
id: string;
|
|
90
|
+
name: string;
|
|
91
|
+
slug: string;
|
|
92
|
+
parent_id: string | null;
|
|
93
|
+
settings: Record<string, any> | null;
|
|
94
|
+
status: import('./types').TenantStatus;
|
|
95
|
+
suspended_at: string | null;
|
|
96
|
+
suspended_reason: string | null;
|
|
97
|
+
created_at: string;
|
|
98
|
+
updated_at: string;
|
|
99
|
+
}[], TenantInfo[] | {
|
|
100
|
+
id: string;
|
|
101
|
+
name: string;
|
|
102
|
+
slug: string;
|
|
103
|
+
parent_id: string | null;
|
|
104
|
+
settings: Record<string, any> | null;
|
|
105
|
+
status: import('./types').TenantStatus;
|
|
106
|
+
suspended_at: string | null;
|
|
107
|
+
suspended_reason: string | null;
|
|
108
|
+
created_at: string;
|
|
109
|
+
updated_at: string;
|
|
110
|
+
}[]>;
|
|
111
|
+
currentTenant: import('vue').Ref<{
|
|
112
|
+
id: string;
|
|
113
|
+
name: string;
|
|
114
|
+
slug: string;
|
|
115
|
+
parent_id: string | null;
|
|
116
|
+
settings: Record<string, any> | null;
|
|
117
|
+
status: import('./types').TenantStatus;
|
|
118
|
+
suspended_at: string | null;
|
|
119
|
+
suspended_reason: string | null;
|
|
120
|
+
created_at: string;
|
|
121
|
+
updated_at: string;
|
|
122
|
+
} | null, TenantInfo | {
|
|
123
|
+
id: string;
|
|
124
|
+
name: string;
|
|
125
|
+
slug: string;
|
|
126
|
+
parent_id: string | null;
|
|
127
|
+
settings: Record<string, any> | null;
|
|
128
|
+
status: import('./types').TenantStatus;
|
|
129
|
+
suspended_at: string | null;
|
|
130
|
+
suspended_reason: string | null;
|
|
131
|
+
created_at: string;
|
|
132
|
+
updated_at: string;
|
|
133
|
+
} | null>;
|
|
100
134
|
getFullName: () => string;
|
|
101
135
|
getIsLoggedIn: () => boolean;
|
|
102
136
|
getEmail: () => string;
|
|
103
137
|
getRoles: () => string[];
|
|
104
|
-
getAccountType: () =>
|
|
138
|
+
getAccountType: () => string;
|
|
105
139
|
isPersonAccount: () => boolean;
|
|
106
|
-
|
|
140
|
+
getTenants: () => {
|
|
141
|
+
id: string;
|
|
142
|
+
name: string;
|
|
143
|
+
slug: string;
|
|
144
|
+
parent_id: string | null;
|
|
145
|
+
settings: Record<string, any> | null;
|
|
146
|
+
status: import('./types').TenantStatus;
|
|
147
|
+
suspended_at: string | null;
|
|
148
|
+
suspended_reason: string | null;
|
|
149
|
+
created_at: string;
|
|
150
|
+
updated_at: string;
|
|
151
|
+
}[];
|
|
152
|
+
getCurrentTenant: () => {
|
|
153
|
+
id: string;
|
|
154
|
+
name: string;
|
|
155
|
+
slug: string;
|
|
156
|
+
parent_id: string | null;
|
|
157
|
+
settings: Record<string, any> | null;
|
|
158
|
+
status: import('./types').TenantStatus;
|
|
159
|
+
suspended_at: string | null;
|
|
160
|
+
suspended_reason: string | null;
|
|
161
|
+
created_at: string;
|
|
162
|
+
updated_at: string;
|
|
163
|
+
} | null;
|
|
107
164
|
login: (credentials: {
|
|
108
165
|
email: string;
|
|
109
166
|
password: string;
|
|
@@ -130,5 +187,8 @@ export declare function useAuth(): {
|
|
|
130
187
|
getSessions: (accountId?: string) => Promise<import('./types').GetSessionsResponse>;
|
|
131
188
|
revokeSession: (sessionToken: string) => Promise<void>;
|
|
132
189
|
revokeAllSessions: (accountId?: string) => Promise<void>;
|
|
190
|
+
loadTenants: () => Promise<TenantInfo[]>;
|
|
191
|
+
setTenant: (tenantId: string | null) => void;
|
|
192
|
+
switchTenant: (tenantId: string) => void;
|
|
133
193
|
};
|
|
134
194
|
export {};
|