@blackcode_sa/metaestetics-api 1.14.4 → 1.14.5
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 +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +49 -48
- package/dist/index.mjs +49 -48
- package/package.json +1 -1
- package/src/services/auth/auth.service.ts +57 -57
package/dist/index.d.mts
CHANGED
|
@@ -8412,9 +8412,9 @@ declare class AuthService extends BaseService {
|
|
|
8412
8412
|
}>;
|
|
8413
8413
|
/**
|
|
8414
8414
|
* Claims draft practitioner profiles after Google Sign-In.
|
|
8415
|
-
*
|
|
8415
|
+
* Uses the current authenticated user (from initial Google Sign-In).
|
|
8416
8416
|
*
|
|
8417
|
-
* @param idToken - The Google ID token
|
|
8417
|
+
* @param idToken - The Google ID token (used to re-authenticate if needed)
|
|
8418
8418
|
* @param practitionerIds - Array of draft practitioner profile IDs to claim
|
|
8419
8419
|
* @returns Object containing user and claimed practitioner
|
|
8420
8420
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -8412,9 +8412,9 @@ declare class AuthService extends BaseService {
|
|
|
8412
8412
|
}>;
|
|
8413
8413
|
/**
|
|
8414
8414
|
* Claims draft practitioner profiles after Google Sign-In.
|
|
8415
|
-
*
|
|
8415
|
+
* Uses the current authenticated user (from initial Google Sign-In).
|
|
8416
8416
|
*
|
|
8417
|
-
* @param idToken - The Google ID token
|
|
8417
|
+
* @param idToken - The Google ID token (used to re-authenticate if needed)
|
|
8418
8418
|
* @param practitionerIds - Array of draft practitioner profile IDs to claim
|
|
8419
8419
|
* @returns Object containing user and claimed practitioner
|
|
8420
8420
|
*/
|
package/dist/index.js
CHANGED
|
@@ -15910,9 +15910,9 @@ var AuthService = class extends BaseService {
|
|
|
15910
15910
|
}
|
|
15911
15911
|
/**
|
|
15912
15912
|
* Claims draft practitioner profiles after Google Sign-In.
|
|
15913
|
-
*
|
|
15913
|
+
* Uses the current authenticated user (from initial Google Sign-In).
|
|
15914
15914
|
*
|
|
15915
|
-
* @param idToken - The Google ID token
|
|
15915
|
+
* @param idToken - The Google ID token (used to re-authenticate if needed)
|
|
15916
15916
|
* @param practitionerIds - Array of draft practitioner profile IDs to claim
|
|
15917
15917
|
* @returns Object containing user and claimed practitioner
|
|
15918
15918
|
*/
|
|
@@ -15925,60 +15925,61 @@ var AuthService = class extends BaseService {
|
|
|
15925
15925
|
if (practitionerIds.length === 0) {
|
|
15926
15926
|
throw new AuthError("No practitioner profiles selected to claim", "AUTH/NO_PROFILES_SELECTED", 400);
|
|
15927
15927
|
}
|
|
15928
|
-
|
|
15929
|
-
|
|
15930
|
-
|
|
15928
|
+
let firebaseUser = this.auth.currentUser;
|
|
15929
|
+
if (!firebaseUser) {
|
|
15930
|
+
console.log("[AUTH] No current user, re-authenticating with Google credential");
|
|
15931
|
+
const credential = import_auth8.GoogleAuthProvider.credential(idToken);
|
|
15932
|
+
const result = await (0, import_auth8.signInWithCredential)(this.auth, credential);
|
|
15933
|
+
firebaseUser = result.user;
|
|
15934
|
+
}
|
|
15935
|
+
console.log("[AUTH] Using Firebase user:", firebaseUser.uid);
|
|
15936
|
+
console.log("[AUTH] Forcing token refresh...");
|
|
15937
|
+
await firebaseUser.getIdToken(true);
|
|
15938
|
+
console.log("[AUTH] Token refreshed successfully");
|
|
15931
15939
|
const practitionerService = new PractitionerService(this.db, this.auth, this.app);
|
|
15932
|
-
let
|
|
15940
|
+
let user = null;
|
|
15933
15941
|
try {
|
|
15934
|
-
|
|
15935
|
-
console.log("[AUTH] User document already exists:",
|
|
15942
|
+
user = await this.userService.getUserById(firebaseUser.uid);
|
|
15943
|
+
console.log("[AUTH] User document already exists:", user.uid);
|
|
15936
15944
|
} catch (userError) {
|
|
15937
|
-
console.log("[AUTH] User document does not exist,
|
|
15945
|
+
console.log("[AUTH] User document does not exist, creating it...");
|
|
15938
15946
|
}
|
|
15939
|
-
|
|
15940
|
-
console.log("[AUTH]
|
|
15941
|
-
|
|
15942
|
-
|
|
15943
|
-
|
|
15944
|
-
|
|
15945
|
-
|
|
15946
|
-
|
|
15947
|
-
|
|
15948
|
-
|
|
15949
|
-
|
|
15950
|
-
|
|
15951
|
-
|
|
15952
|
-
|
|
15953
|
-
|
|
15954
|
-
|
|
15955
|
-
|
|
15956
|
-
|
|
15957
|
-
|
|
15958
|
-
|
|
15959
|
-
|
|
15960
|
-
|
|
15961
|
-
|
|
15962
|
-
|
|
15963
|
-
|
|
15964
|
-
|
|
15965
|
-
|
|
15966
|
-
|
|
15967
|
-
|
|
15968
|
-
practitionerProfile: practitioner.id
|
|
15969
|
-
});
|
|
15970
|
-
}
|
|
15971
|
-
console.log("[AUTH] Transaction completed successfully");
|
|
15972
|
-
return { user, practitioner };
|
|
15973
|
-
});
|
|
15947
|
+
if (!user) {
|
|
15948
|
+
console.log("[AUTH] Creating user document for:", firebaseUser.uid);
|
|
15949
|
+
user = await this.userService.createUser(firebaseUser, ["practitioner" /* PRACTITIONER */], {
|
|
15950
|
+
skipProfileCreation: true
|
|
15951
|
+
});
|
|
15952
|
+
console.log("[AUTH] User document created successfully:", user.uid);
|
|
15953
|
+
}
|
|
15954
|
+
let practitioner;
|
|
15955
|
+
if (practitionerIds.length === 1) {
|
|
15956
|
+
console.log("[AUTH] Claiming single draft profile:", practitionerIds[0]);
|
|
15957
|
+
practitioner = await practitionerService.claimDraftProfileWithGoogle(
|
|
15958
|
+
practitionerIds[0],
|
|
15959
|
+
firebaseUser.uid
|
|
15960
|
+
);
|
|
15961
|
+
} else {
|
|
15962
|
+
console.log("[AUTH] Claiming multiple draft profiles:", practitionerIds);
|
|
15963
|
+
practitioner = await practitionerService.claimMultipleDraftProfilesWithGoogle(
|
|
15964
|
+
practitionerIds,
|
|
15965
|
+
firebaseUser.uid
|
|
15966
|
+
);
|
|
15967
|
+
}
|
|
15968
|
+
console.log("[AUTH] Draft profiles claimed:", practitioner.id);
|
|
15969
|
+
if (!user.practitionerProfile || user.practitionerProfile !== practitioner.id) {
|
|
15970
|
+
console.log("[AUTH] Linking practitioner to user");
|
|
15971
|
+
await this.userService.updateUser(firebaseUser.uid, {
|
|
15972
|
+
practitionerProfile: practitioner.id
|
|
15973
|
+
});
|
|
15974
|
+
}
|
|
15975
|
+
const updatedUser = await this.userService.getUserById(firebaseUser.uid);
|
|
15974
15976
|
console.log("[AUTH] Draft profiles claimed successfully", {
|
|
15975
|
-
userId:
|
|
15976
|
-
practitionerId:
|
|
15977
|
+
userId: updatedUser.uid,
|
|
15978
|
+
practitionerId: practitioner.id
|
|
15977
15979
|
});
|
|
15978
|
-
const updatedUser = await this.userService.getUserById(firebaseUser.uid);
|
|
15979
15980
|
return {
|
|
15980
15981
|
user: updatedUser,
|
|
15981
|
-
practitioner
|
|
15982
|
+
practitioner
|
|
15982
15983
|
};
|
|
15983
15984
|
} catch (error) {
|
|
15984
15985
|
console.error("[AUTH] Error claiming draft profiles with Google:", error);
|
package/dist/index.mjs
CHANGED
|
@@ -15997,9 +15997,9 @@ var AuthService = class extends BaseService {
|
|
|
15997
15997
|
}
|
|
15998
15998
|
/**
|
|
15999
15999
|
* Claims draft practitioner profiles after Google Sign-In.
|
|
16000
|
-
*
|
|
16000
|
+
* Uses the current authenticated user (from initial Google Sign-In).
|
|
16001
16001
|
*
|
|
16002
|
-
* @param idToken - The Google ID token
|
|
16002
|
+
* @param idToken - The Google ID token (used to re-authenticate if needed)
|
|
16003
16003
|
* @param practitionerIds - Array of draft practitioner profile IDs to claim
|
|
16004
16004
|
* @returns Object containing user and claimed practitioner
|
|
16005
16005
|
*/
|
|
@@ -16012,60 +16012,61 @@ var AuthService = class extends BaseService {
|
|
|
16012
16012
|
if (practitionerIds.length === 0) {
|
|
16013
16013
|
throw new AuthError("No practitioner profiles selected to claim", "AUTH/NO_PROFILES_SELECTED", 400);
|
|
16014
16014
|
}
|
|
16015
|
-
|
|
16016
|
-
|
|
16017
|
-
|
|
16015
|
+
let firebaseUser = this.auth.currentUser;
|
|
16016
|
+
if (!firebaseUser) {
|
|
16017
|
+
console.log("[AUTH] No current user, re-authenticating with Google credential");
|
|
16018
|
+
const credential = GoogleAuthProvider.credential(idToken);
|
|
16019
|
+
const result = await signInWithCredential(this.auth, credential);
|
|
16020
|
+
firebaseUser = result.user;
|
|
16021
|
+
}
|
|
16022
|
+
console.log("[AUTH] Using Firebase user:", firebaseUser.uid);
|
|
16023
|
+
console.log("[AUTH] Forcing token refresh...");
|
|
16024
|
+
await firebaseUser.getIdToken(true);
|
|
16025
|
+
console.log("[AUTH] Token refreshed successfully");
|
|
16018
16026
|
const practitionerService = new PractitionerService(this.db, this.auth, this.app);
|
|
16019
|
-
let
|
|
16027
|
+
let user = null;
|
|
16020
16028
|
try {
|
|
16021
|
-
|
|
16022
|
-
console.log("[AUTH] User document already exists:",
|
|
16029
|
+
user = await this.userService.getUserById(firebaseUser.uid);
|
|
16030
|
+
console.log("[AUTH] User document already exists:", user.uid);
|
|
16023
16031
|
} catch (userError) {
|
|
16024
|
-
console.log("[AUTH] User document does not exist,
|
|
16032
|
+
console.log("[AUTH] User document does not exist, creating it...");
|
|
16025
16033
|
}
|
|
16026
|
-
|
|
16027
|
-
console.log("[AUTH]
|
|
16028
|
-
|
|
16029
|
-
|
|
16030
|
-
|
|
16031
|
-
|
|
16032
|
-
|
|
16033
|
-
|
|
16034
|
-
|
|
16035
|
-
|
|
16036
|
-
|
|
16037
|
-
|
|
16038
|
-
|
|
16039
|
-
|
|
16040
|
-
|
|
16041
|
-
|
|
16042
|
-
|
|
16043
|
-
|
|
16044
|
-
|
|
16045
|
-
|
|
16046
|
-
|
|
16047
|
-
|
|
16048
|
-
|
|
16049
|
-
|
|
16050
|
-
|
|
16051
|
-
|
|
16052
|
-
|
|
16053
|
-
|
|
16054
|
-
|
|
16055
|
-
practitionerProfile: practitioner.id
|
|
16056
|
-
});
|
|
16057
|
-
}
|
|
16058
|
-
console.log("[AUTH] Transaction completed successfully");
|
|
16059
|
-
return { user, practitioner };
|
|
16060
|
-
});
|
|
16034
|
+
if (!user) {
|
|
16035
|
+
console.log("[AUTH] Creating user document for:", firebaseUser.uid);
|
|
16036
|
+
user = await this.userService.createUser(firebaseUser, ["practitioner" /* PRACTITIONER */], {
|
|
16037
|
+
skipProfileCreation: true
|
|
16038
|
+
});
|
|
16039
|
+
console.log("[AUTH] User document created successfully:", user.uid);
|
|
16040
|
+
}
|
|
16041
|
+
let practitioner;
|
|
16042
|
+
if (practitionerIds.length === 1) {
|
|
16043
|
+
console.log("[AUTH] Claiming single draft profile:", practitionerIds[0]);
|
|
16044
|
+
practitioner = await practitionerService.claimDraftProfileWithGoogle(
|
|
16045
|
+
practitionerIds[0],
|
|
16046
|
+
firebaseUser.uid
|
|
16047
|
+
);
|
|
16048
|
+
} else {
|
|
16049
|
+
console.log("[AUTH] Claiming multiple draft profiles:", practitionerIds);
|
|
16050
|
+
practitioner = await practitionerService.claimMultipleDraftProfilesWithGoogle(
|
|
16051
|
+
practitionerIds,
|
|
16052
|
+
firebaseUser.uid
|
|
16053
|
+
);
|
|
16054
|
+
}
|
|
16055
|
+
console.log("[AUTH] Draft profiles claimed:", practitioner.id);
|
|
16056
|
+
if (!user.practitionerProfile || user.practitionerProfile !== practitioner.id) {
|
|
16057
|
+
console.log("[AUTH] Linking practitioner to user");
|
|
16058
|
+
await this.userService.updateUser(firebaseUser.uid, {
|
|
16059
|
+
practitionerProfile: practitioner.id
|
|
16060
|
+
});
|
|
16061
|
+
}
|
|
16062
|
+
const updatedUser = await this.userService.getUserById(firebaseUser.uid);
|
|
16061
16063
|
console.log("[AUTH] Draft profiles claimed successfully", {
|
|
16062
|
-
userId:
|
|
16063
|
-
practitionerId:
|
|
16064
|
+
userId: updatedUser.uid,
|
|
16065
|
+
practitionerId: practitioner.id
|
|
16064
16066
|
});
|
|
16065
|
-
const updatedUser = await this.userService.getUserById(firebaseUser.uid);
|
|
16066
16067
|
return {
|
|
16067
16068
|
user: updatedUser,
|
|
16068
|
-
practitioner
|
|
16069
|
+
practitioner
|
|
16069
16070
|
};
|
|
16070
16071
|
} catch (error) {
|
|
16071
16072
|
console.error("[AUTH] Error claiming draft profiles with Google:", error);
|
package/package.json
CHANGED
|
@@ -813,9 +813,9 @@ export class AuthService extends BaseService {
|
|
|
813
813
|
|
|
814
814
|
/**
|
|
815
815
|
* Claims draft practitioner profiles after Google Sign-In.
|
|
816
|
-
*
|
|
816
|
+
* Uses the current authenticated user (from initial Google Sign-In).
|
|
817
817
|
*
|
|
818
|
-
* @param idToken - The Google ID token
|
|
818
|
+
* @param idToken - The Google ID token (used to re-authenticate if needed)
|
|
819
819
|
* @param practitionerIds - Array of draft practitioner profile IDs to claim
|
|
820
820
|
* @returns Object containing user and claimed practitioner
|
|
821
821
|
*/
|
|
@@ -836,77 +836,77 @@ export class AuthService extends BaseService {
|
|
|
836
836
|
throw new AuthError('No practitioner profiles selected to claim', 'AUTH/NO_PROFILES_SELECTED', 400);
|
|
837
837
|
}
|
|
838
838
|
|
|
839
|
-
//
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
839
|
+
// Check if user is currently signed in, if not re-authenticate
|
|
840
|
+
let firebaseUser = this.auth.currentUser;
|
|
841
|
+
if (!firebaseUser) {
|
|
842
|
+
console.log('[AUTH] No current user, re-authenticating with Google credential');
|
|
843
|
+
const credential = GoogleAuthProvider.credential(idToken);
|
|
844
|
+
const result = await signInWithCredential(this.auth, credential);
|
|
845
|
+
firebaseUser = result.user;
|
|
846
|
+
}
|
|
847
|
+
console.log('[AUTH] Using Firebase user:', firebaseUser.uid);
|
|
848
|
+
|
|
849
|
+
// Force token refresh to ensure Firestore has fresh auth context
|
|
850
|
+
console.log('[AUTH] Forcing token refresh...');
|
|
851
|
+
await firebaseUser.getIdToken(true);
|
|
852
|
+
console.log('[AUTH] Token refreshed successfully');
|
|
843
853
|
|
|
844
854
|
const practitionerService = new PractitionerService(this.db, this.auth, this.app);
|
|
845
855
|
|
|
846
|
-
// Check if User document already exists
|
|
847
|
-
let
|
|
856
|
+
// Step 1: Check if User document already exists
|
|
857
|
+
let user: User | null = null;
|
|
848
858
|
try {
|
|
849
|
-
|
|
850
|
-
console.log('[AUTH] User document already exists:',
|
|
859
|
+
user = await this.userService.getUserById(firebaseUser.uid);
|
|
860
|
+
console.log('[AUTH] User document already exists:', user.uid);
|
|
851
861
|
} catch (userError) {
|
|
852
|
-
console.log('[AUTH] User document does not exist,
|
|
862
|
+
console.log('[AUTH] User document does not exist, creating it...');
|
|
853
863
|
}
|
|
854
864
|
|
|
855
|
-
//
|
|
856
|
-
|
|
857
|
-
console.log('[AUTH]
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
} else {
|
|
864
|
-
console.log('[AUTH] Creating user document');
|
|
865
|
-
user = await this.userService.createUser(firebaseUser, [UserRole.PRACTITIONER], {
|
|
866
|
-
skipProfileCreation: true,
|
|
867
|
-
});
|
|
868
|
-
console.log('[AUTH] User document created:', user.uid);
|
|
869
|
-
}
|
|
865
|
+
// Step 2: Create User document if it doesn't exist (NOT in transaction - matches token flow)
|
|
866
|
+
if (!user) {
|
|
867
|
+
console.log('[AUTH] Creating user document for:', firebaseUser.uid);
|
|
868
|
+
user = await this.userService.createUser(firebaseUser, [UserRole.PRACTITIONER], {
|
|
869
|
+
skipProfileCreation: true,
|
|
870
|
+
});
|
|
871
|
+
console.log('[AUTH] User document created successfully:', user.uid);
|
|
872
|
+
}
|
|
870
873
|
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
874
|
+
// Step 3: Claim the draft profiles
|
|
875
|
+
let practitioner: Practitioner;
|
|
876
|
+
if (practitionerIds.length === 1) {
|
|
877
|
+
console.log('[AUTH] Claiming single draft profile:', practitionerIds[0]);
|
|
878
|
+
practitioner = await practitionerService.claimDraftProfileWithGoogle(
|
|
879
|
+
practitionerIds[0],
|
|
880
|
+
firebaseUser.uid
|
|
881
|
+
);
|
|
882
|
+
} else {
|
|
883
|
+
console.log('[AUTH] Claiming multiple draft profiles:', practitionerIds);
|
|
884
|
+
practitioner = await practitionerService.claimMultipleDraftProfilesWithGoogle(
|
|
885
|
+
practitionerIds,
|
|
886
|
+
firebaseUser.uid
|
|
887
|
+
);
|
|
888
|
+
}
|
|
889
|
+
console.log('[AUTH] Draft profiles claimed:', practitioner.id);
|
|
886
890
|
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
891
|
+
// Step 4: Link practitioner to user
|
|
892
|
+
if (!user.practitionerProfile || user.practitionerProfile !== practitioner.id) {
|
|
893
|
+
console.log('[AUTH] Linking practitioner to user');
|
|
894
|
+
await this.userService.updateUser(firebaseUser.uid, {
|
|
895
|
+
practitionerProfile: practitioner.id,
|
|
896
|
+
});
|
|
897
|
+
}
|
|
894
898
|
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
});
|
|
899
|
+
// Fetch updated user (with practitionerProfile reference)
|
|
900
|
+
const updatedUser = await this.userService.getUserById(firebaseUser.uid);
|
|
898
901
|
|
|
899
902
|
console.log('[AUTH] Draft profiles claimed successfully', {
|
|
900
|
-
userId:
|
|
901
|
-
practitionerId:
|
|
903
|
+
userId: updatedUser.uid,
|
|
904
|
+
practitionerId: practitioner.id,
|
|
902
905
|
});
|
|
903
906
|
|
|
904
|
-
// Fetch updated user (with practitionerProfile reference)
|
|
905
|
-
const updatedUser = await this.userService.getUserById(firebaseUser.uid);
|
|
906
|
-
|
|
907
907
|
return {
|
|
908
908
|
user: updatedUser,
|
|
909
|
-
practitioner
|
|
909
|
+
practitioner,
|
|
910
910
|
};
|
|
911
911
|
} catch (error: any) {
|
|
912
912
|
console.error('[AUTH] Error claiming draft profiles with Google:', error);
|