@blackcode_sa/metaestetics-api 1.12.11 → 1.12.13

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
@@ -6191,17 +6191,6 @@ declare class AuthService extends BaseService {
6191
6191
  * @returns The signed-in or newly created user.
6192
6192
  */
6193
6193
  signInWithGoogleIdToken(idToken: string, initialRole?: UserRole): Promise<User>;
6194
- /**
6195
- * Signs in a user with a Google authorization code from a mobile client.
6196
- * This method directly exchanges the authorization code for tokens using Google's OAuth2 API
6197
- * with the platform-specific client ID (no client secret needed for native apps).
6198
- * @param authorizationCode - The Google authorization code obtained from the mobile app.
6199
- * @param redirectUri - The redirect URI used in the OAuth flow.
6200
- * @param platform - The platform (ios/android) to determine which client ID to use.
6201
- * @param initialRole - The role to assign to the user if they are being created.
6202
- * @returns The signed-in or newly created user.
6203
- */
6204
- signInWithGoogleAuthCode(authorizationCode: string, redirectUri: string, platform: 'ios' | 'android', initialRole?: UserRole): Promise<User>;
6205
6194
  /**
6206
6195
  * Links a Google account to the currently signed-in user using an ID token.
6207
6196
  * This is used to upgrade an anonymous user or to allow an existing user
@@ -6210,16 +6199,6 @@ declare class AuthService extends BaseService {
6210
6199
  * @returns The updated user profile.
6211
6200
  */
6212
6201
  linkGoogleAccount(idToken: string): Promise<User>;
6213
- /**
6214
- * Links a Google account to the currently signed-in user using an authorization code.
6215
- * This method directly exchanges the authorization code for tokens using Google's OAuth2 API
6216
- * with the platform-specific client ID, then links the Google account to the current user.
6217
- * @param authorizationCode - The Google authorization code obtained from the mobile app.
6218
- * @param redirectUri - The redirect URI used in the OAuth flow.
6219
- * @param platform - The platform (ios/android) to determine which client ID to use.
6220
- * @returns The updated user profile.
6221
- */
6222
- linkGoogleAccountWithAuthCode(authorizationCode: string, redirectUri: string, platform: 'ios' | 'android'): Promise<User>;
6223
6202
  }
6224
6203
 
6225
6204
  /**
package/dist/index.d.ts CHANGED
@@ -6191,17 +6191,6 @@ declare class AuthService extends BaseService {
6191
6191
  * @returns The signed-in or newly created user.
6192
6192
  */
6193
6193
  signInWithGoogleIdToken(idToken: string, initialRole?: UserRole): Promise<User>;
6194
- /**
6195
- * Signs in a user with a Google authorization code from a mobile client.
6196
- * This method directly exchanges the authorization code for tokens using Google's OAuth2 API
6197
- * with the platform-specific client ID (no client secret needed for native apps).
6198
- * @param authorizationCode - The Google authorization code obtained from the mobile app.
6199
- * @param redirectUri - The redirect URI used in the OAuth flow.
6200
- * @param platform - The platform (ios/android) to determine which client ID to use.
6201
- * @param initialRole - The role to assign to the user if they are being created.
6202
- * @returns The signed-in or newly created user.
6203
- */
6204
- signInWithGoogleAuthCode(authorizationCode: string, redirectUri: string, platform: 'ios' | 'android', initialRole?: UserRole): Promise<User>;
6205
6194
  /**
6206
6195
  * Links a Google account to the currently signed-in user using an ID token.
6207
6196
  * This is used to upgrade an anonymous user or to allow an existing user
@@ -6210,16 +6199,6 @@ declare class AuthService extends BaseService {
6210
6199
  * @returns The updated user profile.
6211
6200
  */
6212
6201
  linkGoogleAccount(idToken: string): Promise<User>;
6213
- /**
6214
- * Links a Google account to the currently signed-in user using an authorization code.
6215
- * This method directly exchanges the authorization code for tokens using Google's OAuth2 API
6216
- * with the platform-specific client ID, then links the Google account to the current user.
6217
- * @param authorizationCode - The Google authorization code obtained from the mobile app.
6218
- * @param redirectUri - The redirect URI used in the OAuth flow.
6219
- * @param platform - The platform (ios/android) to determine which client ID to use.
6220
- * @returns The updated user profile.
6221
- */
6222
- linkGoogleAccountWithAuthCode(authorizationCode: string, redirectUri: string, platform: 'ios' | 'android'): Promise<User>;
6223
6202
  }
