@bagelink/auth 1.4.171 → 1.4.176

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.d.cts CHANGED
@@ -65,6 +65,13 @@ interface AccountInfo {
65
65
  last_login?: string;
66
66
  authentication_methods: AuthMethodInfo[];
67
67
  person?: PersonInfo;
68
+ entity?: EntityInfo;
69
+ }
70
+ interface EntityInfo {
71
+ id: string;
72
+ name: string;
73
+ type?: string;
74
+ metadata?: Record<string, any>;
68
75
  }
69
76
  interface SessionInfo {
70
77
  id: string;
@@ -74,6 +81,34 @@ interface SessionInfo {
74
81
  user_agent?: string;
75
82
  is_current?: boolean;
76
83
  }
84
+ /**
85
+ * Unified user representation that works for both person and entity accounts
86
+ * This is the primary interface for accessing user data in the application
87
+ */
88
+ interface User {
89
+ /** Unique identifier (person_id or entity_id) */
90
+ id: string;
91
+ /** Account ID */
92
+ accountId: string;
93
+ /** Display name */
94
+ name: string;
95
+ /** Email address (from person or authentication methods) */
96
+ email?: string;
97
+ /** Account type: 'person', 'entity', or 'service' */
98
+ type: AuthenticationAccountType;
99
+ /** User roles (only for person accounts) */
100
+ roles?: string[];
101
+ /** Is the account active */
102
+ isActive: boolean;
103
+ /** Is the account verified */
104
+ isVerified: boolean;
105
+ /** Last login timestamp */
106
+ lastLogin?: string;
107
+ /** Entity-specific info (only for entity accounts) */
108
+ entityType?: string;
109
+ /** Additional metadata */
110
+ metadata?: Record<string, any>;
111
+ }
77
112
  interface RegisterRequest {
78
113
  email: string;
79
114
  first_name: string;
@@ -180,14 +215,10 @@ type DeleteSessionResponse = AxiosResponse<MessageResponse>;
180
215
  type DeleteAllSessionsResponse = AxiosResponse<MessageResponse>;
181
216
  type CleanupSessionsResponse = AxiosResponse<MessageResponse>;
182
217
  type GetMethodsResponse = AxiosResponse<AvailableMethodsResponse>;
183
- /** @deprecated Use AccountInfo instead */
184
- type User = AccountInfo & {
185
- email: string;
186
- first_name?: string;
187
- last_name?: string;
188
- is_superuser?: boolean;
189
- is_active?: boolean;
190
- };
218
+ /**
219
+ * Extract unified user from account info
220
+ */
221
+ declare function accountToUser(account: AccountInfo | null): User | null;
191
222
 
192
223
  declare class AuthApi {
193
224
  private api;
@@ -297,7 +328,8 @@ declare function initAuth({ axios, baseURL, }: {
297
328
  install(app: App): void;
298
329
  };
299
330
  declare function useAuth(): {
300
- currentUser: vue.Ref<{
331
+ user: vue.ComputedRef<User | null>;
332
+ accountInfo: vue.Ref<{
301
333
  id: string;
302
334
  account_type: string;
303
335
  display_name: string;
@@ -318,6 +350,12 @@ declare function useAuth(): {
318
350
  email?: string | undefined;
319
351
  roles: string[];
320
352
  } | undefined;
353
+ entity?: {
354
+ id: string;
355
+ name: string;
356
+ type?: string | undefined;
357
+ metadata?: Record<string, any> | undefined;
358
+ } | undefined;
321
359
  } | null, AccountInfo | {
322
360
  id: string;
323
361
  account_type: string;
@@ -339,16 +377,26 @@ declare function useAuth(): {
339
377
  email?: string | undefined;
340
378
  roles: string[];
341
379
  } | undefined;
380
+ entity?: {
381
+ id: string;
382
+ name: string;
383
+ type?: string | undefined;
384
+ metadata?: Record<string, any> | undefined;
385
+ } | undefined;
342
386
  } | null>;
343
387
  getFullName: () => string;
344
388
  getIsLoggedIn: () => boolean;
345
389
  getEmail: () => string;
390
+ getRoles: () => string[];
391
+ getAccountType: () => AuthenticationAccountType;
392
+ isPersonAccount: () => boolean;
393
+ isEntityAccount: () => boolean;
346
394
  login: (credentials: {
347
395
  email: string;
348
396
  password: string;
349
397
  }) => Promise<AuthenticationResponse>;
350
398
  logout: () => Promise<void>;
351
- signup: (user: NewUser) => Promise<AuthenticationResponse>;
399
+ signup: (newUser: NewUser) => Promise<AuthenticationResponse>;
352
400
  checkAuth: () => Promise<boolean>;
353
401
  refreshSession: () => Promise<void>;
354
402
  updateProfile: (updates: UpdateAccountRequest) => Promise<void>;
@@ -367,5 +415,5 @@ declare function useAuth(): {
367
415
  revokeAllSessions: (accountId?: string) => Promise<void>;
368
416
  };
369
417
 
370
- export { AuthApi, AuthState, initAuth, useAuth };
371
- export type { AccountInfo, ActivateAccountResponse, AuthEventHandler, AuthEventMap, AuthMethodInfo, AuthStatusResponse, AuthenticationAccount, AuthenticationAccountType, AuthenticationMethodType, AuthenticationResponse, AvailableMethodsResponse, ChangePasswordRequest, ChangePasswordResponse, CleanupSessionsResponse, DeactivateAccountResponse, DeleteAccountResponse, DeleteAllSessionsResponse, DeleteMeResponse, DeleteSessionResponse, ForgotPasswordRequest, ForgotPasswordResponse, GetAccountResponse, GetMeResponse, GetMethodsResponse, GetSessionsResponse, LoginResponse, LogoutResponse, MessageResponse, NewUser, OTPMetadata, PasswordLoginRequest, PersonInfo, RefreshSessionResponse, RegisterRequest, RegisterResponse, ResetPasswordRequest, ResetPasswordResponse, SSOMetadata, SendVerificationRequest, SendVerificationResponse, SessionInfo, SessionListResponse, UpdateAccountRequest, UpdateAccountResponse, UpdateMeResponse, UpdatePasswordForm, User, VerifyEmailRequest, VerifyEmailResponse, VerifyResetTokenResponse };
418
+ export { AuthApi, AuthState, accountToUser, initAuth, useAuth };
419
+ export type { AccountInfo, ActivateAccountResponse, AuthEventHandler, AuthEventMap, AuthMethodInfo, AuthStatusResponse, AuthenticationAccount, AuthenticationAccountType, AuthenticationMethodType, AuthenticationResponse, AvailableMethodsResponse, ChangePasswordRequest, ChangePasswordResponse, CleanupSessionsResponse, DeactivateAccountResponse, DeleteAccountResponse, DeleteAllSessionsResponse, DeleteMeResponse, DeleteSessionResponse, EntityInfo, ForgotPasswordRequest, ForgotPasswordResponse, GetAccountResponse, GetMeResponse, GetMethodsResponse, GetSessionsResponse, LoginResponse, LogoutResponse, MessageResponse, NewUser, OTPMetadata, PasswordLoginRequest, PersonInfo, RefreshSessionResponse, RegisterRequest, RegisterResponse, ResetPasswordRequest, ResetPasswordResponse, SSOMetadata, SendVerificationRequest, SendVerificationResponse, SessionInfo, SessionListResponse, UpdateAccountRequest, UpdateAccountResponse, UpdateMeResponse, UpdatePasswordForm, User, VerifyEmailRequest, VerifyEmailResponse, VerifyResetTokenResponse };
package/dist/index.d.mts CHANGED
@@ -65,6 +65,13 @@ interface AccountInfo {
65
65
  last_login?: string;
66
66
  authentication_methods: AuthMethodInfo[];
67
67
  person?: PersonInfo;
68
+ entity?: EntityInfo;
69
+ }
70
+ interface EntityInfo {
71
+ id: string;
72
+ name: string;
73
+ type?: string;
74
+ metadata?: Record<string, any>;
68
75
  }
69
76
  interface SessionInfo {
70
77
  id: string;
@@ -74,6 +81,34 @@ interface SessionInfo {
74
81
  user_agent?: string;
75
82
  is_current?: boolean;
76
83
  }
84
+ /**
85
+ * Unified user representation that works for both person and entity accounts
86
+ * This is the primary interface for accessing user data in the application
87
+ */
88
+ interface User {
89
+ /** Unique identifier (person_id or entity_id) */
90
+ id: string;
91
+ /** Account ID */
92
+ accountId: string;
93
+ /** Display name */
94
+ name: string;
95
+ /** Email address (from person or authentication methods) */
96
+ email?: string;
97
+ /** Account type: 'person', 'entity', or 'service' */
98
+ type: AuthenticationAccountType;
99
+ /** User roles (only for person accounts) */
100
+ roles?: string[];
101
+ /** Is the account active */
102
+ isActive: boolean;
103
+ /** Is the account verified */
104
+ isVerified: boolean;
105
+ /** Last login timestamp */
106
+ lastLogin?: string;
107
+ /** Entity-specific info (only for entity accounts) */
108
+ entityType?: string;
109
+ /** Additional metadata */
110
+ metadata?: Record<string, any>;
111
+ }
77
112
  interface RegisterRequest {
78
113
  email: string;
79
114
  first_name: string;
@@ -180,14 +215,10 @@ type DeleteSessionResponse = AxiosResponse<MessageResponse>;
180
215
  type DeleteAllSessionsResponse = AxiosResponse<MessageResponse>;
181
216
  type CleanupSessionsResponse = AxiosResponse<MessageResponse>;
182
217
  type GetMethodsResponse = AxiosResponse<AvailableMethodsResponse>;
183
- /** @deprecated Use AccountInfo instead */
184
- type User = AccountInfo & {
185
- email: string;
186
- first_name?: string;
187
- last_name?: string;
188
- is_superuser?: boolean;
189
- is_active?: boolean;
190
- };
218
+ /**
219
+ * Extract unified user from account info
220
+ */
221
+ declare function accountToUser(account: AccountInfo | null): User | null;
191
222
 
192
223
  declare class AuthApi {
193
224
  private api;
@@ -297,7 +328,8 @@ declare function initAuth({ axios, baseURL, }: {
297
328
  install(app: App): void;
298
329
  };
299
330
  declare function useAuth(): {
300
- currentUser: vue.Ref<{
331
+ user: vue.ComputedRef<User | null>;
332
+ accountInfo: vue.Ref<{
301
333
  id: string;
302
334
  account_type: string;
303
335
  display_name: string;
@@ -318,6 +350,12 @@ declare function useAuth(): {
318
350
  email?: string | undefined;
319
351
  roles: string[];
320
352
  } | undefined;
353
+ entity?: {
354
+ id: string;
355
+ name: string;
356
+ type?: string | undefined;
357
+ metadata?: Record<string, any> | undefined;
358
+ } | undefined;
321
359
  } | null, AccountInfo | {
322
360
  id: string;
323
361
  account_type: string;
@@ -339,16 +377,26 @@ declare function useAuth(): {
339
377
  email?: string | undefined;
340
378
  roles: string[];
341
379
  } | undefined;
380
+ entity?: {
381
+ id: string;
382
+ name: string;
383
+ type?: string | undefined;
384
+ metadata?: Record<string, any> | undefined;
385
+ } | undefined;
342
386
  } | null>;
343
387
  getFullName: () => string;
344
388
  getIsLoggedIn: () => boolean;
345
389
  getEmail: () => string;
390
+ getRoles: () => string[];
391
+ getAccountType: () => AuthenticationAccountType;
392
+ isPersonAccount: () => boolean;
393
+ isEntityAccount: () => boolean;
346
394
  login: (credentials: {
347
395
  email: string;
348
396
  password: string;
349
397
  }) => Promise<AuthenticationResponse>;
350
398
  logout: () => Promise<void>;
351
- signup: (user: NewUser) => Promise<AuthenticationResponse>;
399
+ signup: (newUser: NewUser) => Promise<AuthenticationResponse>;
352
400
  checkAuth: () => Promise<boolean>;
353
401
  refreshSession: () => Promise<void>;
354
402
  updateProfile: (updates: UpdateAccountRequest) => Promise<void>;
@@ -367,5 +415,5 @@ declare function useAuth(): {
367
415
  revokeAllSessions: (accountId?: string) => Promise<void>;
368
416
  };
369
417
 
370
- export { AuthApi, AuthState, initAuth, useAuth };
371
- export type { AccountInfo, ActivateAccountResponse, AuthEventHandler, AuthEventMap, AuthMethodInfo, AuthStatusResponse, AuthenticationAccount, AuthenticationAccountType, AuthenticationMethodType, AuthenticationResponse, AvailableMethodsResponse, ChangePasswordRequest, ChangePasswordResponse, CleanupSessionsResponse, DeactivateAccountResponse, DeleteAccountResponse, DeleteAllSessionsResponse, DeleteMeResponse, DeleteSessionResponse, ForgotPasswordRequest, ForgotPasswordResponse, GetAccountResponse, GetMeResponse, GetMethodsResponse, GetSessionsResponse, LoginResponse, LogoutResponse, MessageResponse, NewUser, OTPMetadata, PasswordLoginRequest, PersonInfo, RefreshSessionResponse, RegisterRequest, RegisterResponse, ResetPasswordRequest, ResetPasswordResponse, SSOMetadata, SendVerificationRequest, SendVerificationResponse, SessionInfo, SessionListResponse, UpdateAccountRequest, UpdateAccountResponse, UpdateMeResponse, UpdatePasswordForm, User, VerifyEmailRequest, VerifyEmailResponse, VerifyResetTokenResponse };
418
+ export { AuthApi, AuthState, accountToUser, initAuth, useAuth };
419
+ export type { AccountInfo, ActivateAccountResponse, AuthEventHandler, AuthEventMap, AuthMethodInfo, AuthStatusResponse, AuthenticationAccount, AuthenticationAccountType, AuthenticationMethodType, AuthenticationResponse, AvailableMethodsResponse, ChangePasswordRequest, ChangePasswordResponse, CleanupSessionsResponse, DeactivateAccountResponse, DeleteAccountResponse, DeleteAllSessionsResponse, DeleteMeResponse, DeleteSessionResponse, EntityInfo, ForgotPasswordRequest, ForgotPasswordResponse, GetAccountResponse, GetMeResponse, GetMethodsResponse, GetSessionsResponse, LoginResponse, LogoutResponse, MessageResponse, NewUser, OTPMetadata, PasswordLoginRequest, PersonInfo, RefreshSessionResponse, RegisterRequest, RegisterResponse, ResetPasswordRequest, ResetPasswordResponse, SSOMetadata, SendVerificationRequest, SendVerificationResponse, SessionInfo, SessionListResponse, UpdateAccountRequest, UpdateAccountResponse, UpdateMeResponse, UpdatePasswordForm, User, VerifyEmailRequest, VerifyEmailResponse, VerifyResetTokenResponse };
package/dist/index.d.ts CHANGED
@@ -65,6 +65,13 @@ interface AccountInfo {
65
65
  last_login?: string;
66
66
  authentication_methods: AuthMethodInfo[];
67
67
  person?: PersonInfo;
68
+ entity?: EntityInfo;
69
+ }
70
+ interface EntityInfo {
71
+ id: string;
72
+ name: string;
73
+ type?: string;
74
+ metadata?: Record<string, any>;
68
75
  }
69
76
  interface SessionInfo {
70
77
  id: string;
@@ -74,6 +81,34 @@ interface SessionInfo {
74
81
  user_agent?: string;
75
82
  is_current?: boolean;
76
83
  }
84
+ /**
85
+ * Unified user representation that works for both person and entity accounts
86
+ * This is the primary interface for accessing user data in the application
87
+ */
88
+ interface User {
89
+ /** Unique identifier (person_id or entity_id) */
90
+ id: string;
91
+ /** Account ID */
92
+ accountId: string;
93
+ /** Display name */
94
+ name: string;
95
+ /** Email address (from person or authentication methods) */
96
+ email?: string;
97
+ /** Account type: 'person', 'entity', or 'service' */
98
+ type: AuthenticationAccountType;
99
+ /** User roles (only for person accounts) */
100
+ roles?: string[];
101
+ /** Is the account active */
102
+ isActive: boolean;
103
+ /** Is the account verified */
104
+ isVerified: boolean;
105
+ /** Last login timestamp */
106
+ lastLogin?: string;
107
+ /** Entity-specific info (only for entity accounts) */
108
+ entityType?: string;
109
+ /** Additional metadata */
110
+ metadata?: Record<string, any>;
111
+ }
77
112
  interface RegisterRequest {
78
113
  email: string;
79
114
  first_name: string;
@@ -180,14 +215,10 @@ type DeleteSessionResponse = AxiosResponse<MessageResponse>;
180
215
  type DeleteAllSessionsResponse = AxiosResponse<MessageResponse>;
181
216
  type CleanupSessionsResponse = AxiosResponse<MessageResponse>;
182
217
  type GetMethodsResponse = AxiosResponse<AvailableMethodsResponse>;
183
- /** @deprecated Use AccountInfo instead */
184
- type User = AccountInfo & {
185
- email: string;
186
- first_name?: string;
187
- last_name?: string;
188
- is_superuser?: boolean;
189
- is_active?: boolean;
190
- };
218
+ /**
219
+ * Extract unified user from account info
220
+ */
221
+ declare function accountToUser(account: AccountInfo | null): User | null;
191
222
 
192
223
  declare class AuthApi {
193
224
  private api;
@@ -297,7 +328,8 @@ declare function initAuth({ axios, baseURL, }: {
297
328
  install(app: App): void;
298
329
  };
299
330
  declare function useAuth(): {
300
- currentUser: vue.Ref<{
331
+ user: vue.ComputedRef<User | null>;
332
+ accountInfo: vue.Ref<{
301
333
  id: string;
302
334
  account_type: string;
303
335
  display_name: string;
@@ -318,6 +350,12 @@ declare function useAuth(): {
318
350
  email?: string | undefined;
319
351
  roles: string[];
320
352
  } | undefined;
353
+ entity?: {
354
+ id: string;
355
+ name: string;
356
+ type?: string | undefined;
357
+ metadata?: Record<string, any> | undefined;
358
+ } | undefined;
321
359
  } | null, AccountInfo | {
322
360
  id: string;
323
361
  account_type: string;
@@ -339,16 +377,26 @@ declare function useAuth(): {
339
377
  email?: string | undefined;
340
378
  roles: string[];
341
379
  } | undefined;
380
+ entity?: {
381
+ id: string;
382
+ name: string;
383
+ type?: string | undefined;
384
+ metadata?: Record<string, any> | undefined;
385
+ } | undefined;
342
386
  } | null>;
343
387
  getFullName: () => string;
344
388
  getIsLoggedIn: () => boolean;
345
389
  getEmail: () => string;
390
+ getRoles: () => string[];
391
+ getAccountType: () => AuthenticationAccountType;
392
+ isPersonAccount: () => boolean;
393
+ isEntityAccount: () => boolean;
346
394
  login: (credentials: {
347
395
  email: string;
348
396
  password: string;
349
397
  }) => Promise<AuthenticationResponse>;
350
398
  logout: () => Promise<void>;
351
- signup: (user: NewUser) => Promise<AuthenticationResponse>;
399
+ signup: (newUser: NewUser) => Promise<AuthenticationResponse>;
352
400
  checkAuth: () => Promise<boolean>;
353
401
  refreshSession: () => Promise<void>;
354
402
  updateProfile: (updates: UpdateAccountRequest) => Promise<void>;
@@ -367,5 +415,5 @@ declare function useAuth(): {
367
415
  revokeAllSessions: (accountId?: string) => Promise<void>;
368
416
  };
369
417
 
370
- export { AuthApi, AuthState, initAuth, useAuth };
371
- export type { AccountInfo, ActivateAccountResponse, AuthEventHandler, AuthEventMap, AuthMethodInfo, AuthStatusResponse, AuthenticationAccount, AuthenticationAccountType, AuthenticationMethodType, AuthenticationResponse, AvailableMethodsResponse, ChangePasswordRequest, ChangePasswordResponse, CleanupSessionsResponse, DeactivateAccountResponse, DeleteAccountResponse, DeleteAllSessionsResponse, DeleteMeResponse, DeleteSessionResponse, ForgotPasswordRequest, ForgotPasswordResponse, GetAccountResponse, GetMeResponse, GetMethodsResponse, GetSessionsResponse, LoginResponse, LogoutResponse, MessageResponse, NewUser, OTPMetadata, PasswordLoginRequest, PersonInfo, RefreshSessionResponse, RegisterRequest, RegisterResponse, ResetPasswordRequest, ResetPasswordResponse, SSOMetadata, SendVerificationRequest, SendVerificationResponse, SessionInfo, SessionListResponse, UpdateAccountRequest, UpdateAccountResponse, UpdateMeResponse, UpdatePasswordForm, User, VerifyEmailRequest, VerifyEmailResponse, VerifyResetTokenResponse };
418
+ export { AuthApi, AuthState, accountToUser, initAuth, useAuth };
419
+ export type { AccountInfo, ActivateAccountResponse, AuthEventHandler, AuthEventMap, AuthMethodInfo, AuthStatusResponse, AuthenticationAccount, AuthenticationAccountType, AuthenticationMethodType, AuthenticationResponse, AvailableMethodsResponse, ChangePasswordRequest, ChangePasswordResponse, CleanupSessionsResponse, DeactivateAccountResponse, DeleteAccountResponse, DeleteAllSessionsResponse, DeleteMeResponse, DeleteSessionResponse, EntityInfo, ForgotPasswordRequest, ForgotPasswordResponse, GetAccountResponse, GetMeResponse, GetMethodsResponse, GetSessionsResponse, LoginResponse, LogoutResponse, MessageResponse, NewUser, OTPMetadata, PasswordLoginRequest, PersonInfo, RefreshSessionResponse, RegisterRequest, RegisterResponse, ResetPasswordRequest, ResetPasswordResponse, SSOMetadata, SendVerificationRequest, SendVerificationResponse, SessionInfo, SessionListResponse, UpdateAccountRequest, UpdateAccountResponse, UpdateMeResponse, UpdatePasswordForm, User, VerifyEmailRequest, VerifyEmailResponse, VerifyResetTokenResponse };
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import axios from 'axios';
2
- import { ref } from 'vue';
2
+ import { computed, ref } from 'vue';
3
3
 
4
4
  function createAxiosInstance(baseURL = "") {
5
5
  return axios.create({
@@ -257,10 +257,52 @@ var AuthState = /* @__PURE__ */ ((AuthState2) => {
257
257
  AuthState2["SESSION_REFRESH"] = "session_refresh";
258
258
  return AuthState2;
259
259
  })(AuthState || {});
260
+ function accountToUser(account) {
261
+ if (account === null) return null;
262
+ if (account.person !== void 0) {
263
+ return {
264
+ id: account.person.id,
265
+ accountId: account.id,
266
+ name: account.person.name,
267
+ email: account.person.email,
268
+ type: account.account_type,
269
+ roles: account.person.roles,
270
+ isActive: account.is_active,
271
+ isVerified: account.is_verified,
272
+ lastLogin: account.last_login
273
+ };
274
+ }
275
+ if (account.entity !== void 0) {
276
+ return {
277
+ id: account.entity.id,
278
+ accountId: account.id,
279
+ name: account.entity.name,
280
+ type: account.account_type,
281
+ isActive: account.is_active,
282
+ isVerified: account.is_verified,
283
+ lastLogin: account.last_login,
284
+ entityType: account.entity.type,
285
+ metadata: account.entity.metadata
286
+ };
287
+ }
288
+ const emailMethod = account.authentication_methods?.find(
289
+ (m) => m.type === "password" || m.type === "email_token"
290
+ );
291
+ return {
292
+ id: account.id,
293
+ accountId: account.id,
294
+ name: account.display_name,
295
+ email: emailMethod?.identifier,
296
+ type: account.account_type,
297
+ isActive: account.is_active,
298
+ isVerified: account.is_verified,
299
+ lastLogin: account.last_login
300
+ };
301
+ }
260
302
 
261
303
  let authApi = null;
262
304
  let eventEmitter = null;
263
- const currentUser = ref(null);
305
+ const accountInfo = ref(null);
264
306
  function initAuth({
265
307
  axios,
266
308
  baseURL
@@ -302,32 +344,33 @@ function useAuth() {
302
344
  }
303
345
  const api = authApi;
304
346
  const emitter = eventEmitter;
347
+ const user = computed(() => accountToUser(accountInfo.value));
305
348
  const getFullName = () => {
306
- const user = currentUser.value;
307
- if (user === null) return "";
308
- if (user.person !== void 0) return user.person.name;
309
- return user.display_name ?? "";
349
+ return user.value?.name ?? "";
310
350
  };
311
351
  const getIsLoggedIn = () => {
312
- const user = currentUser.value;
313
- return user !== null && user.id.length > 0;
352
+ return user.value !== null;
314
353
  };
315
354
  const getEmail = () => {
316
- const user = currentUser.value;
317
- if (user === null) return "";
318
- if (user.person?.email !== void 0) {
319
- return user.person.email;
320
- }
321
- const emailMethod = user.authentication_methods?.find(
322
- (m) => m.type === "password" || m.type === "email_token"
323
- );
324
- return emailMethod?.identifier ?? "";
355
+ return user.value?.email ?? "";
356
+ };
357
+ const getRoles = () => {
358
+ return user.value?.roles ?? [];
359
+ };
360
+ const getAccountType = () => {
361
+ return user.value?.type ?? "person";
362
+ };
363
+ const isPersonAccount = () => {
364
+ return user.value?.type === "person";
365
+ };
366
+ const isEntityAccount = () => {
367
+ return user.value?.type === "entity";
325
368
  };
326
369
  async function logout() {
327
370
  const logoutPromise = api.logout();
328
371
  await logoutPromise.catch(() => {
329
372
  });
330
- currentUser.value = null;
373
+ accountInfo.value = null;
331
374
  emitter.emit(AuthState.LOGOUT);
332
375
  }
333
376
  async function login(credentials) {
@@ -344,26 +387,27 @@ function useAuth() {
344
387
  async function checkAuth() {
345
388
  try {
346
389
  const { data } = await api.getCurrentUser();
347
- currentUser.value = data;
390
+ accountInfo.value = data;
348
391
  if (getIsLoggedIn()) {
349
392
  emitter.emit(AuthState.AUTH_CHECK);
350
393
  }
351
394
  return true;
352
395
  } catch {
353
- currentUser.value = null;
396
+ accountInfo.value = null;
354
397
  return false;
355
398
  }
356
399
  }
357
- async function signup(user) {
358
- if (user.password && user.password !== user.confirmPassword) {
400
+ async function signup(newUser) {
401
+ const hasPassword = newUser.password !== void 0 && newUser.password.length > 0;
402
+ if (hasPassword && newUser.password !== newUser.confirmPassword) {
359
403
  throw new Error("Passwords do not match");
360
404
  }
361
405
  const { data } = await api.register({
362
- email: user.email,
363
- first_name: user.first_name,
364
- last_name: user.last_name,
365
- phone_number: user.phone_number,
366
- password: user.password
406
+ email: newUser.email,
407
+ first_name: newUser.first_name,
408
+ last_name: newUser.last_name,
409
+ phone_number: newUser.phone_number,
410
+ password: newUser.password
367
411
  });
368
412
  if (data.success === true && data.requires_verification !== true) {
369
413
  await checkAuth();
@@ -393,7 +437,7 @@ function useAuth() {
393
437
  }
394
438
  async function updateProfile(updates) {
395
439
  const { data } = await api.updateCurrentUser(updates);
396
- currentUser.value = data;
440
+ accountInfo.value = data;
397
441
  emitter.emit(AuthState.PROFILE_UPDATE);
398
442
  }
399
443
  async function activateAccount(accountId) {
@@ -407,7 +451,7 @@ function useAuth() {
407
451
  }
408
452
  async function deleteCurrentUser() {
409
453
  await api.deleteCurrentUser();
410
- currentUser.value = null;
454
+ accountInfo.value = null;
411
455
  }
412
456
  async function sendVerification(email) {
413
457
  await api.sendVerification({ email });
@@ -422,7 +466,7 @@ function useAuth() {
422
466
  emitter.emit(AuthState.SESSION_REFRESH);
423
467
  }
424
468
  async function getSessions(accountId) {
425
- const id = accountId ?? currentUser.value?.id;
469
+ const id = accountId ?? user.value?.accountId;
426
470
  if (id === void 0 || id === "") {
427
471
  throw new Error("No account ID available");
428
472
  }
@@ -432,19 +476,25 @@ function useAuth() {
432
476
  await api.revokeSession(sessionToken);
433
477
  }
434
478
  async function revokeAllSessions(accountId) {
435
- const id = accountId ?? currentUser.value?.id;
479
+ const id = accountId ?? user.value?.accountId;
436
480
  if (id === void 0 || id === "") {
437
481
  throw new Error("No account ID available");
438
482
  }
439
483
  await api.revokeAllSessions(id);
440
484
  }
441
485
  return {
442
- // State
443
- currentUser,
486
+ // Primary State (use this!)
487
+ user,
488
+ // Full account info (for advanced use cases)
489
+ accountInfo,
444
490
  // Getters
445
491
  getFullName,
446
492
  getIsLoggedIn,
447
493
  getEmail,
494
+ getRoles,
495
+ getAccountType,
496
+ isPersonAccount,
497
+ isEntityAccount,
448
498
  // Authentication Actions
449
499
  login,
450
500
  logout,
@@ -473,4 +523,4 @@ function useAuth() {
473
523
  };
474
524
  }
475
525
 
476
- export { AuthApi, AuthState, initAuth, useAuth };
526
+ export { AuthApi, AuthState, accountToUser, initAuth, useAuth };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bagelink/auth",
3
3
  "type": "module",
4
- "version": "1.4.171",
4
+ "version": "1.4.176",
5
5
  "description": "Bagelink auth package",
6
6
  "author": {
7
7
  "name": "Bagel Studio",