@blackcode_sa/metaestetics-api 1.14.76 → 1.14.78
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/admin/index.js +1 -1
- package/dist/admin/index.mjs +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +4 -54
- package/dist/index.mjs +4 -54
- package/package.json +1 -1
- package/src/admin/mailing/clinicWelcome/clinicWelcome.mailing.ts +1 -1
- package/src/services/auth/auth.service.ts +8 -70
package/dist/admin/index.js
CHANGED
|
@@ -14325,7 +14325,7 @@ var ClinicWelcomeMailingService = class extends BaseMailingService {
|
|
|
14325
14325
|
*/
|
|
14326
14326
|
constructor(firestore19, mailgunClient) {
|
|
14327
14327
|
super(firestore19, mailgunClient);
|
|
14328
|
-
this.DEFAULT_DASHBOARD_URL = "https://
|
|
14328
|
+
this.DEFAULT_DASHBOARD_URL = "https://app.metaesthetics.net/dashboard";
|
|
14329
14329
|
this.DEFAULT_SUPPORT_EMAIL = "support@metaesthetics.net";
|
|
14330
14330
|
this.DEFAULT_SUBJECT = "Welcome to MetaEsthetics - Your Clinic Registration is Complete";
|
|
14331
14331
|
this.DEFAULT_MAILGUN_DOMAIN = "mg.metaesthetics.net";
|
package/dist/admin/index.mjs
CHANGED
|
@@ -14248,7 +14248,7 @@ var ClinicWelcomeMailingService = class extends BaseMailingService {
|
|
|
14248
14248
|
*/
|
|
14249
14249
|
constructor(firestore19, mailgunClient) {
|
|
14250
14250
|
super(firestore19, mailgunClient);
|
|
14251
|
-
this.DEFAULT_DASHBOARD_URL = "https://
|
|
14251
|
+
this.DEFAULT_DASHBOARD_URL = "https://app.metaesthetics.net/dashboard";
|
|
14252
14252
|
this.DEFAULT_SUPPORT_EMAIL = "support@metaesthetics.net";
|
|
14253
14253
|
this.DEFAULT_SUBJECT = "Welcome to MetaEsthetics - Your Clinic Registration is Complete";
|
|
14254
14254
|
this.DEFAULT_MAILGUN_DOMAIN = "mg.metaesthetics.net";
|
package/dist/index.d.mts
CHANGED
|
@@ -8620,8 +8620,8 @@ declare class AuthService extends BaseService {
|
|
|
8620
8620
|
*/
|
|
8621
8621
|
linkGoogleAccount(idToken: string): Promise<User>;
|
|
8622
8622
|
/**
|
|
8623
|
-
*
|
|
8624
|
-
*
|
|
8623
|
+
* Signs in or registers a user with an Apple ID token.
|
|
8624
|
+
* If the user does not exist, a new user is created.
|
|
8625
8625
|
*/
|
|
8626
8626
|
signInWithAppleIdToken(idToken: string, rawNonce: string, appleUserInfo?: {
|
|
8627
8627
|
fullName?: {
|
package/dist/index.d.ts
CHANGED
|
@@ -8620,8 +8620,8 @@ declare class AuthService extends BaseService {
|
|
|
8620
8620
|
*/
|
|
8621
8621
|
linkGoogleAccount(idToken: string): Promise<User>;
|
|
8622
8622
|
/**
|
|
8623
|
-
*
|
|
8624
|
-
*
|
|
8623
|
+
* Signs in or registers a user with an Apple ID token.
|
|
8624
|
+
* If the user does not exist, a new user is created.
|
|
8625
8625
|
*/
|
|
8626
8626
|
signInWithAppleIdToken(idToken: string, rawNonce: string, appleUserInfo?: {
|
|
8627
8627
|
fullName?: {
|
package/dist/index.js
CHANGED
|
@@ -16766,49 +16766,10 @@ var AuthService = class extends BaseService {
|
|
|
16766
16766
|
async signInWithGoogleIdToken(idToken, initialRole = "patient" /* PATIENT */) {
|
|
16767
16767
|
try {
|
|
16768
16768
|
console.log("[AUTH] Signing in with Google ID Token");
|
|
16769
|
-
let email;
|
|
16770
|
-
try {
|
|
16771
|
-
const payloadBase64 = idToken.split(".")[1];
|
|
16772
|
-
const payloadJson = globalThis.atob ? globalThis.atob(payloadBase64) : Buffer.from(payloadBase64, "base64").toString("utf8");
|
|
16773
|
-
const payload = JSON.parse(payloadJson);
|
|
16774
|
-
email = payload.email;
|
|
16775
|
-
} catch (decodeError) {
|
|
16776
|
-
console.warn("[AUTH] Failed to decode email from Google ID token:", decodeError);
|
|
16777
|
-
}
|
|
16778
|
-
if (!email) {
|
|
16779
|
-
throw new AuthError(
|
|
16780
|
-
"Unable to read email from Google token. Please try again or use another sign-in method.",
|
|
16781
|
-
"AUTH/INVALID_GOOGLE_TOKEN",
|
|
16782
|
-
400
|
|
16783
|
-
);
|
|
16784
|
-
}
|
|
16785
|
-
const methods = await (0, import_auth8.fetchSignInMethodsForEmail)(this.auth, email);
|
|
16786
|
-
console.log("[AUTH] Fetch sign in methods for email:", email, methods);
|
|
16787
|
-
const hasGoogleMethod = methods.includes(import_auth8.GoogleAuthProvider.GOOGLE_SIGN_IN_METHOD);
|
|
16788
|
-
console.log("[AUTH] Has Google method:", hasGoogleMethod);
|
|
16789
|
-
if (!hasGoogleMethod) {
|
|
16790
|
-
console.log("[AUTH] No existing Google credential for email, aborting login:", email);
|
|
16791
|
-
throw new AuthError(
|
|
16792
|
-
"No account found for this Google user. Please complete registration first.",
|
|
16793
|
-
"AUTH/USER_NOT_FOUND",
|
|
16794
|
-
404
|
|
16795
|
-
);
|
|
16796
|
-
}
|
|
16797
16769
|
const credential = import_auth8.GoogleAuthProvider.credential(idToken);
|
|
16798
16770
|
const { user: firebaseUser } = await (0, import_auth8.signInWithCredential)(this.auth, credential);
|
|
16799
16771
|
console.log("[AUTH] Firebase user signed in:", firebaseUser.uid);
|
|
16800
|
-
|
|
16801
|
-
if (existingUser) {
|
|
16802
|
-
console.log("[AUTH] Existing user found, returning profile:", existingUser.uid);
|
|
16803
|
-
return existingUser;
|
|
16804
|
-
}
|
|
16805
|
-
console.log("[AUTH] No existing MetaEstetics user for Google account \u2013 signing out.");
|
|
16806
|
-
await (0, import_auth8.signOut)(this.auth);
|
|
16807
|
-
throw new AuthError(
|
|
16808
|
-
'No account found. Please complete registration by starting with "Get Started".',
|
|
16809
|
-
"AUTH/USER_NOT_FOUND",
|
|
16810
|
-
404
|
|
16811
|
-
);
|
|
16772
|
+
return await this.userService.getOrCreateUser(firebaseUser, "patient" /* PATIENT */);
|
|
16812
16773
|
} catch (error) {
|
|
16813
16774
|
console.error("[AUTH] Error in signInWithGoogleIdToken:", error);
|
|
16814
16775
|
throw handleFirebaseError(error);
|
|
@@ -17046,8 +17007,8 @@ var AuthService = class extends BaseService {
|
|
|
17046
17007
|
}
|
|
17047
17008
|
}
|
|
17048
17009
|
/**
|
|
17049
|
-
*
|
|
17050
|
-
*
|
|
17010
|
+
* Signs in or registers a user with an Apple ID token.
|
|
17011
|
+
* If the user does not exist, a new user is created.
|
|
17051
17012
|
*/
|
|
17052
17013
|
async signInWithAppleIdToken(idToken, rawNonce, appleUserInfo) {
|
|
17053
17014
|
try {
|
|
@@ -17056,18 +17017,7 @@ var AuthService = class extends BaseService {
|
|
|
17056
17017
|
const credential = provider.credential({ idToken, rawNonce });
|
|
17057
17018
|
const { user: firebaseUser } = await (0, import_auth8.signInWithCredential)(this.auth, credential);
|
|
17058
17019
|
console.log("[AUTH] Firebase user signed in via Apple:", firebaseUser.uid);
|
|
17059
|
-
|
|
17060
|
-
if (existingUser) {
|
|
17061
|
-
console.log("[AUTH] Existing user found, returning profile:", existingUser.uid);
|
|
17062
|
-
return existingUser;
|
|
17063
|
-
}
|
|
17064
|
-
console.log("[AUTH] No existing MetaEstetics user for Apple account \u2013 signing out.");
|
|
17065
|
-
await (0, import_auth8.signOut)(this.auth);
|
|
17066
|
-
throw new AuthError(
|
|
17067
|
-
'No account found. Please complete registration by starting with "Get Started".',
|
|
17068
|
-
"AUTH/USER_NOT_FOUND",
|
|
17069
|
-
404
|
|
17070
|
-
);
|
|
17020
|
+
return await this.userService.getOrCreateUser(firebaseUser, "patient" /* PATIENT */);
|
|
17071
17021
|
} catch (error) {
|
|
17072
17022
|
console.error("[AUTH] Error in signInWithAppleIdToken:", error);
|
|
17073
17023
|
throw handleFirebaseError(error);
|
package/dist/index.mjs
CHANGED
|
@@ -16855,49 +16855,10 @@ var AuthService = class extends BaseService {
|
|
|
16855
16855
|
async signInWithGoogleIdToken(idToken, initialRole = "patient" /* PATIENT */) {
|
|
16856
16856
|
try {
|
|
16857
16857
|
console.log("[AUTH] Signing in with Google ID Token");
|
|
16858
|
-
let email;
|
|
16859
|
-
try {
|
|
16860
|
-
const payloadBase64 = idToken.split(".")[1];
|
|
16861
|
-
const payloadJson = globalThis.atob ? globalThis.atob(payloadBase64) : Buffer.from(payloadBase64, "base64").toString("utf8");
|
|
16862
|
-
const payload = JSON.parse(payloadJson);
|
|
16863
|
-
email = payload.email;
|
|
16864
|
-
} catch (decodeError) {
|
|
16865
|
-
console.warn("[AUTH] Failed to decode email from Google ID token:", decodeError);
|
|
16866
|
-
}
|
|
16867
|
-
if (!email) {
|
|
16868
|
-
throw new AuthError(
|
|
16869
|
-
"Unable to read email from Google token. Please try again or use another sign-in method.",
|
|
16870
|
-
"AUTH/INVALID_GOOGLE_TOKEN",
|
|
16871
|
-
400
|
|
16872
|
-
);
|
|
16873
|
-
}
|
|
16874
|
-
const methods = await fetchSignInMethodsForEmail2(this.auth, email);
|
|
16875
|
-
console.log("[AUTH] Fetch sign in methods for email:", email, methods);
|
|
16876
|
-
const hasGoogleMethod = methods.includes(GoogleAuthProvider.GOOGLE_SIGN_IN_METHOD);
|
|
16877
|
-
console.log("[AUTH] Has Google method:", hasGoogleMethod);
|
|
16878
|
-
if (!hasGoogleMethod) {
|
|
16879
|
-
console.log("[AUTH] No existing Google credential for email, aborting login:", email);
|
|
16880
|
-
throw new AuthError(
|
|
16881
|
-
"No account found for this Google user. Please complete registration first.",
|
|
16882
|
-
"AUTH/USER_NOT_FOUND",
|
|
16883
|
-
404
|
|
16884
|
-
);
|
|
16885
|
-
}
|
|
16886
16858
|
const credential = GoogleAuthProvider.credential(idToken);
|
|
16887
16859
|
const { user: firebaseUser } = await signInWithCredential(this.auth, credential);
|
|
16888
16860
|
console.log("[AUTH] Firebase user signed in:", firebaseUser.uid);
|
|
16889
|
-
|
|
16890
|
-
if (existingUser) {
|
|
16891
|
-
console.log("[AUTH] Existing user found, returning profile:", existingUser.uid);
|
|
16892
|
-
return existingUser;
|
|
16893
|
-
}
|
|
16894
|
-
console.log("[AUTH] No existing MetaEstetics user for Google account \u2013 signing out.");
|
|
16895
|
-
await firebaseSignOut(this.auth);
|
|
16896
|
-
throw new AuthError(
|
|
16897
|
-
'No account found. Please complete registration by starting with "Get Started".',
|
|
16898
|
-
"AUTH/USER_NOT_FOUND",
|
|
16899
|
-
404
|
|
16900
|
-
);
|
|
16861
|
+
return await this.userService.getOrCreateUser(firebaseUser, "patient" /* PATIENT */);
|
|
16901
16862
|
} catch (error) {
|
|
16902
16863
|
console.error("[AUTH] Error in signInWithGoogleIdToken:", error);
|
|
16903
16864
|
throw handleFirebaseError(error);
|
|
@@ -17135,8 +17096,8 @@ var AuthService = class extends BaseService {
|
|
|
17135
17096
|
}
|
|
17136
17097
|
}
|
|
17137
17098
|
/**
|
|
17138
|
-
*
|
|
17139
|
-
*
|
|
17099
|
+
* Signs in or registers a user with an Apple ID token.
|
|
17100
|
+
* If the user does not exist, a new user is created.
|
|
17140
17101
|
*/
|
|
17141
17102
|
async signInWithAppleIdToken(idToken, rawNonce, appleUserInfo) {
|
|
17142
17103
|
try {
|
|
@@ -17145,18 +17106,7 @@ var AuthService = class extends BaseService {
|
|
|
17145
17106
|
const credential = provider.credential({ idToken, rawNonce });
|
|
17146
17107
|
const { user: firebaseUser } = await signInWithCredential(this.auth, credential);
|
|
17147
17108
|
console.log("[AUTH] Firebase user signed in via Apple:", firebaseUser.uid);
|
|
17148
|
-
|
|
17149
|
-
if (existingUser) {
|
|
17150
|
-
console.log("[AUTH] Existing user found, returning profile:", existingUser.uid);
|
|
17151
|
-
return existingUser;
|
|
17152
|
-
}
|
|
17153
|
-
console.log("[AUTH] No existing MetaEstetics user for Apple account \u2013 signing out.");
|
|
17154
|
-
await firebaseSignOut(this.auth);
|
|
17155
|
-
throw new AuthError(
|
|
17156
|
-
'No account found. Please complete registration by starting with "Get Started".',
|
|
17157
|
-
"AUTH/USER_NOT_FOUND",
|
|
17158
|
-
404
|
|
17159
|
-
);
|
|
17109
|
+
return await this.userService.getOrCreateUser(firebaseUser, "patient" /* PATIENT */);
|
|
17160
17110
|
} catch (error) {
|
|
17161
17111
|
console.error("[AUTH] Error in signInWithAppleIdToken:", error);
|
|
17162
17112
|
throw handleFirebaseError(error);
|
package/package.json
CHANGED
|
@@ -45,7 +45,7 @@ export interface ClinicWelcomeEmailData {
|
|
|
45
45
|
*/
|
|
46
46
|
export class ClinicWelcomeMailingService extends BaseMailingService {
|
|
47
47
|
private readonly DEFAULT_DASHBOARD_URL =
|
|
48
|
-
"https://
|
|
48
|
+
"https://app.metaesthetics.net/dashboard";
|
|
49
49
|
private readonly DEFAULT_SUPPORT_EMAIL = "support@metaesthetics.net";
|
|
50
50
|
private readonly DEFAULT_SUBJECT =
|
|
51
51
|
"Welcome to MetaEsthetics - Your Clinic Registration is Complete";
|
|
@@ -1073,62 +1073,13 @@ export class AuthService extends BaseService {
|
|
|
1073
1073
|
try {
|
|
1074
1074
|
console.log('[AUTH] Signing in with Google ID Token');
|
|
1075
1075
|
|
|
1076
|
-
//
|
|
1077
|
-
let email: string | undefined;
|
|
1078
|
-
try {
|
|
1079
|
-
const payloadBase64 = idToken.split('.')[1];
|
|
1080
|
-
const payloadJson = globalThis.atob
|
|
1081
|
-
? globalThis.atob(payloadBase64)
|
|
1082
|
-
: Buffer.from(payloadBase64, 'base64').toString('utf8');
|
|
1083
|
-
const payload = JSON.parse(payloadJson);
|
|
1084
|
-
email = payload.email as string | undefined;
|
|
1085
|
-
} catch (decodeError) {
|
|
1086
|
-
console.warn('[AUTH] Failed to decode email from Google ID token:', decodeError);
|
|
1087
|
-
}
|
|
1088
|
-
|
|
1089
|
-
if (!email) {
|
|
1090
|
-
throw new AuthError(
|
|
1091
|
-
'Unable to read email from Google token. Please try again or use another sign-in method.',
|
|
1092
|
-
'AUTH/INVALID_GOOGLE_TOKEN',
|
|
1093
|
-
400,
|
|
1094
|
-
);
|
|
1095
|
-
}
|
|
1096
|
-
|
|
1097
|
-
// 2) Check if this email already has a Google credential in Firebase Auth.
|
|
1098
|
-
// If not, abort early so we *never* create an unwanted Auth user.
|
|
1099
|
-
const methods = await fetchSignInMethodsForEmail(this.auth, email);
|
|
1100
|
-
console.log('[AUTH] Fetch sign in methods for email:', email, methods);
|
|
1101
|
-
const hasGoogleMethod = methods.includes(GoogleAuthProvider.GOOGLE_SIGN_IN_METHOD);
|
|
1102
|
-
console.log('[AUTH] Has Google method:', hasGoogleMethod);
|
|
1103
|
-
if (!hasGoogleMethod) {
|
|
1104
|
-
console.log('[AUTH] No existing Google credential for email, aborting login:', email);
|
|
1105
|
-
throw new AuthError(
|
|
1106
|
-
'No account found for this Google user. Please complete registration first.',
|
|
1107
|
-
'AUTH/USER_NOT_FOUND',
|
|
1108
|
-
404,
|
|
1109
|
-
);
|
|
1110
|
-
}
|
|
1111
|
-
|
|
1112
|
-
// 3) Safe to sign-in – we know the credential belongs to an existing Auth account.
|
|
1076
|
+
// Sign in with Google credential — auto-creates Firebase Auth user if needed.
|
|
1113
1077
|
const credential = GoogleAuthProvider.credential(idToken);
|
|
1114
1078
|
const { user: firebaseUser } = await signInWithCredential(this.auth, credential);
|
|
1115
1079
|
console.log('[AUTH] Firebase user signed in:', firebaseUser.uid);
|
|
1116
1080
|
|
|
1117
|
-
//
|
|
1118
|
-
|
|
1119
|
-
if (existingUser) {
|
|
1120
|
-
console.log('[AUTH] Existing user found, returning profile:', existingUser.uid);
|
|
1121
|
-
return existingUser;
|
|
1122
|
-
}
|
|
1123
|
-
|
|
1124
|
-
// 5) If no profile exists we sign out immediately and error – but crucially no phantom user was created.
|
|
1125
|
-
console.log('[AUTH] No existing MetaEstetics user for Google account – signing out.');
|
|
1126
|
-
await firebaseSignOut(this.auth);
|
|
1127
|
-
throw new AuthError(
|
|
1128
|
-
'No account found. Please complete registration by starting with "Get Started".',
|
|
1129
|
-
'AUTH/USER_NOT_FOUND',
|
|
1130
|
-
404,
|
|
1131
|
-
);
|
|
1081
|
+
// Load or create domain user document
|
|
1082
|
+
return await this.userService.getOrCreateUser(firebaseUser, UserRole.PATIENT);
|
|
1132
1083
|
} catch (error) {
|
|
1133
1084
|
console.error('[AUTH] Error in signInWithGoogleIdToken:', error);
|
|
1134
1085
|
throw handleFirebaseError(error);
|
|
@@ -1418,8 +1369,8 @@ export class AuthService extends BaseService {
|
|
|
1418
1369
|
}
|
|
1419
1370
|
|
|
1420
1371
|
/**
|
|
1421
|
-
*
|
|
1422
|
-
*
|
|
1372
|
+
* Signs in or registers a user with an Apple ID token.
|
|
1373
|
+
* If the user does not exist, a new user is created.
|
|
1423
1374
|
*/
|
|
1424
1375
|
async signInWithAppleIdToken(
|
|
1425
1376
|
idToken: string,
|
|
@@ -1433,25 +1384,12 @@ export class AuthService extends BaseService {
|
|
|
1433
1384
|
const provider = new OAuthProvider('apple.com');
|
|
1434
1385
|
const credential = provider.credential({ idToken, rawNonce });
|
|
1435
1386
|
|
|
1436
|
-
// Sign in to Firebase
|
|
1387
|
+
// Sign in to Firebase — auto-creates Firebase Auth user if needed
|
|
1437
1388
|
const { user: firebaseUser } = await signInWithCredential(this.auth, credential);
|
|
1438
1389
|
console.log('[AUTH] Firebase user signed in via Apple:', firebaseUser.uid);
|
|
1439
1390
|
|
|
1440
|
-
// Load domain user document
|
|
1441
|
-
|
|
1442
|
-
if (existingUser) {
|
|
1443
|
-
console.log('[AUTH] Existing user found, returning profile:', existingUser.uid);
|
|
1444
|
-
return existingUser;
|
|
1445
|
-
}
|
|
1446
|
-
|
|
1447
|
-
// No user document — sign out and error
|
|
1448
|
-
console.log('[AUTH] No existing MetaEstetics user for Apple account – signing out.');
|
|
1449
|
-
await firebaseSignOut(this.auth);
|
|
1450
|
-
throw new AuthError(
|
|
1451
|
-
'No account found. Please complete registration by starting with "Get Started".',
|
|
1452
|
-
'AUTH/USER_NOT_FOUND',
|
|
1453
|
-
404,
|
|
1454
|
-
);
|
|
1391
|
+
// Load or create domain user document
|
|
1392
|
+
return await this.userService.getOrCreateUser(firebaseUser, UserRole.PATIENT);
|
|
1455
1393
|
} catch (error) {
|
|
1456
1394
|
console.error('[AUTH] Error in signInWithAppleIdToken:', error);
|
|
1457
1395
|
throw handleFirebaseError(error);
|