6224
6203
 
6225
6204
  /**
package/dist/index.js CHANGED
@@ -10388,79 +10388,18 @@ var AuthService = class extends BaseService {
10388
10388
  console.log("[AUTH] Existing user found, returning profile:", existingUser.uid);
10389
10389
  return existingUser;
10390
10390
  }
10391
- console.log("[AUTH] No existing user found, creating new profile for:", firebaseUser.uid);
10392
- return this.userService.createUser(firebaseUser, [initialRole]);
10391
+ console.log("[AUTH] No existing user found for Google account:", firebaseUser.email);
10392
+ await (0, import_auth7.signOut)(this.auth);
10393
+ throw new AuthError(
10394
+ 'No account found. Please complete registration by starting with "Get Started".',
10395
+ "AUTH/USER_NOT_FOUND",
10396
+ 404
10397
+ );
10393
10398
  } catch (error) {
10394
10399
  console.error("[AUTH] Error in signInWithGoogleIdToken:", error);
10395
10400
  throw handleFirebaseError(error);
10396
10401
  }
10397
10402
  }
10398
- /**
10399
- * Signs in a user with a Google authorization code from a mobile client.
10400
- * This method directly exchanges the authorization code for tokens using Google's OAuth2 API
10401
- * with the platform-specific client ID (no client secret needed for native apps).
10402
- * @param authorizationCode - The Google authorization code obtained from the mobile app.
10403
- * @param redirectUri - The redirect URI used in the OAuth flow.
10404
- * @param platform - The platform (ios/android) to determine which client ID to use.
10405
- * @param initialRole - The role to assign to the user if they are being created.
10406
- * @returns The signed-in or newly created user.
10407
- */
10408
- async signInWithGoogleAuthCode(authorizationCode, redirectUri, platform, initialRole = "patient" /* PATIENT */) {
10409
- try {
10410
- console.log("[AUTH] Signing in with Google authorization code (native flow)");
10411
- console.log("[AUTH] Platform:", platform);
10412
- console.log("[AUTH] Redirect URI:", redirectUri);
10413
- console.log("[AUTH] Code length:", authorizationCode.length);
10414
- const clientId = platform === "ios" ? process.env.GOOGLE_IOS_CLIENT_ID : process.env.GOOGLE_ANDROID_CLIENT_ID;
10415
- if (!clientId) {
10416
- throw new Error(
10417
- `Missing Google ${platform.toUpperCase()} client ID in environment variables`
10418
- );
10419
- }
10420
- console.log("[AUTH] Using client ID:", `${clientId.substring(0, 20)}...`);
10421
- const tokenEndpoint = "https://oauth2.googleapis.com/token";
10422
- const params = new URLSearchParams({
10423
- client_id: clientId,
10424
- code: authorizationCode,
10425
- grant_type: "authorization_code",
10426
- redirect_uri: redirectUri
10427
- // For native apps, we don't include client_secret
10428
- });
10429
- console.log("[AUTH] Making request to Google token endpoint...");
10430
- const response = await fetch(tokenEndpoint, {
10431
- method: "POST",
10432
- headers: {
10433
- "Content-Type": "application/x-www-form-urlencoded"
10434
- },
10435
- body: params.toString()
10436
- });
10437
- if (!response.ok) {
10438
- const errorText = await response.text();
10439
- console.error("[AUTH] Google token exchange failed:", {
10440
- status: response.status,
10441
- statusText: response.statusText,
10442
- error: errorText
10443
- });
10444
- throw new Error(`Google token exchange failed: ${response.status} - ${errorText}`);
10445
- }
10446
- const tokenData = await response.json();
10447
- console.log("[AUTH] Token exchange response received:", {
10448
- hasIdToken: !!tokenData.id_token,
10449
- hasAccessToken: !!tokenData.access_token,
10450
- hasRefreshToken: !!tokenData.refresh_token
10451
- });
10452
- if (!tokenData.id_token) {
10453
- console.error("[AUTH] No ID token in response:", tokenData);
10454
- throw new Error("No ID token received from Google token exchange");
10455
- }
10456
- console.log("[AUTH] Successfully obtained ID token from Google");
10457
- console.log("[AUTH] ID token length:", tokenData.id_token.length);
10458
- return await this.signInWithGoogleIdToken(tokenData.id_token, initialRole);
10459
- } catch (error) {
10460
- console.error("[AUTH] Error in signInWithGoogleAuthCode:", error);
10461
- throw handleFirebaseError(error);
10462
- }
10463
- }
10464
10403
  /**
10465
10404
  * Links a Google account to the currently signed-in user using an ID token.
10466
10405
  * This is used to upgrade an anonymous user or to allow an existing user
@@ -10494,70 +10433,6 @@ var AuthService = class extends BaseService {
10494
10433
  throw handleFirebaseError(error);
10495
10434
  }
10496
10435
  }
10497
- /**
10498
- * Links a Google account to the currently signed-in user using an authorization code.
10499
- * This method directly exchanges the authorization code for tokens using Google's OAuth2 API
10500
- * with the platform-specific client ID, then links the Google account to the current user.
10501
- * @param authorizationCode - The Google authorization code obtained from the mobile app.
10502
- * @param redirectUri - The redirect URI used in the OAuth flow.
10503
- * @param platform - The platform (ios/android) to determine which client ID to use.
10504
- * @returns The updated user profile.
10505
- */
10506
- async linkGoogleAccountWithAuthCode(authorizationCode, redirectUri, platform) {
10507
- try {
10508
- console.log("[AUTH] Linking Google account with authorization code (native flow)");
10509
- console.log("[AUTH] Platform:", platform);
10510
- console.log("[AUTH] Redirect URI:", redirectUri);
10511
- console.log("[AUTH] Code length:", authorizationCode.length);
10512
- const clientId = platform === "ios" ? process.env.GOOGLE_IOS_CLIENT_ID : process.env.GOOGLE_ANDROID_CLIENT_ID;
10513
- if (!clientId) {
10514
- throw new Error(
10515
- `Missing Google ${platform.toUpperCase()} client ID in environment variables`
10516
- );
10517
- }
10518
- console.log("[AUTH] Using client ID:", `${clientId.substring(0, 20)}...`);
10519
- const tokenEndpoint = "https://oauth2.googleapis.com/token";
10520
- const params = new URLSearchParams({
10521
- client_id: clientId,
10522
- code: authorizationCode,
10523
- grant_type: "authorization_code",
10524
- redirect_uri: redirectUri
10525
- });
10526
- console.log("[AUTH] Making request to Google token endpoint...");
10527
- const response = await fetch(tokenEndpoint, {
10528
- method: "POST",
10529
- headers: {
10530
- "Content-Type": "application/x-www-form-urlencoded"
10531
- },
10532
- body: params.toString()
10533
- });
10534
- if (!response.ok) {
10535
- const errorText = await response.text();
10536
- console.error("[AUTH] Google token exchange failed:", {
10537
- status: response.status,
10538
- statusText: response.statusText,
10539
- error: errorText
10540
- });
10541
- throw new Error(`Google token exchange failed: ${response.status} - ${errorText}`);
10542
- }
10543
- const tokenData = await response.json();
10544
- console.log("[AUTH] Token exchange response received:", {
10545
- hasIdToken: !!tokenData.id_token,
10546
- hasAccessToken: !!tokenData.access_token,
10547
- hasRefreshToken: !!tokenData.refresh_token
10548
- });
10549
- if (!tokenData.id_token) {
10550
- console.error("[AUTH] No ID token in response:", tokenData);
10551
- throw new Error("No ID token received from Google token exchange");
10552
- }
10553
- console.log("[AUTH] Successfully obtained ID token from Google");
10554
- console.log("[AUTH] ID token length:", tokenData.id_token.length);
10555
- return await this.linkGoogleAccount(tokenData.id_token);
10556
- } catch (error) {
10557
- console.error("[AUTH] Error in linkGoogleAccountWithAuthCode:", error);
10558
- throw handleFirebaseError(error);
10559
- }
10560
- }
10561
10436
  };
