@blackcode_sa/metaestetics-api 1.12.15 → 1.12.16
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 +3 -4
- package/dist/index.d.ts +3 -4
- package/dist/index.js +7 -28
- package/dist/index.mjs +7 -28
- package/package.json +1 -1
- package/src/services/auth/auth.service.ts +12 -42
package/dist/index.d.mts
CHANGED
|
@@ -6185,11 +6185,10 @@ declare class AuthService extends BaseService {
|
|
|
6185
6185
|
}>;
|
|
6186
6186
|
/**
|
|
6187
6187
|
* Signs in a user with a Google ID token from a mobile client.
|
|
6188
|
-
* If the user does not exist
|
|
6188
|
+
* If the user does not exist, a new user is created.
|
|
6189
6189
|
* @param idToken - The Google ID token obtained from the mobile app.
|
|
6190
|
-
* @param initialRole - The role to assign to the user
|
|
6191
|
-
* @returns The signed-in
|
|
6192
|
-
* @throws AuthError if no user profile is found.
|
|
6190
|
+
* @param initialRole - The role to assign to the user if they are being created.
|
|
6191
|
+
* @returns The signed-in or newly created user.
|
|
6193
6192
|
*/
|
|
6194
6193
|
signInWithGoogleIdToken(idToken: string, initialRole?: UserRole): Promise<User>;
|
|
6195
6194
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -6185,11 +6185,10 @@ declare class AuthService extends BaseService {
|
|
|
6185
6185
|
}>;
|
|
6186
6186
|
/**
|
|
6187
6187
|
* Signs in a user with a Google ID token from a mobile client.
|
|
6188
|
-
* If the user does not exist
|
|
6188
|
+
* If the user does not exist, a new user is created.
|
|
6189
6189
|
* @param idToken - The Google ID token obtained from the mobile app.
|
|
6190
|
-
* @param initialRole - The role to assign to the user
|
|
6191
|
-
* @returns The signed-in
|
|
6192
|
-
* @throws AuthError if no user profile is found.
|
|
6190
|
+
* @param initialRole - The role to assign to the user if they are being created.
|
|
6191
|
+
* @returns The signed-in or newly created user.
|
|
6193
6192
|
*/
|
|
6194
6193
|
signInWithGoogleIdToken(idToken: string, initialRole?: UserRole): Promise<User>;
|
|
6195
6194
|
/**
|
package/dist/index.js
CHANGED
|
@@ -10344,37 +10344,15 @@ var AuthService = class extends BaseService {
|
|
|
10344
10344
|
}
|
|
10345
10345
|
/**
|
|
10346
10346
|
* Signs in a user with a Google ID token from a mobile client.
|
|
10347
|
-
* If the user does not exist
|
|
10347
|
+
* If the user does not exist, a new user is created.
|
|
10348
10348
|
* @param idToken - The Google ID token obtained from the mobile app.
|
|
10349
|
-
* @param initialRole - The role to assign to the user
|
|
10350
|
-
* @returns The signed-in
|
|
10351
|
-
* @throws AuthError if no user profile is found.
|
|
10349
|
+
* @param initialRole - The role to assign to the user if they are being created.
|
|
10350
|
+
* @returns The signed-in or newly created user.
|
|
10352
10351
|
*/
|
|
10353
10352
|
async signInWithGoogleIdToken(idToken, initialRole = "patient" /* PATIENT */) {
|
|
10354
10353
|
try {
|
|
10355
10354
|
console.log("[AUTH] Signing in with Google ID Token");
|
|
10356
10355
|
const credential = import_auth7.GoogleAuthProvider.credential(idToken);
|
|
10357
|
-
const decodedToken = JSON.parse(atob(idToken.split(".")[1]));
|
|
10358
|
-
const userEmail = decodedToken.email;
|
|
10359
|
-
const userUid = decodedToken.sub;
|
|
10360
|
-
console.log("[AUTH] Checking if Firebase Auth user exists with email:", userEmail);
|
|
10361
|
-
let existingAuthUser;
|
|
10362
|
-
try {
|
|
10363
|
-
const admin = await import("firebase-admin");
|
|
10364
|
-
existingAuthUser = await admin.auth().getUserByEmail(userEmail);
|
|
10365
|
-
console.log("[AUTH] Firebase Auth user found:", existingAuthUser.uid);
|
|
10366
|
-
} catch (authError) {
|
|
10367
|
-
if (authError.code === "auth/user-not-found") {
|
|
10368
|
-
console.log("[AUTH] No Firebase Auth user found for email:", userEmail);
|
|
10369
|
-
throw new AuthError(
|
|
10370
|
-
'No account found. Please complete registration by starting with "Get Started".',
|
|
10371
|
-
"AUTH/USER_NOT_FOUND",
|
|
10372
|
-
404
|
|
10373
|
-
);
|
|
10374
|
-
}
|
|
10375
|
-
throw authError;
|
|
10376
|
-
}
|
|
10377
|
-
console.log("[AUTH] Firebase Auth user exists, proceeding with sign-in");
|
|
10378
10356
|
const { user: firebaseUser } = await (0, import_auth7.signInWithCredential)(this.auth, credential);
|
|
10379
10357
|
console.log("[AUTH] Firebase user signed in:", firebaseUser.uid);
|
|
10380
10358
|
const existingUser = await this.userService.getUserById(firebaseUser.uid);
|
|
@@ -10382,11 +10360,12 @@ var AuthService = class extends BaseService {
|
|
|
10382
10360
|
console.log("[AUTH] Existing user found, returning profile:", existingUser.uid);
|
|
10383
10361
|
return existingUser;
|
|
10384
10362
|
}
|
|
10363
|
+
console.log("[AUTH] No existing user found for Google account:", firebaseUser.email);
|
|
10385
10364
|
await (0, import_auth7.signOut)(this.auth);
|
|
10386
10365
|
throw new AuthError(
|
|
10387
|
-
|
|
10388
|
-
"AUTH/
|
|
10389
|
-
|
|
10366
|
+
'No account found. Please complete registration by starting with "Get Started".',
|
|
10367
|
+
"AUTH/USER_NOT_FOUND",
|
|
10368
|
+
404
|
|
10390
10369
|
);
|
|
10391
10370
|
} catch (error) {
|
|
10392
10371
|
console.error("[AUTH] Error in signInWithGoogleIdToken:", error);
|
package/dist/index.mjs
CHANGED
|
@@ -10448,37 +10448,15 @@ var AuthService = class extends BaseService {
|
|
|
10448
10448
|
}
|
|
10449
10449
|
/**
|
|
10450
10450
|
* Signs in a user with a Google ID token from a mobile client.
|
|
10451
|
-
* If the user does not exist
|
|
10451
|
+
* If the user does not exist, a new user is created.
|
|
10452
10452
|
* @param idToken - The Google ID token obtained from the mobile app.
|
|
10453
|
-
* @param initialRole - The role to assign to the user
|
|
10454
|
-
* @returns The signed-in
|
|
10455
|
-
* @throws AuthError if no user profile is found.
|
|
10453
|
+
* @param initialRole - The role to assign to the user if they are being created.
|
|
10454
|
+
* @returns The signed-in or newly created user.
|
|
10456
10455
|
*/
|
|
10457
10456
|
async signInWithGoogleIdToken(idToken, initialRole = "patient" /* PATIENT */) {
|
|
10458
10457
|
try {
|
|
10459
10458
|
console.log("[AUTH] Signing in with Google ID Token");
|
|
10460
10459
|
const credential = GoogleAuthProvider.credential(idToken);
|
|
10461
|
-
const decodedToken = JSON.parse(atob(idToken.split(".")[1]));
|
|
10462
|
-
const userEmail = decodedToken.email;
|
|
10463
|
-
const userUid = decodedToken.sub;
|
|
10464
|
-
console.log("[AUTH] Checking if Firebase Auth user exists with email:", userEmail);
|
|
10465
|
-
let existingAuthUser;
|
|
10466
|
-
try {
|
|
10467
|
-
const admin = await import("firebase-admin");
|
|
10468
|
-
existingAuthUser = await admin.auth().getUserByEmail(userEmail);
|
|
10469
|
-
console.log("[AUTH] Firebase Auth user found:", existingAuthUser.uid);
|
|
10470
|
-
} catch (authError) {
|
|
10471
|
-
if (authError.code === "auth/user-not-found") {
|
|
10472
|
-
console.log("[AUTH] No Firebase Auth user found for email:", userEmail);
|
|
10473
|
-
throw new AuthError(
|
|
10474
|
-
'No account found. Please complete registration by starting with "Get Started".',
|
|
10475
|
-
"AUTH/USER_NOT_FOUND",
|
|
10476
|
-
404
|
|
10477
|
-
);
|
|
10478
|
-
}
|
|
10479
|
-
throw authError;
|
|
10480
|
-
}
|
|
10481
|
-
console.log("[AUTH] Firebase Auth user exists, proceeding with sign-in");
|
|
10482
10460
|
const { user: firebaseUser } = await signInWithCredential(this.auth, credential);
|
|
10483
10461
|
console.log("[AUTH] Firebase user signed in:", firebaseUser.uid);
|
|
10484
10462
|
const existingUser = await this.userService.getUserById(firebaseUser.uid);
|
|
@@ -10486,11 +10464,12 @@ var AuthService = class extends BaseService {
|
|
|
10486
10464
|
console.log("[AUTH] Existing user found, returning profile:", existingUser.uid);
|
|
10487
10465
|
return existingUser;
|
|
10488
10466
|
}
|
|
10467
|
+
console.log("[AUTH] No existing user found for Google account:", firebaseUser.email);
|
|
10489
10468
|
await firebaseSignOut(this.auth);
|
|
10490
10469
|
throw new AuthError(
|
|
10491
|
-
|
|
10492
|
-
"AUTH/
|
|
10493
|
-
|
|
10470
|
+
'No account found. Please complete registration by starting with "Get Started".',
|
|
10471
|
+
"AUTH/USER_NOT_FOUND",
|
|
10472
|
+
404
|
|
10494
10473
|
);
|
|
10495
10474
|
} catch (error) {
|
|
10496
10475
|
console.error("[AUTH] Error in signInWithGoogleIdToken:", error);
|
package/package.json
CHANGED
|
@@ -872,11 +872,10 @@ export class AuthService extends BaseService {
|
|
|
872
872
|
|
|
873
873
|
/**
|
|
874
874
|
* Signs in a user with a Google ID token from a mobile client.
|
|
875
|
-
* If the user does not exist
|
|
875
|
+
* If the user does not exist, a new user is created.
|
|
876
876
|
* @param idToken - The Google ID token obtained from the mobile app.
|
|
877
|
-
* @param initialRole - The role to assign to the user
|
|
878
|
-
* @returns The signed-in
|
|
879
|
-
* @throws AuthError if no user profile is found.
|
|
877
|
+
* @param initialRole - The role to assign to the user if they are being created.
|
|
878
|
+
* @returns The signed-in or newly created user.
|
|
880
879
|
*/
|
|
881
880
|
async signInWithGoogleIdToken(
|
|
882
881
|
idToken: string,
|
|
@@ -884,56 +883,27 @@ export class AuthService extends BaseService {
|
|
|
884
883
|
): Promise<User> {
|
|
885
884
|
try {
|
|
886
885
|
console.log('[AUTH] Signing in with Google ID Token');
|
|
887
|
-
|
|
888
|
-
// First, decode the ID token to get the user's email without signing them in
|
|
889
886
|
const credential = GoogleAuthProvider.credential(idToken);
|
|
890
|
-
|
|
891
|
-
// Parse the ID token to get user info without creating a Firebase Auth session
|
|
892
|
-
const decodedToken = JSON.parse(atob(idToken.split('.')[1]));
|
|
893
|
-
const userEmail = decodedToken.email;
|
|
894
|
-
const userUid = decodedToken.sub; // This will be the Firebase UID
|
|
895
|
-
|
|
896
|
-
console.log('[AUTH] Checking if Firebase Auth user exists with email:', userEmail);
|
|
897
|
-
|
|
898
|
-
// Check if a Firebase Auth user with this email already exists
|
|
899
|
-
let existingAuthUser;
|
|
900
|
-
try {
|
|
901
|
-
const admin = await import('firebase-admin');
|
|
902
|
-
existingAuthUser = await admin.auth().getUserByEmail(userEmail);
|
|
903
|
-
console.log('[AUTH] Firebase Auth user found:', existingAuthUser.uid);
|
|
904
|
-
} catch (authError: any) {
|
|
905
|
-
if (authError.code === 'auth/user-not-found') {
|
|
906
|
-
// No Firebase Auth user exists - reject the login
|
|
907
|
-
console.log('[AUTH] No Firebase Auth user found for email:', userEmail);
|
|
908
|
-
throw new AuthError(
|
|
909
|
-
'No account found. Please complete registration by starting with "Get Started".',
|
|
910
|
-
'AUTH/USER_NOT_FOUND',
|
|
911
|
-
404,
|
|
912
|
-
);
|
|
913
|
-
}
|
|
914
|
-
// Re-throw other auth errors
|
|
915
|
-
throw authError;
|
|
916
|
-
}
|
|
917
|
-
|
|
918
|
-
console.log('[AUTH] Firebase Auth user exists, proceeding with sign-in');
|
|
919
|
-
|
|
920
|
-
// Now proceed with the actual Firebase sign-in since we know the auth user exists
|
|
921
887
|
const { user: firebaseUser } = await signInWithCredential(this.auth, credential);
|
|
922
888
|
console.log('[AUTH] Firebase user signed in:', firebaseUser.uid);
|
|
923
889
|
|
|
924
|
-
//
|
|
890
|
+
// Check if the user already has a profile in our database
|
|
925
891
|
const existingUser = await this.userService.getUserById(firebaseUser.uid);
|
|
926
892
|
if (existingUser) {
|
|
927
893
|
console.log('[AUTH] Existing user found, returning profile:', existingUser.uid);
|
|
928
894
|
return existingUser;
|
|
929
895
|
}
|
|
930
896
|
|
|
931
|
-
//
|
|
897
|
+
// If no profile exists, reject the login - user must complete onboarding first
|
|
898
|
+
console.log('[AUTH] No existing user found for Google account:', firebaseUser.email);
|
|
899
|
+
|
|
900
|
+
// Sign out the Firebase user since we don't allow auto-registration
|
|
932
901
|
await firebaseSignOut(this.auth);
|
|
902
|
+
|
|
933
903
|
throw new AuthError(
|
|
934
|
-
'
|
|
935
|
-
'AUTH/
|
|
936
|
-
|
|
904
|
+
'No account found. Please complete registration by starting with "Get Started".',
|
|
905
|
+
'AUTH/USER_NOT_FOUND',
|
|
906
|
+
404,
|
|
937
907
|
);
|
|
938
908
|
} catch (error) {
|
|
939
909
|
console.error('[AUTH] Error in signInWithGoogleIdToken:', error);
|