@blackcode_sa/metaestetics-api 1.14.9 → 1.14.11

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.js CHANGED
@@ -12880,6 +12880,11 @@ var PractitionerService = class extends BaseService {
12880
12880
  var UserService = class extends BaseService {
12881
12881
  constructor(db, auth, app, patientService, clinicAdminService, practitionerService) {
12882
12882
  super(db, auth, app);
12883
+ if (!this.auth.__userServiceId) {
12884
+ this.auth.__userServiceId = "user-service-" + Date.now();
12885
+ }
12886
+ console.log("[USER_SERVICE] Constructor - auth ID:", this.auth.__userServiceId);
12887
+ console.log("[USER_SERVICE] Constructor - auth.__authServiceId:", this.auth.__authServiceId || "NOT SET");
12883
12888
  if (!patientService) {
12884
12889
  patientService = new PatientService(db, auth, app);
12885
12890
  }
@@ -12908,6 +12913,7 @@ var UserService = class extends BaseService {
12908
12913
  async createUser(firebaseUser, roles = ["patient" /* PATIENT */], options) {
12909
12914
  var _a, _b, _c, _d, _e, _f, _g, _h, _i;
12910
12915
  console.log("[USER_SERVICE] ====== CREATE USER DEBUG ======");
12916
+ console.log(this.auth);
12911
12917
  console.log("[USER_SERVICE] Auth instance ID:", ((_a = this.auth) == null ? void 0 : _a.__debugId) || "no-id");
12912
12918
  console.log("[USER_SERVICE] Current auth state:", {
12913
12919
  currentUser: ((_c = (_b = this.auth) == null ? void 0 : _b.currentUser) == null ? void 0 : _c.uid) || "NULL",
@@ -15378,9 +15384,15 @@ var validatePractitionerProfileData = async (profileData) => {
15378
15384
  // src/services/auth/auth.service.ts
15379
15385
  var AuthService = class extends BaseService {
15380
15386
  constructor(db, auth, app, userService) {
15387
+ var _a;
15381
15388
  super(db, auth, app);
15382
15389
  this.googleProvider = new import_auth8.GoogleAuthProvider();
15383
15390
  this.userService = userService || new UserService(db, auth, app);
15391
+ if (!this.auth.__authServiceId) {
15392
+ this.auth.__authServiceId = "auth-service-" + Date.now();
15393
+ }
15394
+ console.log("[AUTH] AuthService constructor - auth ID:", this.auth.__authServiceId);
15395
+ console.log("[AUTH] AuthService constructor - userService.auth ID:", ((_a = this.userService.auth) == null ? void 0 : _a.__authServiceId) || "NOT SET");
15384
15396
  }
15385
15397
  /**
15386
15398
  * Waits for Firebase Auth state to settle after sign-in.
@@ -15984,7 +15996,7 @@ var AuthService = class extends BaseService {
15984
15996
  * @returns Object containing user and claimed practitioner
15985
15997
  */
15986
15998
  async claimDraftProfilesWithGoogle(idToken, practitionerIds) {
15987
- var _a;
15999
+ var _a, _b;
15988
16000
  try {
15989
16001
  console.log("[AUTH] Starting claim draft profiles with Google", {
15990
16002
  practitionerIdsCount: practitionerIds.length,
@@ -15993,16 +16005,13 @@ var AuthService = class extends BaseService {
15993
16005
  if (practitionerIds.length === 0) {
15994
16006
  throw new AuthError("No practitioner profiles selected to claim", "AUTH/NO_PROFILES_SELECTED", 400);
15995
16007
  }
15996
- let firebaseUser = this.auth.currentUser;
15997
- if (!firebaseUser) {
15998
- console.log("[AUTH] No current user, re-authenticating with Google credential");
15999
- const credential = import_auth8.GoogleAuthProvider.credential(idToken);
16000
- const result = await (0, import_auth8.signInWithCredential)(this.auth, credential);
16001
- firebaseUser = result.user;
16002
- }
16003
- console.log("[AUTH] Using Firebase user:", firebaseUser.uid);
16004
- await this.waitForAuthState(firebaseUser.uid);
16005
- console.log("[AUTH] Auth state after waitForAuthState:", ((_a = this.auth.currentUser) == null ? void 0 : _a.uid) || "NULL");
16008
+ console.log("[AUTH] currentUser BEFORE sign-in:", ((_a = this.auth.currentUser) == null ? void 0 : _a.uid) || "NULL");
16009
+ console.log("[AUTH] Signing in with Google credential...");
16010
+ const credential = import_auth8.GoogleAuthProvider.credential(idToken);
16011
+ const result = await (0, import_auth8.signInWithCredential)(this.auth, credential);
16012
+ const firebaseUser = result.user;
16013
+ console.log("[AUTH] currentUser IMMEDIATELY AFTER sign-in:", ((_b = this.auth.currentUser) == null ? void 0 : _b.uid) || "NULL");
16014
+ console.log("[AUTH] User returned from signInWithCredential:", firebaseUser.uid);
16006
16015
  const practitionerService = new PractitionerService(this.db, this.auth, this.app);
16007
16016
  let user = null;
16008
16017
  try {
package/dist/index.mjs CHANGED
@@ -12903,6 +12903,11 @@ var PractitionerService = class extends BaseService {
12903
12903
  var UserService = class extends BaseService {
12904
12904
  constructor(db, auth, app, patientService, clinicAdminService, practitionerService) {
12905
12905
  super(db, auth, app);
12906
+ if (!this.auth.__userServiceId) {
12907
+ this.auth.__userServiceId = "user-service-" + Date.now();
12908
+ }
12909
+ console.log("[USER_SERVICE] Constructor - auth ID:", this.auth.__userServiceId);
12910
+ console.log("[USER_SERVICE] Constructor - auth.__authServiceId:", this.auth.__authServiceId || "NOT SET");
12906
12911
  if (!patientService) {
12907
12912
  patientService = new PatientService(db, auth, app);
12908
12913
  }
@@ -12931,6 +12936,7 @@ var UserService = class extends BaseService {
12931
12936
  async createUser(firebaseUser, roles = ["patient" /* PATIENT */], options) {
12932
12937
  var _a, _b, _c, _d, _e, _f, _g, _h, _i;
12933
12938
  console.log("[USER_SERVICE] ====== CREATE USER DEBUG ======");
12939
+ console.log(this.auth);
12934
12940
  console.log("[USER_SERVICE] Auth instance ID:", ((_a = this.auth) == null ? void 0 : _a.__debugId) || "no-id");
12935
12941
  console.log("[USER_SERVICE] Current auth state:", {
12936
12942
  currentUser: ((_c = (_b = this.auth) == null ? void 0 : _b.currentUser) == null ? void 0 : _c.uid) || "NULL",
@@ -15465,9 +15471,15 @@ var validatePractitionerProfileData = async (profileData) => {
15465
15471
  // src/services/auth/auth.service.ts
15466
15472
  var AuthService = class extends BaseService {
15467
15473
  constructor(db, auth, app, userService) {
15474
+ var _a;
15468
15475
  super(db, auth, app);
15469
15476
  this.googleProvider = new GoogleAuthProvider();
15470
15477
  this.userService = userService || new UserService(db, auth, app);
15478
+ if (!this.auth.__authServiceId) {
15479
+ this.auth.__authServiceId = "auth-service-" + Date.now();
15480
+ }
15481
+ console.log("[AUTH] AuthService constructor - auth ID:", this.auth.__authServiceId);
15482
+ console.log("[AUTH] AuthService constructor - userService.auth ID:", ((_a = this.userService.auth) == null ? void 0 : _a.__authServiceId) || "NOT SET");
15471
15483
  }
15472
15484
  /**
15473
15485
  * Waits for Firebase Auth state to settle after sign-in.
@@ -16071,7 +16083,7 @@ var AuthService = class extends BaseService {
16071
16083
  * @returns Object containing user and claimed practitioner
16072
16084
  */
16073
16085
  async claimDraftProfilesWithGoogle(idToken, practitionerIds) {
16074
- var _a;
16086
+ var _a, _b;
16075
16087
  try {
16076
16088
  console.log("[AUTH] Starting claim draft profiles with Google", {
16077
16089
  practitionerIdsCount: practitionerIds.length,
@@ -16080,16 +16092,13 @@ var AuthService = class extends BaseService {
16080
16092
  if (practitionerIds.length === 0) {
16081
16093
  throw new AuthError("No practitioner profiles selected to claim", "AUTH/NO_PROFILES_SELECTED", 400);
16082
16094
  }
16083
- let firebaseUser = this.auth.currentUser;
16084
- if (!firebaseUser) {
16085
- console.log("[AUTH] No current user, re-authenticating with Google credential");
16086
- const credential = GoogleAuthProvider.credential(idToken);
16087
- const result = await signInWithCredential(this.auth, credential);
16088
- firebaseUser = result.user;
16089
- }
16090
- console.log("[AUTH] Using Firebase user:", firebaseUser.uid);
16091
- await this.waitForAuthState(firebaseUser.uid);
16092
- console.log("[AUTH] Auth state after waitForAuthState:", ((_a = this.auth.currentUser) == null ? void 0 : _a.uid) || "NULL");
16095
+ console.log("[AUTH] currentUser BEFORE sign-in:", ((_a = this.auth.currentUser) == null ? void 0 : _a.uid) || "NULL");
16096
+ console.log("[AUTH] Signing in with Google credential...");
16097
+ const credential = GoogleAuthProvider.credential(idToken);
16098
+ const result = await signInWithCredential(this.auth, credential);
16099
+ const firebaseUser = result.user;
16100
+ console.log("[AUTH] currentUser IMMEDIATELY AFTER sign-in:", ((_b = this.auth.currentUser) == null ? void 0 : _b.uid) || "NULL");
16101
+ console.log("[AUTH] User returned from signInWithCredential:", firebaseUser.uid);
16093
16102
  const practitionerService = new PractitionerService(this.db, this.auth, this.app);
16094
16103
  let user = null;
16095
16104
  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.9",
4
+ "version": "1.14.11",
5
5
  "description": "Firebase authentication service with anonymous upgrade support",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.mjs",
@@ -90,6 +90,17 @@ export class AuthService extends BaseService {
90
90
  constructor(db: Firestore, auth: Auth, app: FirebaseApp, userService: UserService) {
91
91
  super(db, auth, app);
92
92
  this.userService = userService || new UserService(db, auth, app);
93
+
94
+ // DEBUG: Tag the auth instances to track them
95
+ // @ts-ignore
96
+ if (!this.auth.__authServiceId) {
97
+ // @ts-ignore
98
+ this.auth.__authServiceId = 'auth-service-' + Date.now();
99
+ }
100
+ // @ts-ignore
101
+ console.log('[AUTH] AuthService constructor - auth ID:', this.auth.__authServiceId);
102
+ // @ts-ignore
103
+ console.log('[AUTH] AuthService constructor - userService.auth ID:', (this.userService as any).auth?.__authServiceId || 'NOT SET');
93
104
  }
94
105
 
95
106
  /**
@@ -874,28 +885,18 @@ export class AuthService extends BaseService {
874
885
  throw new AuthError('No practitioner profiles selected to claim', 'AUTH/NO_PROFILES_SELECTED', 400);
875
886
  }
876
887
 
877
- // Check if user is currently signed in, if not re-authenticate
878
- let firebaseUser = this.auth.currentUser;
879
- if (!firebaseUser) {
880
- console.log('[AUTH] No current user, re-authenticating with Google credential');
881
- const credential = GoogleAuthProvider.credential(idToken);
882
- const result = await signInWithCredential(this.auth, credential);
883
- firebaseUser = result.user;
884
- }
885
- console.log('[AUTH] Using Firebase user:', firebaseUser.uid);
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);
888
+ // Check auth state BEFORE sign-in
889
+ console.log('[AUTH] currentUser BEFORE sign-in:', this.auth.currentUser?.uid || 'NULL');
891
890
 
892
- // Verify auth state BEFORE any other operations
893
- console.log('[AUTH] Auth state after waitForAuthState:', this.auth.currentUser?.uid || 'NULL');
891
+ // Sign in with Google credential
892
+ console.log('[AUTH] Signing in with Google credential...');
893
+ const credential = GoogleAuthProvider.credential(idToken);
894
+ const result = await signInWithCredential(this.auth, credential);
895
+ const firebaseUser = result.user;
894
896
 
895
- // DON'T force token refresh - it might be clearing auth state in React Native!
896
- // console.log('[AUTH] Forcing token refresh...');
897
- // await firebaseUser.getIdToken(true);
898
- // console.log('[AUTH] Token refreshed successfully');
897
+ // Check auth state IMMEDIATELY AFTER sign-in
898
+ console.log('[AUTH] currentUser IMMEDIATELY AFTER sign-in:', this.auth.currentUser?.uid || 'NULL');
899
+ console.log('[AUTH] User returned from signInWithCredential:', firebaseUser.uid);
899
900
 
900
901
  const practitionerService = new PractitionerService(this.db, this.auth, this.app);
901
902
 
@@ -45,6 +45,17 @@ export class UserService extends BaseService {
45
45
  ) {
46
46
  super(db, auth, app);
47
47
 
48
+ // DEBUG: Tag the auth instance
49
+ // @ts-ignore
50
+ if (!this.auth.__userServiceId) {
51
+ // @ts-ignore
52
+ this.auth.__userServiceId = 'user-service-' + Date.now();
53
+ }
54
+ // @ts-ignore
55
+ console.log('[USER_SERVICE] Constructor - auth ID:', this.auth.__userServiceId);
56
+ // @ts-ignore
57
+ console.log('[USER_SERVICE] Constructor - auth.__authServiceId:', this.auth.__authServiceId || 'NOT SET');
58
+
48
59
  // Kreiramo servise samo ako nisu prosleđeni
49
60
  if (!patientService) {
50
61
  patientService = new PatientService(db, auth, app);
@@ -92,6 +103,7 @@ export class UserService extends BaseService {
92
103
  // DEBUG LOGGING - Check auth state before creating user document
93
104
  console.log('[USER_SERVICE] ====== CREATE USER DEBUG ======');
94
105
  // @ts-ignore - Debug: Check auth instance ID
106
+ console.log(this.auth)
95
107
  console.log('[USER_SERVICE] Auth instance ID:', (this.auth as any)?.__debugId || 'no-id');
96
108
  console.log('[USER_SERVICE] Current auth state:', {
97
109
  currentUser: this.auth?.currentUser?.uid || 'NULL',