10562
10437
 
10563
10438
  // src/services/calendar/calendar.v2.service.ts
package/dist/index.mjs CHANGED
@@ -10492,79 +10492,18 @@ var AuthService = class extends BaseService {
10492
10492
  console.log("[AUTH] Existing user found, returning profile:", existingUser.uid);
10493
10493
  return existingUser;
10494
10494
  }
10495
- console.log("[AUTH] No existing user found, creating new profile for:", firebaseUser.uid);
10496
- return this.userService.createUser(firebaseUser, [initialRole]);
10495
+ console.log("[AUTH] No existing user found for Google account:", firebaseUser.email);
10496
+ await firebaseSignOut(this.auth);
10497
+ throw new AuthError(
10498
+ 'No account found. Please complete registration by starting with "Get Started".',
10499
+ "AUTH/USER_NOT_FOUND",
10500
+ 404
10501
+ );
10497
10502
  } catch (error) {
10498
10503
  console.error("[AUTH] Error in signInWithGoogleIdToken:", error);
10499
10504
  throw handleFirebaseError(error);
10500
10505
  }
10501
10506
  }
10502
- /**
10503
- * Signs in a user with a Google authorization code from a mobile client.
10504
- * This method directly exchanges the authorization code for tokens using Google's OAuth2 API
10505
- * with the platform-specific client ID (no client secret needed for native apps).
10506
- * @param authorizationCode - The Google authorization code obtained from the mobile app.
10507
- * @param redirectUri - The redirect URI used in the OAuth flow.
10508
- * @param platform - The platform (ios/android) to determine which client ID to use.
10509
- * @param initialRole - The role to assign to the user if they are being created.
10510
- * @returns The signed-in or newly created user.
10511
- */
10512
- async signInWithGoogleAuthCode(authorizationCode, redirectUri, platform, initialRole = "patient" /* PATIENT */) {
10513
- try {
10514
- console.log("[AUTH] Signing in with Google authorization code (native flow)");
10515
- console.log("[AUTH] Platform:", platform);
10516
- console.log("[AUTH] Redirect URI:", redirectUri);
10517
- console.log("[AUTH] Code length:", authorizationCode.length);
10518
- const clientId = platform === "ios" ? process.env.GOOGLE_IOS_CLIENT_ID : process.env.GOOGLE_ANDROID_CLIENT_ID;
10519
- if (!clientId) {
10520
- throw new Error(
10521
- `Missing Google ${platform.toUpperCase()} client ID in environment variables`
10522
- );
10523
- }
10524
- console.log("[AUTH] Using client ID:", `${clientId.substring(0, 20)}...`);
10525
- const tokenEndpoint = "https://oauth2.googleapis.com/token";
10526
- const params = new URLSearchParams({
10527
- client_id: clientId,
10528
- code: authorizationCode,
10529
- grant_type: "authorization_code",
10530
- redirect_uri: redirectUri
10531
- // For native apps, we don't include client_secret
10532
- });
10533
- console.log("[AUTH] Making request to Google token endpoint...");
10534
- const response = await fetch(tokenEndpoint, {
10535
- method: "POST",
10536
- headers: {
10537
- "Content-Type": "application/x-www-form-urlencoded"
10538
- },
10539
- body: params.toString()
10540
- });
10541
- if (!response.ok) {
10542
- const errorText = await response.text();
10543
- console.error("[AUTH] Google token exchange failed:", {
10544
- status: response.status,
10545
- statusText: response.statusText,
10546
- error: errorText
10547
- });
10548
- throw new Error(`Google token exchange failed: ${response.status} - ${errorText}`);
10549
- }
10550
- const tokenData = await response.json();
10551
- console.log("[AUTH] Token exchange response received:", {
10552
- hasIdToken: !!tokenData.id_token,
10553
- hasAccessToken: !!tokenData.access_token,
10554
- hasRefreshToken: !!tokenData.refresh_token
10555
- });
10556
- if (!tokenData.id_token) {
10557
- console.error("[AUTH] No ID token in response:", tokenData);
10558
- throw new Error("No ID token received from Google token exchange");
10559
- }
10560
- console.log("[AUTH] Successfully obtained ID token from Google");
10561
- console.log("[AUTH] ID token length:", tokenData.id_token.length);
10562
- return await this.signInWithGoogleIdToken(tokenData.id_token, initialRole);
10563
- } catch (error) {
10564
- console.error("[AUTH] Error in signInWithGoogleAuthCode:", error);
10565
- throw handleFirebaseError(error);
10566
- }
10567
- }
10568
10507
  /**
10569
10508
  * Links a Google account to the currently signed-in user using an ID token.
10570
10509
  * This is used to upgrade an anonymous user or to allow an existing user
@@ -10598,70 +10537,6 @@ var AuthService = class extends BaseService {
10598
10537
  throw handleFirebaseError(error);
10599
10538
  }
10600
10539
  }
10601
- /**
10602
- * Links a Google account to the currently signed-in user using an authorization code.
10603
- * This method directly exchanges the authorization code for tokens using Google's OAuth2 API
10604
- * with the platform-specific client ID, then links the Google account to the current user.
10605
- * @param authorizationCode - The Google authorization code obtained from the mobile app.
10606
- * @param redirectUri - The redirect URI used in the OAuth flow.
10607
- * @param platform - The platform (ios/android) to determine which client ID to use.
10608
- * @returns The updated user profile.
10609
- */
10610
- async linkGoogleAccountWithAuthCode(authorizationCode, redirectUri, platform) {
10611
- try {
10612
- console.log("[AUTH] Linking Google account with authorization code (native flow)");
10613
- console.log("[AUTH] Platform:", platform);
10614
- console.log("[AUTH] Redirect URI:", redirectUri);
10615
- console.log("[AUTH] Code length:", authorizationCode.length);
10616
- const clientId = platform === "ios" ? process.env.GOOGLE_IOS_CLIENT_ID : process.env.GOOGLE_ANDROID_CLIENT_ID;
10617
- if (!clientId) {
10618
- throw new Error(
10619
- `Missing Google ${platform.toUpperCase()} client ID in environment variables`
10620
- );
10621
- }
10622
- console.log("[AUTH] Using client ID:", `${clientId.substring(0, 20)}...`);
10623
- const tokenEndpoint = "https://oauth2.googleapis.com/token";
10624
- const params = new URLSearchParams({
10625
- client_id: clientId,
10626
- code: authorizationCode,
10627
- grant_type: "authorization_code",
10628
- redirect_uri: redirectUri
10629
- });
10630
- console.log("[AUTH] Making request to Google token endpoint...");
10631
- const response = await fetch(tokenEndpoint, {
10632
- method: "POST",
10633
- headers: {
10634
- "Content-Type": "application/x-www-form-urlencoded"
10635
- },
10636
- body: params.toString()
10637
- });
10638
- if (!response.ok) {
10639
- const errorText = await response.text();
10640
- console.error("[AUTH] Google token exchange failed:", {
10641
- status: response.status,
10642
- statusText: response.statusText,
10643
- error: errorText
10644
- });
10645
- throw new Error(`Google token exchange failed: ${response.status} - ${errorText}`);
10646
- }
10647
- const tokenData = await response.json();
10648
- console.log("[AUTH] Token exchange response received:", {
10649
- hasIdToken: !!tokenData.id_token,
10650
- hasAccessToken: !!tokenData.access_token,
10651
- hasRefreshToken: !!tokenData.refresh_token
10652
- });
10653
- if (!tokenData.id_token) {
10654
- console.error("[AUTH] No ID token in response:", tokenData);
10655
- throw new Error("No ID token received from Google token exchange");
10656
- }
10657
- console.log("[AUTH] Successfully obtained ID token from Google");
10658
- console.log("[AUTH] ID token length:", tokenData.id_token.length);
10659
- return await this.linkGoogleAccount(tokenData.id_token);
10660
- } catch (error) {
10661
- console.error("[AUTH] Error in linkGoogleAccountWithAuthCode:", error);
10662
- throw handleFirebaseError(error);
10663
- }
10664
- }
10665
10540
  };
