@blackcode_sa/metaestetics-api 1.14.6 → 1.14.8

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.mts CHANGED
@@ -8321,6 +8321,16 @@ declare class AuthService extends BaseService {
8321
8321
  private googleProvider;
8322
8322
  private userService;
8323
8323
  constructor(db: Firestore, auth: Auth, app: FirebaseApp, userService: UserService);
8324
+ /**
8325
+ * Waits for Firebase Auth state to settle after sign-in.
8326
+ * In React Native with Firebase JS SDK, auth.currentUser doesn't update synchronously
8327
+ * after signInWithCredential. This causes Firestore permission issues.
8328
+ *
8329
+ * @param expectedUid - The UID we expect to see in auth.currentUser
8330
+ * @param timeoutMs - Maximum time to wait (default 10 seconds)
8331
+ * @returns Promise that resolves when auth state is ready
8332
+ */
8333
+ private waitForAuthState;
8324
8334
  /**
8325
8335
  * Registruje novog korisnika sa email-om i lozinkom
8326
8336
  */
package/dist/index.d.ts CHANGED
@@ -8321,6 +8321,16 @@ declare class AuthService extends BaseService {
8321
8321
  private googleProvider;
8322
8322
  private userService;
8323
8323
  constructor(db: Firestore, auth: Auth, app: FirebaseApp, userService: UserService);
8324
+ /**
8325
+ * Waits for Firebase Auth state to settle after sign-in.
8326
+ * In React Native with Firebase JS SDK, auth.currentUser doesn't update synchronously
8327
+ * after signInWithCredential. This causes Firestore permission issues.
8328
+ *
8329
+ * @param expectedUid - The UID we expect to see in auth.currentUser
8330
+ * @param timeoutMs - Maximum time to wait (default 10 seconds)
8331
+ * @returns Promise that resolves when auth state is ready
8332
+ */
8333
+ private waitForAuthState;
8324
8334
  /**
8325
8335
  * Registruje novog korisnika sa email-om i lozinkom
8326
8336
  */
package/dist/index.js CHANGED
@@ -12906,12 +12906,13 @@ var UserService = class extends BaseService {
12906
12906
  * Kreira novog korisnika na osnovu Firebase korisnika
12907
12907
  */
12908
12908
  async createUser(firebaseUser, roles = ["patient" /* PATIENT */], options) {
12909
- var _a, _b, _c, _d, _e, _f, _g, _h;
12909
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
12910
12910
  console.log("[USER_SERVICE] ====== CREATE USER DEBUG ======");
12911
+ console.log("[USER_SERVICE] Auth instance ID:", ((_a = this.auth) == null ? void 0 : _a.__debugId) || "no-id");
12911
12912
  console.log("[USER_SERVICE] Current auth state:", {
12912
- currentUser: ((_b = (_a = this.auth) == null ? void 0 : _a.currentUser) == null ? void 0 : _b.uid) || "NULL",
12913
- currentUserEmail: ((_d = (_c = this.auth) == null ? void 0 : _c.currentUser) == null ? void 0 : _d.email) || "NULL",
12914
- currentUserProvider: ((_f = (_e = this.auth) == null ? void 0 : _e.currentUser) == null ? void 0 : _f.providerId) || "NULL"
12913
+ currentUser: ((_c = (_b = this.auth) == null ? void 0 : _b.currentUser) == null ? void 0 : _c.uid) || "NULL",
12914
+ currentUserEmail: ((_e = (_d = this.auth) == null ? void 0 : _d.currentUser) == null ? void 0 : _e.email) || "NULL",
12915
+ currentUserProvider: ((_g = (_f = this.auth) == null ? void 0 : _f.currentUser) == null ? void 0 : _g.providerId) || "NULL"
12915
12916
  });
12916
12917
  console.log("[USER_SERVICE] Firebase user passed to createUser:", {
12917
12918
  uid: (firebaseUser == null ? void 0 : firebaseUser.uid) || "NULL",
@@ -12919,7 +12920,7 @@ var UserService = class extends BaseService {
12919
12920
  providerId: (firebaseUser == null ? void 0 : firebaseUser.providerId) || "NULL",
12920
12921
  isAnonymous: firebaseUser == null ? void 0 : firebaseUser.isAnonymous
12921
12922
  });
12922
- console.log("[USER_SERVICE] Auth instances match:", ((_h = (_g = this.auth) == null ? void 0 : _g.currentUser) == null ? void 0 : _h.uid) === (firebaseUser == null ? void 0 : firebaseUser.uid));
12923
+ console.log("[USER_SERVICE] Auth instances match:", ((_i = (_h = this.auth) == null ? void 0 : _h.currentUser) == null ? void 0 : _i.uid) === (firebaseUser == null ? void 0 : firebaseUser.uid));
12923
12924
  console.log("[USER_SERVICE] Document path:", `${USERS_COLLECTION}/${firebaseUser == null ? void 0 : firebaseUser.uid}`);
12924
12925
  console.log("[USER_SERVICE] Roles:", roles);
12925
12926
  console.log("[USER_SERVICE] ================================");
@@ -15381,6 +15382,40 @@ var AuthService = class extends BaseService {
15381
15382
  this.googleProvider = new import_auth8.GoogleAuthProvider();
15382
15383
  this.userService = userService || new UserService(db, auth, app);
15383
15384
  }
15385
+ /**
15386
+ * Waits for Firebase Auth state to settle after sign-in.
15387
+ * In React Native with Firebase JS SDK, auth.currentUser doesn't update synchronously
15388
+ * after signInWithCredential. This causes Firestore permission issues.
15389
+ *
15390
+ * @param expectedUid - The UID we expect to see in auth.currentUser
15391
+ * @param timeoutMs - Maximum time to wait (default 10 seconds)
15392
+ * @returns Promise that resolves when auth state is ready
15393
+ */
15394
+ waitForAuthState(expectedUid, timeoutMs = 1e4) {
15395
+ return new Promise((resolve, reject) => {
15396
+ var _a;
15397
+ if (((_a = this.auth.currentUser) == null ? void 0 : _a.uid) === expectedUid) {
15398
+ console.log("[AUTH] Auth state already settled for:", expectedUid);
15399
+ resolve();
15400
+ return;
15401
+ }
15402
+ console.log("[AUTH] Waiting for auth state to settle for:", expectedUid);
15403
+ const timeout = setTimeout(() => {
15404
+ unsubscribe();
15405
+ console.error("[AUTH] Timeout waiting for auth state");
15406
+ reject(new Error("Timeout waiting for auth state to settle"));
15407
+ }, timeoutMs);
15408
+ const unsubscribe = (0, import_auth8.onAuthStateChanged)(this.auth, (user) => {
15409
+ console.log("[AUTH] Auth state changed:", (user == null ? void 0 : user.uid) || "null");
15410
+ if ((user == null ? void 0 : user.uid) === expectedUid) {
15411
+ clearTimeout(timeout);
15412
+ unsubscribe();
15413
+ console.log("[AUTH] Auth state settled successfully for:", expectedUid);
15414
+ resolve();
15415
+ }
15416
+ });
15417
+ });
15418
+ }
15384
15419
  /**
15385
15420
  * Registruje novog korisnika sa email-om i lozinkom
15386
15421
  */
@@ -15949,6 +15984,7 @@ var AuthService = class extends BaseService {
15949
15984
  * @returns Object containing user and claimed practitioner
15950
15985
  */
15951
15986
  async claimDraftProfilesWithGoogle(idToken, practitionerIds) {
15987
+ var _a;
15952
15988
  try {
15953
15989
  console.log("[AUTH] Starting claim draft profiles with Google", {
15954
15990
  practitionerIdsCount: practitionerIds.length,
@@ -15965,9 +16001,16 @@ var AuthService = class extends BaseService {
15965
16001
  firebaseUser = result.user;
15966
16002
  }
15967
16003
  console.log("[AUTH] Using Firebase user:", firebaseUser.uid);
16004
+ await this.waitForAuthState(firebaseUser.uid);
15968
16005
  console.log("[AUTH] Forcing token refresh...");
15969
16006
  await firebaseUser.getIdToken(true);
15970
16007
  console.log("[AUTH] Token refreshed successfully");
16008
+ console.log("[AUTH] Verifying auth.currentUser:", ((_a = this.auth.currentUser) == null ? void 0 : _a.uid) || "NULL");
16009
+ console.log("[AUTH] Auth instance ID:", this.auth.__debugId || "no-id");
16010
+ if (!this.auth.__debugId) {
16011
+ this.auth.__debugId = "auth-" + Date.now();
16012
+ }
16013
+ console.log("[AUTH] Auth instance ID set to:", this.auth.__debugId);
15971
16014
  const practitionerService = new PractitionerService(this.db, this.auth, this.app);
15972
16015
  let user = null;
15973
16016
  try {
package/dist/index.mjs CHANGED
@@ -12929,12 +12929,13 @@ var UserService = class extends BaseService {
12929
12929
  * Kreira novog korisnika na osnovu Firebase korisnika
12930
12930
  */
12931
12931
  async createUser(firebaseUser, roles = ["patient" /* PATIENT */], options) {
12932
- var _a, _b, _c, _d, _e, _f, _g, _h;
12932
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
12933
12933
  console.log("[USER_SERVICE] ====== CREATE USER DEBUG ======");
12934
+ console.log("[USER_SERVICE] Auth instance ID:", ((_a = this.auth) == null ? void 0 : _a.__debugId) || "no-id");
12934
12935
  console.log("[USER_SERVICE] Current auth state:", {
12935
- currentUser: ((_b = (_a = this.auth) == null ? void 0 : _a.currentUser) == null ? void 0 : _b.uid) || "NULL",
12936
- currentUserEmail: ((_d = (_c = this.auth) == null ? void 0 : _c.currentUser) == null ? void 0 : _d.email) || "NULL",
12937
- currentUserProvider: ((_f = (_e = this.auth) == null ? void 0 : _e.currentUser) == null ? void 0 : _f.providerId) || "NULL"
12936
+ currentUser: ((_c = (_b = this.auth) == null ? void 0 : _b.currentUser) == null ? void 0 : _c.uid) || "NULL",
12937
+ currentUserEmail: ((_e = (_d = this.auth) == null ? void 0 : _d.currentUser) == null ? void 0 : _e.email) || "NULL",
12938
+ currentUserProvider: ((_g = (_f = this.auth) == null ? void 0 : _f.currentUser) == null ? void 0 : _g.providerId) || "NULL"
12938
12939
  });
12939
12940
  console.log("[USER_SERVICE] Firebase user passed to createUser:", {
12940
12941
  uid: (firebaseUser == null ? void 0 : firebaseUser.uid) || "NULL",
@@ -12942,7 +12943,7 @@ var UserService = class extends BaseService {
12942
12943
  providerId: (firebaseUser == null ? void 0 : firebaseUser.providerId) || "NULL",
12943
12944
  isAnonymous: firebaseUser == null ? void 0 : firebaseUser.isAnonymous
12944
12945
  });
12945
- console.log("[USER_SERVICE] Auth instances match:", ((_h = (_g = this.auth) == null ? void 0 : _g.currentUser) == null ? void 0 : _h.uid) === (firebaseUser == null ? void 0 : firebaseUser.uid));
12946
+ console.log("[USER_SERVICE] Auth instances match:", ((_i = (_h = this.auth) == null ? void 0 : _h.currentUser) == null ? void 0 : _i.uid) === (firebaseUser == null ? void 0 : firebaseUser.uid));
12946
12947
  console.log("[USER_SERVICE] Document path:", `${USERS_COLLECTION}/${firebaseUser == null ? void 0 : firebaseUser.uid}`);
12947
12948
  console.log("[USER_SERVICE] Roles:", roles);
12948
12949
  console.log("[USER_SERVICE] ================================");
@@ -15468,6 +15469,40 @@ var AuthService = class extends BaseService {
15468
15469
  this.googleProvider = new GoogleAuthProvider();
15469
15470
  this.userService = userService || new UserService(db, auth, app);
15470
15471
  }
15472
+ /**
15473
+ * Waits for Firebase Auth state to settle after sign-in.
15474
+ * In React Native with Firebase JS SDK, auth.currentUser doesn't update synchronously
15475
+ * after signInWithCredential. This causes Firestore permission issues.
15476
+ *
15477
+ * @param expectedUid - The UID we expect to see in auth.currentUser
15478
+ * @param timeoutMs - Maximum time to wait (default 10 seconds)
15479
+ * @returns Promise that resolves when auth state is ready
15480
+ */
15481
+ waitForAuthState(expectedUid, timeoutMs = 1e4) {
15482
+ return new Promise((resolve, reject) => {
15483
+ var _a;
15484
+ if (((_a = this.auth.currentUser) == null ? void 0 : _a.uid) === expectedUid) {
15485
+ console.log("[AUTH] Auth state already settled for:", expectedUid);
15486
+ resolve();
15487
+ return;
15488
+ }
15489
+ console.log("[AUTH] Waiting for auth state to settle for:", expectedUid);
15490
+ const timeout = setTimeout(() => {
15491
+ unsubscribe();
15492
+ console.error("[AUTH] Timeout waiting for auth state");
15493
+ reject(new Error("Timeout waiting for auth state to settle"));
15494
+ }, timeoutMs);
15495
+ const unsubscribe = onAuthStateChanged(this.auth, (user) => {
15496
+ console.log("[AUTH] Auth state changed:", (user == null ? void 0 : user.uid) || "null");
15497
+ if ((user == null ? void 0 : user.uid) === expectedUid) {
15498
+ clearTimeout(timeout);
15499
+ unsubscribe();
15500
+ console.log("[AUTH] Auth state settled successfully for:", expectedUid);
15501
+ resolve();
15502
+ }
15503
+ });
15504
+ });
15505
+ }
15471
15506
  /**
15472
15507
  * Registruje novog korisnika sa email-om i lozinkom
15473
15508
  */
@@ -16036,6 +16071,7 @@ var AuthService = class extends BaseService {
16036
16071
  * @returns Object containing user and claimed practitioner
16037
16072
  */
16038
16073
  async claimDraftProfilesWithGoogle(idToken, practitionerIds) {
16074
+ var _a;
16039
16075
  try {
16040
16076
  console.log("[AUTH] Starting claim draft profiles with Google", {
16041
16077
  practitionerIdsCount: practitionerIds.length,
@@ -16052,9 +16088,16 @@ var AuthService = class extends BaseService {
16052
16088
  firebaseUser = result.user;
16053
16089
  }
16054
16090
  console.log("[AUTH] Using Firebase user:", firebaseUser.uid);
16091
+ await this.waitForAuthState(firebaseUser.uid);
16055
16092
  console.log("[AUTH] Forcing token refresh...");
16056
16093
  await firebaseUser.getIdToken(true);
16057
16094
  console.log("[AUTH] Token refreshed successfully");
16095
+ console.log("[AUTH] Verifying auth.currentUser:", ((_a = this.auth.currentUser) == null ? void 0 : _a.uid) || "NULL");
16096
+ console.log("[AUTH] Auth instance ID:", this.auth.__debugId || "no-id");
16097
+ if (!this.auth.__debugId) {
16098
+ this.auth.__debugId = "auth-" + Date.now();
16099
+ }
16100
+ console.log("[AUTH] Auth instance ID set to:", this.auth.__debugId);
16058
16101
  const practitionerService = new PractitionerService(this.db, this.auth, this.app);
16059
16102
  let user = null;
16060
16103
  try {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@blackcode_sa/metaestetics-api",
3
3
  "private": false,
4
- "version": "1.14.6",
4
+ "version": "1.14.8",
5
5
  "description": "Firebase authentication service with anonymous upgrade support",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.mjs",
@@ -92,6 +92,44 @@ export class AuthService extends BaseService {
92
92
  this.userService = userService || new UserService(db, auth, app);
93
93
  }
94
94
 
95
+ /**
96
+ * Waits for Firebase Auth state to settle after sign-in.
97
+ * In React Native with Firebase JS SDK, auth.currentUser doesn't update synchronously
98
+ * after signInWithCredential. This causes Firestore permission issues.
99
+ *
100
+ * @param expectedUid - The UID we expect to see in auth.currentUser
101
+ * @param timeoutMs - Maximum time to wait (default 10 seconds)
102
+ * @returns Promise that resolves when auth state is ready
103
+ */
104
+ private waitForAuthState(expectedUid: string, timeoutMs: number = 10000): Promise<void> {
105
+ return new Promise((resolve, reject) => {
106
+ // If already correct, resolve immediately
107
+ if (this.auth.currentUser?.uid === expectedUid) {
108
+ console.log('[AUTH] Auth state already settled for:', expectedUid);
109
+ resolve();
110
+ return;
111
+ }
112
+
113
+ console.log('[AUTH] Waiting for auth state to settle for:', expectedUid);
114
+
115
+ const timeout = setTimeout(() => {
116
+ unsubscribe();
117
+ console.error('[AUTH] Timeout waiting for auth state');
118
+ reject(new Error('Timeout waiting for auth state to settle'));
119
+ }, timeoutMs);
120
+
121
+ const unsubscribe = onAuthStateChanged(this.auth, (user) => {
122
+ console.log('[AUTH] Auth state changed:', user?.uid || 'null');
123
+ if (user?.uid === expectedUid) {
124
+ clearTimeout(timeout);
125
+ unsubscribe();
126
+ console.log('[AUTH] Auth state settled successfully for:', expectedUid);
127
+ resolve();
128
+ }
129
+ });
130
+ });
131
+ }
132
+
95
133
  /**
96
134
  * Registruje novog korisnika sa email-om i lozinkom
97
135
  */
@@ -846,10 +884,25 @@ export class AuthService extends BaseService {
846
884
  }
847
885
  console.log('[AUTH] Using Firebase user:', firebaseUser.uid);
848
886
 
887
+ // CRITICAL: Wait for auth state to settle in React Native
888
+ // The Firebase JS SDK doesn't update auth.currentUser synchronously after signInWithCredential
889
+ // This causes Firestore to not see the authenticated user, resulting in permission denied
890
+ await this.waitForAuthState(firebaseUser.uid);
891
+
849
892
  // Force token refresh to ensure Firestore has fresh auth context
850
893
  console.log('[AUTH] Forcing token refresh...');
851
894
  await firebaseUser.getIdToken(true);
852
895
  console.log('[AUTH] Token refreshed successfully');
896
+
897
+ // Verify auth state is correct
898
+ console.log('[AUTH] Verifying auth.currentUser:', this.auth.currentUser?.uid || 'NULL');
899
+ // @ts-ignore - Debug: Add unique ID to track auth instance
900
+ console.log('[AUTH] Auth instance ID:', (this.auth as any).__debugId || 'no-id');
901
+ // @ts-ignore - Add debug ID if not exists
902
+ if (!(this.auth as any).__debugId) {
903
+ (this.auth as any).__debugId = 'auth-' + Date.now();
904
+ }
905
+ console.log('[AUTH] Auth instance ID set to:', (this.auth as any).__debugId);
853
906
 
854
907
  const practitionerService = new PractitionerService(this.db, this.auth, this.app);
855
908
 
@@ -91,6 +91,8 @@ export class UserService extends BaseService {
91
91
  ): Promise<User> {
92
92
  // DEBUG LOGGING - Check auth state before creating user document
93
93
  console.log('[USER_SERVICE] ====== CREATE USER DEBUG ======');
94
+ // @ts-ignore - Debug: Check auth instance ID
95
+ console.log('[USER_SERVICE] Auth instance ID:', (this.auth as any)?.__debugId || 'no-id');
94
96
  console.log('[USER_SERVICE] Current auth state:', {
95
97
  currentUser: this.auth?.currentUser?.uid || 'NULL',
96
98
  currentUserEmail: this.auth?.currentUser?.email || 'NULL',