@blackcode_sa/metaestetics-api 1.14.6 → 1.14.7
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 +10 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +37 -0
- package/dist/index.mjs +37 -0
- package/package.json +1 -1
- package/src/services/auth/auth.service.ts +46 -0
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
|
@@ -15381,6 +15381,40 @@ var AuthService = class extends BaseService {
|
|
|
15381
15381
|
this.googleProvider = new import_auth8.GoogleAuthProvider();
|
|
15382
15382
|
this.userService = userService || new UserService(db, auth, app);
|
|
15383
15383
|
}
|
|
15384
|
+
/**
|
|
15385
|
+
* Waits for Firebase Auth state to settle after sign-in.
|
|
15386
|
+
* In React Native with Firebase JS SDK, auth.currentUser doesn't update synchronously
|
|
15387
|
+
* after signInWithCredential. This causes Firestore permission issues.
|
|
15388
|
+
*
|
|
15389
|
+
* @param expectedUid - The UID we expect to see in auth.currentUser
|
|
15390
|
+
* @param timeoutMs - Maximum time to wait (default 10 seconds)
|
|
15391
|
+
* @returns Promise that resolves when auth state is ready
|
|
15392
|
+
*/
|
|
15393
|
+
waitForAuthState(expectedUid, timeoutMs = 1e4) {
|
|
15394
|
+
return new Promise((resolve, reject) => {
|
|
15395
|
+
var _a;
|
|
15396
|
+
if (((_a = this.auth.currentUser) == null ? void 0 : _a.uid) === expectedUid) {
|
|
15397
|
+
console.log("[AUTH] Auth state already settled for:", expectedUid);
|
|
15398
|
+
resolve();
|
|
15399
|
+
return;
|
|
15400
|
+
}
|
|
15401
|
+
console.log("[AUTH] Waiting for auth state to settle for:", expectedUid);
|
|
15402
|
+
const timeout = setTimeout(() => {
|
|
15403
|
+
unsubscribe();
|
|
15404
|
+
console.error("[AUTH] Timeout waiting for auth state");
|
|
15405
|
+
reject(new Error("Timeout waiting for auth state to settle"));
|
|
15406
|
+
}, timeoutMs);
|
|
15407
|
+
const unsubscribe = (0, import_auth8.onAuthStateChanged)(this.auth, (user) => {
|
|
15408
|
+
console.log("[AUTH] Auth state changed:", (user == null ? void 0 : user.uid) || "null");
|
|
15409
|
+
if ((user == null ? void 0 : user.uid) === expectedUid) {
|
|
15410
|
+
clearTimeout(timeout);
|
|
15411
|
+
unsubscribe();
|
|
15412
|
+
console.log("[AUTH] Auth state settled successfully for:", expectedUid);
|
|
15413
|
+
resolve();
|
|
15414
|
+
}
|
|
15415
|
+
});
|
|
15416
|
+
});
|
|
15417
|
+
}
|
|
15384
15418
|
/**
|
|
15385
15419
|
* Registruje novog korisnika sa email-om i lozinkom
|
|
15386
15420
|
*/
|
|
@@ -15949,6 +15983,7 @@ var AuthService = class extends BaseService {
|
|
|
15949
15983
|
* @returns Object containing user and claimed practitioner
|
|
15950
15984
|
*/
|
|
15951
15985
|
async claimDraftProfilesWithGoogle(idToken, practitionerIds) {
|
|
15986
|
+
var _a;
|
|
15952
15987
|
try {
|
|
15953
15988
|
console.log("[AUTH] Starting claim draft profiles with Google", {
|
|
15954
15989
|
practitionerIdsCount: practitionerIds.length,
|
|
@@ -15965,9 +16000,11 @@ var AuthService = class extends BaseService {
|
|
|
15965
16000
|
firebaseUser = result.user;
|
|
15966
16001
|
}
|
|
15967
16002
|
console.log("[AUTH] Using Firebase user:", firebaseUser.uid);
|
|
16003
|
+
await this.waitForAuthState(firebaseUser.uid);
|
|
15968
16004
|
console.log("[AUTH] Forcing token refresh...");
|
|
15969
16005
|
await firebaseUser.getIdToken(true);
|
|
15970
16006
|
console.log("[AUTH] Token refreshed successfully");
|
|
16007
|
+
console.log("[AUTH] Verifying auth.currentUser:", ((_a = this.auth.currentUser) == null ? void 0 : _a.uid) || "NULL");
|
|
15971
16008
|
const practitionerService = new PractitionerService(this.db, this.auth, this.app);
|
|
15972
16009
|
let user = null;
|
|
15973
16010
|
try {
|
package/dist/index.mjs
CHANGED
|
@@ -15468,6 +15468,40 @@ var AuthService = class extends BaseService {
|
|
|
15468
15468
|
this.googleProvider = new GoogleAuthProvider();
|
|
15469
15469
|
this.userService = userService || new UserService(db, auth, app);
|
|
15470
15470
|
}
|
|
15471
|
+
/**
|
|
15472
|
+
* Waits for Firebase Auth state to settle after sign-in.
|
|
15473
|
+
* In React Native with Firebase JS SDK, auth.currentUser doesn't update synchronously
|
|
15474
|
+
* after signInWithCredential. This causes Firestore permission issues.
|
|
15475
|
+
*
|
|
15476
|
+
* @param expectedUid - The UID we expect to see in auth.currentUser
|
|
15477
|
+
* @param timeoutMs - Maximum time to wait (default 10 seconds)
|
|
15478
|
+
* @returns Promise that resolves when auth state is ready
|
|
15479
|
+
*/
|
|
15480
|
+
waitForAuthState(expectedUid, timeoutMs = 1e4) {
|
|
15481
|
+
return new Promise((resolve, reject) => {
|
|
15482
|
+
var _a;
|
|
15483
|
+
if (((_a = this.auth.currentUser) == null ? void 0 : _a.uid) === expectedUid) {
|
|
15484
|
+
console.log("[AUTH] Auth state already settled for:", expectedUid);
|
|
15485
|
+
resolve();
|
|
15486
|
+
return;
|
|
15487
|
+
}
|
|
15488
|
+
console.log("[AUTH] Waiting for auth state to settle for:", expectedUid);
|
|
15489
|
+
const timeout = setTimeout(() => {
|
|
15490
|
+
unsubscribe();
|
|
15491
|
+
console.error("[AUTH] Timeout waiting for auth state");
|
|
15492
|
+
reject(new Error("Timeout waiting for auth state to settle"));
|
|
15493
|
+
}, timeoutMs);
|
|
15494
|
+
const unsubscribe = onAuthStateChanged(this.auth, (user) => {
|
|
15495
|
+
console.log("[AUTH] Auth state changed:", (user == null ? void 0 : user.uid) || "null");
|
|
15496
|
+
if ((user == null ? void 0 : user.uid) === expectedUid) {
|
|
15497
|
+
clearTimeout(timeout);
|
|
15498
|
+
unsubscribe();
|
|
15499
|
+
console.log("[AUTH] Auth state settled successfully for:", expectedUid);
|
|
15500
|
+
resolve();
|
|
15501
|
+
}
|
|
15502
|
+
});
|
|
15503
|
+
});
|
|
15504
|
+
}
|
|
15471
15505
|
/**
|
|
15472
15506
|
* Registruje novog korisnika sa email-om i lozinkom
|
|
15473
15507
|
*/
|
|
@@ -16036,6 +16070,7 @@ var AuthService = class extends BaseService {
|
|
|
16036
16070
|
* @returns Object containing user and claimed practitioner
|
|
16037
16071
|
*/
|
|
16038
16072
|
async claimDraftProfilesWithGoogle(idToken, practitionerIds) {
|
|
16073
|
+
var _a;
|
|
16039
16074
|
try {
|
|
16040
16075
|
console.log("[AUTH] Starting claim draft profiles with Google", {
|
|
16041
16076
|
practitionerIdsCount: practitionerIds.length,
|
|
@@ -16052,9 +16087,11 @@ var AuthService = class extends BaseService {
|
|
|
16052
16087
|
firebaseUser = result.user;
|
|
16053
16088
|
}
|
|
16054
16089
|
console.log("[AUTH] Using Firebase user:", firebaseUser.uid);
|
|
16090
|
+
await this.waitForAuthState(firebaseUser.uid);
|
|
16055
16091
|
console.log("[AUTH] Forcing token refresh...");
|
|
16056
16092
|
await firebaseUser.getIdToken(true);
|
|
16057
16093
|
console.log("[AUTH] Token refreshed successfully");
|
|
16094
|
+
console.log("[AUTH] Verifying auth.currentUser:", ((_a = this.auth.currentUser) == null ? void 0 : _a.uid) || "NULL");
|
|
16058
16095
|
const practitionerService = new PractitionerService(this.db, this.auth, this.app);
|
|
16059
16096
|
let user = null;
|
|
16060
16097
|
try {
|
package/package.json
CHANGED
|
@@ -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,18 @@ 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');
|
|
853
899
|
|
|
854
900
|
const practitionerService = new PractitionerService(this.db, this.auth, this.app);
|
|
855
901
|
|