10666
10541
 
10667
10542
  // src/services/calendar/calendar.v2.service.ts
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@blackcode_sa/metaestetics-api",
3
3
  "private": false,
4
- "version": "1.12.11",
4
+ "version": "1.12.13",
5
5
  "description": "Firebase authentication service with anonymous upgrade support",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.mjs",
@@ -894,103 +894,19 @@ export class AuthService extends BaseService {
894
894
  return existingUser;
895
895
  }
896
896
 
897
- // If no profile exists, create a new one
898
- console.log('[AUTH] No existing user found, creating new profile for:', firebaseUser.uid);
899
- return this.userService.createUser(firebaseUser, [initialRole]);
900
- } catch (error) {
901
- console.error('[AUTH] Error in signInWithGoogleIdToken:', error);
902
- throw handleFirebaseError(error);
903
- }
904
- }
905
-
906
- /**
907
- * Signs in a user with a Google authorization code from a mobile client.
908
- * This method directly exchanges the authorization code for tokens using Google's OAuth2 API
909
- * with the platform-specific client ID (no client secret needed for native apps).
910
- * @param authorizationCode - The Google authorization code obtained from the mobile app.
911
- * @param redirectUri - The redirect URI used in the OAuth flow.
912
- * @param platform - The platform (ios/android) to determine which client ID to use.
913
- * @param initialRole - The role to assign to the user if they are being created.
914
- * @returns The signed-in or newly created user.
915
- */
916
- async signInWithGoogleAuthCode(
917
- authorizationCode: string,
918
- redirectUri: string,
919
- platform: 'ios' | 'android',
920
- initialRole: UserRole = UserRole.PATIENT,
921
- ): Promise<User> {
922
- try {
923
- console.log('[AUTH] Signing in with Google authorization code (native flow)');
924
- console.log('[AUTH] Platform:', platform);
925
- console.log('[AUTH] Redirect URI:', redirectUri);
926
- console.log('[AUTH] Code length:', authorizationCode.length);
927
-
928
- // Get the platform-specific client ID from environment variables
929
- // These should be the same client IDs used in the mobile app
930
- const clientId =
931
- platform === 'ios'
932
- ? process.env.GOOGLE_IOS_CLIENT_ID
933
- : process.env.GOOGLE_ANDROID_CLIENT_ID;
934
-
935
- if (!clientId) {
936
- throw new Error(
937
- `Missing Google ${platform.toUpperCase()} client ID in environment variables`,
938
- );
939
- }
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);
940
899
 
941
- console.log('[AUTH] Using client ID:', `${clientId.substring(0, 20)}...`);
900
+ // Sign out the Firebase user since we don't allow auto-registration
901
+ await firebaseSignOut(this.auth);
942
902
 
943
- // Exchange authorization code for tokens using Google's OAuth2 API
944
- // For native apps, we don't need a client secret
945
- const tokenEndpoint = 'https://oauth2.googleapis.com/token';
946
-
947
- const params = new URLSearchParams({
948
- client_id: clientId,
949
- code: authorizationCode,
950
- grant_type: 'authorization_code',
951
- redirect_uri: redirectUri,
952
- // For native apps, we don't include client_secret
953
- });
954
-
955
- console.log('[AUTH] Making request to Google token endpoint...');
956
-
957
- const response = await fetch(tokenEndpoint, {
958
- method: 'POST',
959
- headers: {
960
- 'Content-Type': 'application/x-www-form-urlencoded',
961
- },
962
- body: params.toString(),
963
- });
964
-
965
- if (!response.ok) {
966
- const errorText = await response.text();
967
- console.error('[AUTH] Google token exchange failed:', {
968
- status: response.status,
969
- statusText: response.statusText,
970
- error: errorText,
971
- });
972
- throw new Error(`Google token exchange failed: ${response.status} - ${errorText}`);
973
- }
974
-
975
- const tokenData = await response.json();
976
- console.log('[AUTH] Token exchange response received:', {
977
- hasIdToken: !!tokenData.id_token,
978
- hasAccessToken: !!tokenData.access_token,
979
- hasRefreshToken: !!tokenData.refresh_token,
980
- });
981
-
982
- if (!tokenData.id_token) {
983
- console.error('[AUTH] No ID token in response:', tokenData);
984
- throw new Error('No ID token received from Google token exchange');
985
- }
986
-
987
- console.log('[AUTH] Successfully obtained ID token from Google');
988
- console.log('[AUTH] ID token length:', tokenData.id_token.length);
989
-
990
- // Now sign in with the ID token
991
- return await this.signInWithGoogleIdToken(tokenData.id_token, initialRole);
903
+ throw new AuthError(
904
+ 'No account found. Please complete registration by starting with "Get Started".',
905
+ 'AUTH/USER_NOT_FOUND',
906
+ 404,
907
+ );
992
908
  } catch (error) {
993
- console.error('[AUTH] Error in signInWithGoogleAuthCode:', error);
909
+ console.error('[AUTH] Error in signInWithGoogleIdToken:', error);
994
910
  throw handleFirebaseError(error);
995
911
  }
