@blackcode_sa/metaestetics-api 1.12.12 → 1.12.14
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 +0 -21
- package/dist/index.d.ts +0 -21
- package/dist/index.js +7 -124
- package/dist/index.mjs +7 -124
- package/package.json +1 -1
- package/src/services/auth/auth.service.ts +10 -162
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 clientId - The platform-specific Google OAuth client ID.
|
|
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, clientId: string, 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 clientId - The platform-specific Google OAuth client ID.
|
|
6220
|
-
* @returns The updated user profile.
|
|
6221
|
-
*/
|
|
6222
|
-
linkGoogleAccountWithAuthCode(authorizationCode: string, redirectUri: string, clientId: string): 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 clientId - The platform-specific Google OAuth client ID.
|
|
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, clientId: string, 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 clientId - The platform-specific Google OAuth client ID.
|
|
6220
|
-
* @returns The updated user profile.
|
|
6221
|
-
*/
|
|
6222
|
-
linkGoogleAccountWithAuthCode(authorizationCode: string, redirectUri: string, clientId: string): Promise<User>;
|
|
6223
6202
|
}
|
|
6224
6203
|
|
|
6225
6204
|
/**
|
package/dist/index.js
CHANGED
|
@@ -10388,75 +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
|
|
10392
|
-
|
|
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 clientId - The platform-specific Google OAuth client ID.
|
|
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, clientId, initialRole = "patient" /* PATIENT */) {
|
|
10409
|
-
try {
|
|
10410
|
-
console.log("[AUTH] Signing in with Google authorization code (native flow)");
|
|
10411
|
-
console.log("[AUTH] Redirect URI:", redirectUri);
|
|
10412
|
-
console.log("[AUTH] Code length:", authorizationCode.length);
|
|
10413
|
-
if (!clientId) {
|
|
10414
|
-
throw new Error("Google client ID is required for authorization code exchange");
|
|
10415
|
-
}
|
|
10416
|
-
console.log("[AUTH] Using client ID:", `${clientId.substring(0, 20)}...`);
|
|
10417
|
-
const tokenEndpoint = "https://oauth2.googleapis.com/token";
|
|
10418
|
-
const params = new URLSearchParams({
|
|
10419
|
-
client_id: clientId,
|
|
10420
|
-
code: authorizationCode,
|
|
10421
|
-
grant_type: "authorization_code",
|
|
10422
|
-
redirect_uri: redirectUri
|
|
10423
|
-
// For native apps, we don't include client_secret
|
|
10424
|
-
});
|
|
10425
|
-
console.log("[AUTH] Making request to Google token endpoint...");
|
|
10426
|
-
const response = await fetch(tokenEndpoint, {
|
|
10427
|
-
method: "POST",
|
|
10428
|
-
headers: {
|
|
10429
|
-
"Content-Type": "application/x-www-form-urlencoded"
|
|
10430
|
-
},
|
|
10431
|
-
body: params.toString()
|
|
10432
|
-
});
|
|
10433
|
-
if (!response.ok) {
|
|
10434
|
-
const errorText = await response.text();
|
|
10435
|
-
console.error("[AUTH] Google token exchange failed:", {
|
|
10436
|
-
status: response.status,
|
|
10437
|
-
statusText: response.statusText,
|
|
10438
|
-
error: errorText
|
|
10439
|
-
});
|
|
10440
|
-
throw new Error(`Google token exchange failed: ${response.status} - ${errorText}`);
|
|
10441
|
-
}
|
|
10442
|
-
const tokenData = await response.json();
|
|
10443
|
-
console.log("[AUTH] Token exchange response received:", {
|
|
10444
|
-
hasIdToken: !!tokenData.id_token,
|
|
10445
|
-
hasAccessToken: !!tokenData.access_token,
|
|
10446
|
-
hasRefreshToken: !!tokenData.refresh_token
|
|
10447
|
-
});
|
|
10448
|
-
if (!tokenData.id_token) {
|
|
10449
|
-
console.error("[AUTH] No ID token in response:", tokenData);
|
|
10450
|
-
throw new Error("No ID token received from Google token exchange");
|
|
10451
|
-
}
|
|
10452
|
-
console.log("[AUTH] Successfully obtained ID token from Google");
|
|
10453
|
-
console.log("[AUTH] ID token length:", tokenData.id_token.length);
|
|
10454
|
-
return await this.signInWithGoogleIdToken(tokenData.id_token, initialRole);
|
|
10455
|
-
} catch (error) {
|
|
10456
|
-
console.error("[AUTH] Error in signInWithGoogleAuthCode:", error);
|
|
10457
|
-
throw handleFirebaseError(error);
|
|
10458
|
-
}
|
|
10459
|
-
}
|
|
10460
10403
|
/**
|
|
10461
10404
|
* Links a Google account to the currently signed-in user using an ID token.
|
|
10462
10405
|
* This is used to upgrade an anonymous user or to allow an existing user
|
|
@@ -10490,66 +10433,6 @@ var AuthService = class extends BaseService {
|
|
|
10490
10433
|
throw handleFirebaseError(error);
|
|
10491
10434
|
}
|
|
10492
10435
|
}
|
|
10493
|
-
/**
|
|
10494
|
-
* Links a Google account to the currently signed-in user using an authorization code.
|
|
10495
|
-
* This method directly exchanges the authorization code for tokens using Google's OAuth2 API
|
|
10496
|
-
* with the platform-specific client ID, then links the Google account to the current user.
|
|
10497
|
-
* @param authorizationCode - The Google authorization code obtained from the mobile app.
|
|
10498
|
-
* @param redirectUri - The redirect URI used in the OAuth flow.
|
|
10499
|
-
* @param clientId - The platform-specific Google OAuth client ID.
|
|
10500
|
-
* @returns The updated user profile.
|
|
10501
|
-
*/
|
|
10502
|
-
async linkGoogleAccountWithAuthCode(authorizationCode, redirectUri, clientId) {
|
|
10503
|
-
try {
|
|
10504
|
-
console.log("[AUTH] Linking Google account with authorization code (native flow)");
|
|
10505
|
-
console.log("[AUTH] Redirect URI:", redirectUri);
|
|
10506
|
-
console.log("[AUTH] Code length:", authorizationCode.length);
|
|
10507
|
-
if (!clientId) {
|
|
10508
|
-
throw new Error("Google client ID is required for authorization code exchange");
|
|
10509
|
-
}
|
|
10510
|
-
console.log("[AUTH] Using client ID:", `${clientId.substring(0, 20)}...`);
|
|
10511
|
-
const tokenEndpoint = "https://oauth2.googleapis.com/token";
|
|
10512
|
-
const params = new URLSearchParams({
|
|
10513
|
-
client_id: clientId,
|
|
10514
|
-
code: authorizationCode,
|
|
10515
|
-
grant_type: "authorization_code",
|
|
10516
|
-
redirect_uri: redirectUri
|
|
10517
|
-
});
|
|
10518
|
-
console.log("[AUTH] Making request to Google token endpoint...");
|
|
10519
|
-
const response = await fetch(tokenEndpoint, {
|
|
10520
|
-
method: "POST",
|
|
10521
|
-
headers: {
|
|
10522
|
-
"Content-Type": "application/x-www-form-urlencoded"
|
|
10523
|
-
},
|
|
10524
|
-
body: params.toString()
|
|
10525
|
-
});
|
|
10526
|
-
if (!response.ok) {
|
|
10527
|
-
const errorText = await response.text();
|
|
10528
|
-
console.error("[AUTH] Google token exchange failed:", {
|
|
10529
|
-
status: response.status,
|
|
10530
|
-
statusText: response.statusText,
|
|
10531
|
-
error: errorText
|
|
10532
|
-
});
|
|
10533
|
-
throw new Error(`Google token exchange failed: ${response.status} - ${errorText}`);
|
|
10534
|
-
}
|
|
10535
|
-
const tokenData = await response.json();
|
|
10536
|
-
console.log("[AUTH] Token exchange response received:", {
|
|
10537
|
-
hasIdToken: !!tokenData.id_token,
|
|
10538
|
-
hasAccessToken: !!tokenData.access_token,
|
|
10539
|
-
hasRefreshToken: !!tokenData.refresh_token
|
|
10540
|
-
});
|
|
10541
|
-
if (!tokenData.id_token) {
|
|
10542
|
-
console.error("[AUTH] No ID token in response:", tokenData);
|
|
10543
|
-
throw new Error("No ID token received from Google token exchange");
|
|
10544
|
-
}
|
|
10545
|
-
console.log("[AUTH] Successfully obtained ID token from Google");
|
|
10546
|
-
console.log("[AUTH] ID token length:", tokenData.id_token.length);
|
|
10547
|
-
return await this.linkGoogleAccount(tokenData.id_token);
|
|
10548
|
-
} catch (error) {
|
|
10549
|
-
console.error("[AUTH] Error in linkGoogleAccountWithAuthCode:", error);
|
|
10550
|
-
throw handleFirebaseError(error);
|
|
10551
|
-
}
|
|
10552
|
-
}
|
|
10553
10436
|
};
|
|
10554
10437
|
|
|
10555
10438
|
// src/services/calendar/calendar.v2.service.ts
|
package/dist/index.mjs
CHANGED
|
@@ -10492,75 +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
|
|
10496
|
-
|
|
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 clientId - The platform-specific Google OAuth client ID.
|
|
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, clientId, initialRole = "patient" /* PATIENT */) {
|
|
10513
|
-
try {
|
|
10514
|
-
console.log("[AUTH] Signing in with Google authorization code (native flow)");
|
|
10515
|
-
console.log("[AUTH] Redirect URI:", redirectUri);
|
|
10516
|
-
console.log("[AUTH] Code length:", authorizationCode.length);
|
|
10517
|
-
if (!clientId) {
|
|
10518
|
-
throw new Error("Google client ID is required for authorization code exchange");
|
|
10519
|
-
}
|
|
10520
|
-
console.log("[AUTH] Using client ID:", `${clientId.substring(0, 20)}...`);
|
|
10521
|
-
const tokenEndpoint = "https://oauth2.googleapis.com/token";
|
|
10522
|
-
const params = new URLSearchParams({
|
|
10523
|
-
client_id: clientId,
|
|
10524
|
-
code: authorizationCode,
|
|
10525
|
-
grant_type: "authorization_code",
|
|
10526
|
-
redirect_uri: redirectUri
|
|
10527
|
-
// For native apps, we don't include client_secret
|
|
10528
|
-
});
|
|
10529
|
-
console.log("[AUTH] Making request to Google token endpoint...");
|
|
10530
|
-
const response = await fetch(tokenEndpoint, {
|
|
10531
|
-
method: "POST",
|
|
10532
|
-
headers: {
|
|
10533
|
-
"Content-Type": "application/x-www-form-urlencoded"
|
|
10534
|
-
},
|
|
10535
|
-
body: params.toString()
|
|
10536
|
-
});
|
|
10537
|
-
if (!response.ok) {
|
|
10538
|
-
const errorText = await response.text();
|
|
10539
|
-
console.error("[AUTH] Google token exchange failed:", {
|
|
10540
|
-
status: response.status,
|
|
10541
|
-
statusText: response.statusText,
|
|
10542
|
-
error: errorText
|
|
10543
|
-
});
|
|
10544
|
-
throw new Error(`Google token exchange failed: ${response.status} - ${errorText}`);
|
|
10545
|
-
}
|
|
10546
|
-
const tokenData = await response.json();
|
|
10547
|
-
console.log("[AUTH] Token exchange response received:", {
|
|
10548
|
-
hasIdToken: !!tokenData.id_token,
|
|
10549
|
-
hasAccessToken: !!tokenData.access_token,
|
|
10550
|
-
hasRefreshToken: !!tokenData.refresh_token
|
|
10551
|
-
});
|
|
10552
|
-
if (!tokenData.id_token) {
|
|
10553
|
-
console.error("[AUTH] No ID token in response:", tokenData);
|
|
10554
|
-
throw new Error("No ID token received from Google token exchange");
|
|
10555
|
-
}
|
|
10556
|
-
console.log("[AUTH] Successfully obtained ID token from Google");
|
|
10557
|
-
console.log("[AUTH] ID token length:", tokenData.id_token.length);
|
|
10558
|
-
return await this.signInWithGoogleIdToken(tokenData.id_token, initialRole);
|
|
10559
|
-
} catch (error) {
|
|
10560
|
-
console.error("[AUTH] Error in signInWithGoogleAuthCode:", error);
|
|
10561
|
-
throw handleFirebaseError(error);
|
|
10562
|
-
}
|
|
10563
|
-
}
|
|
10564
10507
|
/**
|
|
10565
10508
|
* Links a Google account to the currently signed-in user using an ID token.
|
|
10566
10509
|
* This is used to upgrade an anonymous user or to allow an existing user
|
|
@@ -10594,66 +10537,6 @@ var AuthService = class extends BaseService {
|
|
|
10594
10537
|
throw handleFirebaseError(error);
|
|
10595
10538
|
}
|
|
10596
10539
|
}
|
|
10597
|
-
/**
|
|
10598
|
-
* Links a Google account to the currently signed-in user using an authorization code.
|
|
10599
|
-
* This method directly exchanges the authorization code for tokens using Google's OAuth2 API
|
|
10600
|
-
* with the platform-specific client ID, then links the Google account to the current user.
|
|
10601
|
-
* @param authorizationCode - The Google authorization code obtained from the mobile app.
|
|
10602
|
-
* @param redirectUri - The redirect URI used in the OAuth flow.
|
|
10603
|
-
* @param clientId - The platform-specific Google OAuth client ID.
|
|
10604
|
-
* @returns The updated user profile.
|
|
10605
|
-
*/
|
|
10606
|
-
async linkGoogleAccountWithAuthCode(authorizationCode, redirectUri, clientId) {
|
|
10607
|
-
try {
|
|
10608
|
-
console.log("[AUTH] Linking Google account with authorization code (native flow)");
|
|
10609
|
-
console.log("[AUTH] Redirect URI:", redirectUri);
|
|
10610
|
-
console.log("[AUTH] Code length:", authorizationCode.length);
|
|
10611
|
-
if (!clientId) {
|
|
10612
|
-
throw new Error("Google client ID is required for authorization code exchange");
|
|
10613
|
-
}
|
|
10614
|
-
console.log("[AUTH] Using client ID:", `${clientId.substring(0, 20)}...`);
|
|
10615
|
-
const tokenEndpoint = "https://oauth2.googleapis.com/token";
|
|
10616
|
-
const params = new URLSearchParams({
|
|
10617
|
-
client_id: clientId,
|
|
10618
|
-
code: authorizationCode,
|
|
10619
|
-
grant_type: "authorization_code",
|
|
10620
|
-
redirect_uri: redirectUri
|
|
10621
|
-
});
|
|
10622
|
-
console.log("[AUTH] Making request to Google token endpoint...");
|
|
10623
|
-
const response = await fetch(tokenEndpoint, {
|
|
10624
|
-
method: "POST",
|
|
10625
|
-
headers: {
|
|
10626
|
-
"Content-Type": "application/x-www-form-urlencoded"
|
|
10627
|
-
},
|
|
10628
|
-
body: params.toString()
|
|
10629
|
-
});
|
|
10630
|
-
if (!response.ok) {
|
|
10631
|
-
const errorText = await response.text();
|
|
10632
|
-
console.error("[AUTH] Google token exchange failed:", {
|
|
10633
|
-
status: response.status,
|
|
10634
|
-
statusText: response.statusText,
|
|
10635
|
-
error: errorText
|
|
10636
|
-
});
|
|
10637
|
-
throw new Error(`Google token exchange failed: ${response.status} - ${errorText}`);
|
|
10638
|
-
}
|
|
10639
|
-
const tokenData = await response.json();
|
|
10640
|
-
console.log("[AUTH] Token exchange response received:", {
|
|
10641
|
-
hasIdToken: !!tokenData.id_token,
|
|
10642
|
-
hasAccessToken: !!tokenData.access_token,
|
|
10643
|
-
hasRefreshToken: !!tokenData.refresh_token
|
|
10644
|
-
});
|
|
10645
|
-
if (!tokenData.id_token) {
|
|
10646
|
-
console.error("[AUTH] No ID token in response:", tokenData);
|
|
10647
|
-
throw new Error("No ID token received from Google token exchange");
|
|
10648
|
-
}
|
|
10649
|
-
console.log("[AUTH] Successfully obtained ID token from Google");
|
|
10650
|
-
console.log("[AUTH] ID token length:", tokenData.id_token.length);
|
|
10651
|
-
return await this.linkGoogleAccount(tokenData.id_token);
|
|
10652
|
-
} catch (error) {
|
|
10653
|
-
console.error("[AUTH] Error in linkGoogleAccountWithAuthCode:", error);
|
|
10654
|
-
throw handleFirebaseError(error);
|
|
10655
|
-
}
|
|
10656
|
-
}
|
|
10657
10540
|
};
|
|
10658
10541
|
|
|
10659
10542
|
// src/services/calendar/calendar.v2.service.ts
|
package/package.json
CHANGED
|
@@ -894,93 +894,19 @@ export class AuthService extends BaseService {
|
|
|
894
894
|
return existingUser;
|
|
895
895
|
}
|
|
896
896
|
|
|
897
|
-
// If no profile exists,
|
|
898
|
-
console.log('[AUTH] No existing user found
|
|
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 clientId - The platform-specific Google OAuth client ID.
|
|
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
|
-
clientId: string,
|
|
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] Redirect URI:', redirectUri);
|
|
925
|
-
console.log('[AUTH] Code length:', authorizationCode.length);
|
|
926
|
-
|
|
927
|
-
if (!clientId) {
|
|
928
|
-
throw new Error('Google client ID is required for authorization code exchange');
|
|
929
|
-
}
|
|
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);
|
|
930
899
|
|
|
931
|
-
|
|
900
|
+
// Sign out the Firebase user since we don't allow auto-registration
|
|
901
|
+
await firebaseSignOut(this.auth);
|
|
932
902
|
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
client_id: clientId,
|
|
939
|
-
code: authorizationCode,
|
|
940
|
-
grant_type: 'authorization_code',
|
|
941
|
-
redirect_uri: redirectUri,
|
|
942
|
-
// For native apps, we don't include client_secret
|
|
943
|
-
});
|
|
944
|
-
|
|
945
|
-
console.log('[AUTH] Making request to Google token endpoint...');
|
|
946
|
-
|
|
947
|
-
const response = await fetch(tokenEndpoint, {
|
|
948
|
-
method: 'POST',
|
|
949
|
-
headers: {
|
|
950
|
-
'Content-Type': 'application/x-www-form-urlencoded',
|
|
951
|
-
},
|
|
952
|
-
body: params.toString(),
|
|
953
|
-
});
|
|
954
|
-
|
|
955
|
-
if (!response.ok) {
|
|
956
|
-
const errorText = await response.text();
|
|
957
|
-
console.error('[AUTH] Google token exchange failed:', {
|
|
958
|
-
status: response.status,
|
|
959
|
-
statusText: response.statusText,
|
|
960
|
-
error: errorText,
|
|
961
|
-
});
|
|
962
|
-
throw new Error(`Google token exchange failed: ${response.status} - ${errorText}`);
|
|
963
|
-
}
|
|
964
|
-
|
|
965
|
-
const tokenData = await response.json();
|
|
966
|
-
console.log('[AUTH] Token exchange response received:', {
|
|
967
|
-
hasIdToken: !!tokenData.id_token,
|
|
968
|
-
hasAccessToken: !!tokenData.access_token,
|
|
969
|
-
hasRefreshToken: !!tokenData.refresh_token,
|
|
970
|
-
});
|
|
971
|
-
|
|
972
|
-
if (!tokenData.id_token) {
|
|
973
|
-
console.error('[AUTH] No ID token in response:', tokenData);
|
|
974
|
-
throw new Error('No ID token received from Google token exchange');
|
|
975
|
-
}
|
|
976
|
-
|
|
977
|
-
console.log('[AUTH] Successfully obtained ID token from Google');
|
|
978
|
-
console.log('[AUTH] ID token length:', tokenData.id_token.length);
|
|
979
|
-
|
|
980
|
-
// Now sign in with the ID token
|
|
981
|
-
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
|
+
);
|
|
982
908
|
} catch (error) {
|
|
983
|
-
console.error('[AUTH] Error in
|
|
909
|
+
console.error('[AUTH] Error in signInWithGoogleIdToken:', error);
|
|
984
910
|
throw handleFirebaseError(error);
|
|
985
911
|
}
|
|
986
912
|
}
|
|
@@ -1023,82 +949,4 @@ export class AuthService extends BaseService {
|
|
|
1023
949
|
throw handleFirebaseError(error);
|
|
1024
950
|
}
|
|
1025
951
|
}
|
|
1026
|
-
|
|
1027
|
-
/**
|
|
1028
|
-
* Links a Google account to the currently signed-in user using an authorization code.
|
|
1029
|
-
* This method directly exchanges the authorization code for tokens using Google's OAuth2 API
|
|
1030
|
-
* with the platform-specific client ID, then links the Google account to the current user.
|
|
1031
|
-
* @param authorizationCode - The Google authorization code obtained from the mobile app.
|
|
1032
|
-
* @param redirectUri - The redirect URI used in the OAuth flow.
|
|
1033
|
-
* @param clientId - The platform-specific Google OAuth client ID.
|
|
1034
|
-
* @returns The updated user profile.
|
|
1035
|
-
*/
|
|
1036
|
-
async linkGoogleAccountWithAuthCode(
|
|
1037
|
-
authorizationCode: string,
|
|
1038
|
-
redirectUri: string,
|
|
1039
|
-
clientId: string,
|
|
1040
|
-
): Promise<User> {
|
|
1041
|
-
try {
|
|
1042
|
-
console.log('[AUTH] Linking Google account with authorization code (native flow)');
|
|
1043
|
-
console.log('[AUTH] Redirect URI:', redirectUri);
|
|
1044
|
-
console.log('[AUTH] Code length:', authorizationCode.length);
|
|
1045
|
-
|
|
1046
|
-
if (!clientId) {
|
|
1047
|
-
throw new Error('Google client ID is required for authorization code exchange');
|
|
1048
|
-
}
|
|
1049
|
-
|
|
1050
|
-
console.log('[AUTH] Using client ID:', `${clientId.substring(0, 20)}...`);
|
|
1051
|
-
|
|
1052
|
-
// Exchange authorization code for tokens using Google's OAuth2 API
|
|
1053
|
-
const tokenEndpoint = 'https://oauth2.googleapis.com/token';
|
|
1054
|
-
|
|
1055
|
-
const params = new URLSearchParams({
|
|
1056
|
-
client_id: clientId,
|
|
1057
|
-
code: authorizationCode,
|
|
1058
|
-
grant_type: 'authorization_code',
|
|
1059
|
-
redirect_uri: redirectUri,
|
|
1060
|
-
});
|
|
1061
|
-
|
|
1062
|
-
console.log('[AUTH] Making request to Google token endpoint...');
|
|
1063
|
-
|
|
1064
|
-
const response = await fetch(tokenEndpoint, {
|
|
1065
|
-
method: 'POST',
|
|
1066
|
-
headers: {
|
|
1067
|
-
'Content-Type': 'application/x-www-form-urlencoded',
|
|
1068
|
-
},
|
|
1069
|
-
body: params.toString(),
|
|
1070
|
-
});
|
|
1071
|
-
|
|
1072
|
-
if (!response.ok) {
|
|
1073
|
-
const errorText = await response.text();
|
|
1074
|
-
console.error('[AUTH] Google token exchange failed:', {
|
|
1075
|
-
status: response.status,
|
|
1076
|
-
statusText: response.statusText,
|
|
1077
|
-
error: errorText,
|
|
1078
|
-
});
|
|
1079
|
-
throw new Error(`Google token exchange failed: ${response.status} - ${errorText}`);
|
|
1080
|
-
}
|
|
1081
|
-
|
|
1082
|
-
const tokenData = await response.json();
|
|
1083
|
-
console.log('[AUTH] Token exchange response received:', {
|
|
1084
|
-
hasIdToken: !!tokenData.id_token,
|
|
1085
|
-
hasAccessToken: !!tokenData.access_token,
|
|
1086
|
-
hasRefreshToken: !!tokenData.refresh_token,
|
|
1087
|
-
});
|
|
1088
|
-
|
|
1089
|
-
if (!tokenData.id_token) {
|
|
1090
|
-
console.error('[AUTH] No ID token in response:', tokenData);
|
|
1091
|
-
throw new Error('No ID token received from Google token exchange');
|
|
1092
|
-
}
|
|
1093
|
-
|
|
1094
|
-
console.log('[AUTH] Successfully obtained ID token from Google');
|
|
1095
|
-
console.log('[AUTH] ID token length:', tokenData.id_token.length);
|
|
1096
|
-
|
|
1097
|
-
// Now link the Google account using the ID token
|
|
1098
|
-
return await this.linkGoogleAccount(tokenData.id_token);
|
|
1099
|
-
} catch (error) {
|
|
1100
|
-
console.error('[AUTH] Error in linkGoogleAccountWithAuthCode:', error);
|
|
1101
|
-
throw handleFirebaseError(error);
|
|
1102
|
-
}
|
|
1103
|
-
}
|
|
1104
952
|
}
|