996
912
  }
@@ -1033,91 +949,4 @@ export class AuthService extends BaseService {
1033
949
  throw handleFirebaseError(error);
1034
950
  }
1035
951
  }
1036
-
1037
- /**
1038
- * Links a Google account to the currently signed-in user using an authorization code.
1039
- * This method directly exchanges the authorization code for tokens using Google's OAuth2 API
1040
- * with the platform-specific client ID, then links the Google account to the current user.
1041
- * @param authorizationCode - The Google authorization code obtained from the mobile app.
1042
- * @param redirectUri - The redirect URI used in the OAuth flow.
1043
- * @param platform - The platform (ios/android) to determine which client ID to use.
1044
- * @returns The updated user profile.
1045
- */
1046
- async linkGoogleAccountWithAuthCode(
1047
- authorizationCode: string,
1048
- redirectUri: string,
1049
- platform: 'ios' | 'android',
1050
- ): Promise<User> {
1051
- try {
1052
- console.log('[AUTH] Linking Google account with authorization code (native flow)');
1053
- console.log('[AUTH] Platform:', platform);
1054
- console.log('[AUTH] Redirect URI:', redirectUri);
1055
- console.log('[AUTH] Code length:', authorizationCode.length);
1056
-
1057
- // Get the platform-specific client ID from environment variables
1058
- const clientId =
1059
- platform === 'ios'
1060
- ? process.env.GOOGLE_IOS_CLIENT_ID
1061
- : process.env.GOOGLE_ANDROID_CLIENT_ID;
1062
-
1063
- if (!clientId) {
1064
- throw new Error(
1065
- `Missing Google ${platform.toUpperCase()} client ID in environment variables`,
1066
- );
1067
- }
1068
-
1069
- console.log('[AUTH] Using client ID:', `${clientId.substring(0, 20)}...`);
1070
-
1071
- // Exchange authorization code for tokens using Google's OAuth2 API
1072
- const tokenEndpoint = 'https://oauth2.googleapis.com/token';
1073
-
1074
- const params = new URLSearchParams({
1075
- client_id: clientId,
1076
- code: authorizationCode,
1077
- grant_type: 'authorization_code',
1078
- redirect_uri: redirectUri,
1079
- });
1080
-
1081
- console.log('[AUTH] Making request to Google token endpoint...');
1082
-
1083
- const response = await fetch(tokenEndpoint, {
1084
- method: 'POST',
1085
- headers: {
1086
- 'Content-Type': 'application/x-www-form-urlencoded',
1087
- },
1088
- body: params.toString(),
1089
- });
1090
-
1091
- if (!response.ok) {
1092
- const errorText = await response.text();
1093
- console.error('[AUTH] Google token exchange failed:', {
1094
- status: response.status,
1095
- statusText: response.statusText,
1096
- error: errorText,
1097
- });
1098
- throw new Error(`Google token exchange failed: ${response.status} - ${errorText}`);
1099
- }
1100
-
1101
- const tokenData = await response.json();
1102
- console.log('[AUTH] Token exchange response received:', {
1103
- hasIdToken: !!tokenData.id_token,
1104
- hasAccessToken: !!tokenData.access_token,
1105
- hasRefreshToken: !!tokenData.refresh_token,
1106
- });
1107
-
1108
- if (!tokenData.id_token) {
1109
- console.error('[AUTH] No ID token in response:', tokenData);
1110
- throw new Error('No ID token received from Google token exchange');
1111
- }
1112
-
1113
- console.log('[AUTH] Successfully obtained ID token from Google');
1114
- console.log('[AUTH] ID token length:', tokenData.id_token.length);
1115
-
1116
- // Now link the Google account using the ID token
1117
- return await this.linkGoogleAccount(tokenData.id_token);
1118
- } catch (error) {
1119
- console.error('[AUTH] Error in linkGoogleAccountWithAuthCode:', error);
1120
- throw handleFirebaseError(error);
1121
- }
1122
- }
1123
952
  }