@blackcode_sa/metaestetics-api 1.14.73 → 1.14.77
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 +8 -4
- package/dist/index.d.ts +8 -4
- package/dist/index.js +12 -57
- package/dist/index.mjs +12 -57
- package/package.json +1 -1
- package/src/services/auth/auth.service.ts +13 -71
- package/src/services/user/user.service.ts +8 -2
package/dist/index.d.mts
CHANGED
|
@@ -8414,7 +8414,9 @@ declare class UserService extends BaseService {
|
|
|
8414
8414
|
/**
|
|
8415
8415
|
* Dohvata ili kreira korisnika na osnovu Firebase korisnika
|
|
8416
8416
|
*/
|
|
8417
|
-
getOrCreateUser(firebaseUser: User$1, initialRole?: UserRole
|
|
8417
|
+
getOrCreateUser(firebaseUser: User$1, initialRole?: UserRole, options?: {
|
|
8418
|
+
skipProfileCreation?: boolean;
|
|
8419
|
+
}): Promise<User>;
|
|
8418
8420
|
/**
|
|
8419
8421
|
* Kreira profile za odgovarajuće role
|
|
8420
8422
|
*/
|
|
@@ -8507,7 +8509,9 @@ declare class AuthService extends BaseService {
|
|
|
8507
8509
|
/**
|
|
8508
8510
|
* Prijavljuje korisnika anonimno
|
|
8509
8511
|
*/
|
|
8510
|
-
signInAnonymously(
|
|
8512
|
+
signInAnonymously(options?: {
|
|
8513
|
+
skipProfileCreation?: boolean;
|
|
8514
|
+
}): Promise<User>;
|
|
8511
8515
|
/**
|
|
8512
8516
|
* Odjavljuje trenutnog korisnika
|
|
8513
8517
|
*/
|
|
@@ -8616,8 +8620,8 @@ declare class AuthService extends BaseService {
|
|
|
8616
8620
|
*/
|
|
8617
8621
|
linkGoogleAccount(idToken: string): Promise<User>;
|
|
8618
8622
|
/**
|
|
8619
|
-
*
|
|
8620
|
-
*
|
|
8623
|
+
* Signs in or registers a user with an Apple ID token.
|
|
8624
|
+
* If the user does not exist, a new user is created.
|
|
8621
8625
|
*/
|
|
8622
8626
|
signInWithAppleIdToken(idToken: string, rawNonce: string, appleUserInfo?: {
|
|
8623
8627
|
fullName?: {
|
package/dist/index.d.ts
CHANGED
|
@@ -8414,7 +8414,9 @@ declare class UserService extends BaseService {
|
|
|
8414
8414
|
/**
|
|
8415
8415
|
* Dohvata ili kreira korisnika na osnovu Firebase korisnika
|
|
8416
8416
|
*/
|
|
8417
|
-
getOrCreateUser(firebaseUser: User$1, initialRole?: UserRole
|
|
8417
|
+
getOrCreateUser(firebaseUser: User$1, initialRole?: UserRole, options?: {
|
|
8418
|
+
skipProfileCreation?: boolean;
|
|
8419
|
+
}): Promise<User>;
|
|
8418
8420
|
/**
|
|
8419
8421
|
* Kreira profile za odgovarajuće role
|
|
8420
8422
|
*/
|
|
@@ -8507,7 +8509,9 @@ declare class AuthService extends BaseService {
|
|
|
8507
8509
|
/**
|
|
8508
8510
|
* Prijavljuje korisnika anonimno
|
|
8509
8511
|
*/
|
|
8510
|
-
signInAnonymously(
|
|
8512
|
+
signInAnonymously(options?: {
|
|
8513
|
+
skipProfileCreation?: boolean;
|
|
8514
|
+
}): Promise<User>;
|
|
8511
8515
|
/**
|
|
8512
8516
|
* Odjavljuje trenutnog korisnika
|
|
8513
8517
|
*/
|
|
@@ -8616,8 +8620,8 @@ declare class AuthService extends BaseService {
|
|
|
8616
8620
|
*/
|
|
8617
8621
|
linkGoogleAccount(idToken: string): Promise<User>;
|
|
8618
8622
|
/**
|
|
8619
|
-
*
|
|
8620
|
-
*
|
|
8623
|
+
* Signs in or registers a user with an Apple ID token.
|
|
8624
|
+
* If the user does not exist, a new user is created.
|
|
8621
8625
|
*/
|
|
8622
8626
|
signInWithAppleIdToken(idToken: string, rawNonce: string, appleUserInfo?: {
|
|
8623
8627
|
fullName?: {
|
package/dist/index.js
CHANGED
|
@@ -13560,13 +13560,15 @@ var UserService = class extends BaseService {
|
|
|
13560
13560
|
/**
|
|
13561
13561
|
* Dohvata ili kreira korisnika na osnovu Firebase korisnika
|
|
13562
13562
|
*/
|
|
13563
|
-
async getOrCreateUser(firebaseUser, initialRole) {
|
|
13563
|
+
async getOrCreateUser(firebaseUser, initialRole, options) {
|
|
13564
13564
|
try {
|
|
13565
13565
|
const existingUser = await this.getUserById(firebaseUser.uid);
|
|
13566
13566
|
await this.updateUserLoginTimestamp(firebaseUser.uid);
|
|
13567
13567
|
return existingUser;
|
|
13568
13568
|
} catch (error) {
|
|
13569
|
-
return this.createUser(firebaseUser, [initialRole || "patient" /* PATIENT */]
|
|
13569
|
+
return this.createUser(firebaseUser, [initialRole || "patient" /* PATIENT */], {
|
|
13570
|
+
skipProfileCreation: options == null ? void 0 : options.skipProfileCreation
|
|
13571
|
+
});
|
|
13570
13572
|
}
|
|
13571
13573
|
}
|
|
13572
13574
|
/**
|
|
@@ -16381,8 +16383,11 @@ var AuthService = class extends BaseService {
|
|
|
16381
16383
|
/**
|
|
16382
16384
|
* Prijavljuje korisnika anonimno
|
|
16383
16385
|
*/
|
|
16384
|
-
async signInAnonymously() {
|
|
16386
|
+
async signInAnonymously(options) {
|
|
16385
16387
|
const { user: firebaseUser } = await (0, import_auth8.signInAnonymously)(this.auth);
|
|
16388
|
+
if (options == null ? void 0 : options.skipProfileCreation) {
|
|
16389
|
+
return this.userService.getOrCreateUser(firebaseUser, "patient" /* PATIENT */, { skipProfileCreation: true });
|
|
16390
|
+
}
|
|
16386
16391
|
return this.userService.getOrCreateUser(firebaseUser);
|
|
16387
16392
|
}
|
|
16388
16393
|
/**
|
|
@@ -16761,49 +16766,10 @@ var AuthService = class extends BaseService {
|
|
|
16761
16766
|
async signInWithGoogleIdToken(idToken, initialRole = "patient" /* PATIENT */) {
|
|
16762
16767
|
try {
|
|
16763
16768
|
console.log("[AUTH] Signing in with Google ID Token");
|
|
16764
|
-
let email;
|
|
16765
|
-
try {
|
|
16766
|
-
const payloadBase64 = idToken.split(".")[1];
|
|
16767
|
-
const payloadJson = globalThis.atob ? globalThis.atob(payloadBase64) : Buffer.from(payloadBase64, "base64").toString("utf8");
|
|
16768
|
-
const payload = JSON.parse(payloadJson);
|
|
16769
|
-
email = payload.email;
|
|
16770
|
-
} catch (decodeError) {
|
|
16771
|
-
console.warn("[AUTH] Failed to decode email from Google ID token:", decodeError);
|
|
16772
|
-
}
|
|
16773
|
-
if (!email) {
|
|
16774
|
-
throw new AuthError(
|
|
16775
|
-
"Unable to read email from Google token. Please try again or use another sign-in method.",
|
|
16776
|
-
"AUTH/INVALID_GOOGLE_TOKEN",
|
|
16777
|
-
400
|
|
16778
|
-
);
|
|
16779
|
-
}
|
|
16780
|
-
const methods = await (0, import_auth8.fetchSignInMethodsForEmail)(this.auth, email);
|
|
16781
|
-
console.log("[AUTH] Fetch sign in methods for email:", email, methods);
|
|
16782
|
-
const hasGoogleMethod = methods.includes(import_auth8.GoogleAuthProvider.GOOGLE_SIGN_IN_METHOD);
|
|
16783
|
-
console.log("[AUTH] Has Google method:", hasGoogleMethod);
|
|
16784
|
-
if (!hasGoogleMethod) {
|
|
16785
|
-
console.log("[AUTH] No existing Google credential for email, aborting login:", email);
|
|
16786
|
-
throw new AuthError(
|
|
16787
|
-
"No account found for this Google user. Please complete registration first.",
|
|
16788
|
-
"AUTH/USER_NOT_FOUND",
|
|
16789
|
-
404
|
|
16790
|
-
);
|
|
16791
|
-
}
|
|
16792
16769
|
const credential = import_auth8.GoogleAuthProvider.credential(idToken);
|
|
16793
16770
|
const { user: firebaseUser } = await (0, import_auth8.signInWithCredential)(this.auth, credential);
|
|
16794
16771
|
console.log("[AUTH] Firebase user signed in:", firebaseUser.uid);
|
|
16795
|
-
|
|
16796
|
-
if (existingUser) {
|
|
16797
|
-
console.log("[AUTH] Existing user found, returning profile:", existingUser.uid);
|
|
16798
|
-
return existingUser;
|
|
16799
|
-
}
|
|
16800
|
-
console.log("[AUTH] No existing MetaEstetics user for Google account \u2013 signing out.");
|
|
16801
|
-
await (0, import_auth8.signOut)(this.auth);
|
|
16802
|
-
throw new AuthError(
|
|
16803
|
-
'No account found. Please complete registration by starting with "Get Started".',
|
|
16804
|
-
"AUTH/USER_NOT_FOUND",
|
|
16805
|
-
404
|
|
16806
|
-
);
|
|
16772
|
+
return await this.userService.getOrCreateUser(firebaseUser, "patient" /* PATIENT */);
|
|
16807
16773
|
} catch (error) {
|
|
16808
16774
|
console.error("[AUTH] Error in signInWithGoogleIdToken:", error);
|
|
16809
16775
|
throw handleFirebaseError(error);
|
|
@@ -17041,8 +17007,8 @@ var AuthService = class extends BaseService {
|
|
|
17041
17007
|
}
|
|
17042
17008
|
}
|
|
17043
17009
|
/**
|
|
17044
|
-
*
|
|
17045
|
-
*
|
|
17010
|
+
* Signs in or registers a user with an Apple ID token.
|
|
17011
|
+
* If the user does not exist, a new user is created.
|
|
17046
17012
|
*/
|
|
17047
17013
|
async signInWithAppleIdToken(idToken, rawNonce, appleUserInfo) {
|
|
17048
17014
|
try {
|
|
@@ -17051,18 +17017,7 @@ var AuthService = class extends BaseService {
|
|
|
17051
17017
|
const credential = provider.credential({ idToken, rawNonce });
|
|
17052
17018
|
const { user: firebaseUser } = await (0, import_auth8.signInWithCredential)(this.auth, credential);
|
|
17053
17019
|
console.log("[AUTH] Firebase user signed in via Apple:", firebaseUser.uid);
|
|
17054
|
-
|
|
17055
|
-
if (existingUser) {
|
|
17056
|
-
console.log("[AUTH] Existing user found, returning profile:", existingUser.uid);
|
|
17057
|
-
return existingUser;
|
|
17058
|
-
}
|
|
17059
|
-
console.log("[AUTH] No existing MetaEstetics user for Apple account \u2013 signing out.");
|
|
17060
|
-
await (0, import_auth8.signOut)(this.auth);
|
|
17061
|
-
throw new AuthError(
|
|
17062
|
-
'No account found. Please complete registration by starting with "Get Started".',
|
|
17063
|
-
"AUTH/USER_NOT_FOUND",
|
|
17064
|
-
404
|
|
17065
|
-
);
|
|
17020
|
+
return await this.userService.getOrCreateUser(firebaseUser, "patient" /* PATIENT */);
|
|
17066
17021
|
} catch (error) {
|
|
17067
17022
|
console.error("[AUTH] Error in signInWithAppleIdToken:", error);
|
|
17068
17023
|
throw handleFirebaseError(error);
|
package/dist/index.mjs
CHANGED
|
@@ -13585,13 +13585,15 @@ var UserService = class extends BaseService {
|
|
|
13585
13585
|
/**
|
|
13586
13586
|
* Dohvata ili kreira korisnika na osnovu Firebase korisnika
|
|
13587
13587
|
*/
|
|
13588
|
-
async getOrCreateUser(firebaseUser, initialRole) {
|
|
13588
|
+
async getOrCreateUser(firebaseUser, initialRole, options) {
|
|
13589
13589
|
try {
|
|
13590
13590
|
const existingUser = await this.getUserById(firebaseUser.uid);
|
|
13591
13591
|
await this.updateUserLoginTimestamp(firebaseUser.uid);
|
|
13592
13592
|
return existingUser;
|
|
13593
13593
|
} catch (error) {
|
|
13594
|
-
return this.createUser(firebaseUser, [initialRole || "patient" /* PATIENT */]
|
|
13594
|
+
return this.createUser(firebaseUser, [initialRole || "patient" /* PATIENT */], {
|
|
13595
|
+
skipProfileCreation: options == null ? void 0 : options.skipProfileCreation
|
|
13596
|
+
});
|
|
13595
13597
|
}
|
|
13596
13598
|
}
|
|
13597
13599
|
/**
|
|
@@ -16470,8 +16472,11 @@ var AuthService = class extends BaseService {
|
|
|
16470
16472
|
/**
|
|
16471
16473
|
* Prijavljuje korisnika anonimno
|
|
16472
16474
|
*/
|
|
16473
|
-
async signInAnonymously() {
|
|
16475
|
+
async signInAnonymously(options) {
|
|
16474
16476
|
const { user: firebaseUser } = await firebaseSignInAnonymously(this.auth);
|
|
16477
|
+
if (options == null ? void 0 : options.skipProfileCreation) {
|
|
16478
|
+
return this.userService.getOrCreateUser(firebaseUser, "patient" /* PATIENT */, { skipProfileCreation: true });
|
|
16479
|
+
}
|
|
16475
16480
|
return this.userService.getOrCreateUser(firebaseUser);
|
|
16476
16481
|
}
|
|
16477
16482
|
/**
|
|
@@ -16850,49 +16855,10 @@ var AuthService = class extends BaseService {
|
|
|
16850
16855
|
async signInWithGoogleIdToken(idToken, initialRole = "patient" /* PATIENT */) {
|
|
16851
16856
|
try {
|
|
16852
16857
|
console.log("[AUTH] Signing in with Google ID Token");
|
|
16853
|
-
let email;
|
|
16854
|
-
try {
|
|
16855
|
-
const payloadBase64 = idToken.split(".")[1];
|
|
16856
|
-
const payloadJson = globalThis.atob ? globalThis.atob(payloadBase64) : Buffer.from(payloadBase64, "base64").toString("utf8");
|
|
16857
|
-
const payload = JSON.parse(payloadJson);
|
|
16858
|
-
email = payload.email;
|
|
16859
|
-
} catch (decodeError) {
|
|
16860
|
-
console.warn("[AUTH] Failed to decode email from Google ID token:", decodeError);
|
|
16861
|
-
}
|
|
16862
|
-
if (!email) {
|
|
16863
|
-
throw new AuthError(
|
|
16864
|
-
"Unable to read email from Google token. Please try again or use another sign-in method.",
|
|
16865
|
-
"AUTH/INVALID_GOOGLE_TOKEN",
|
|
16866
|
-
400
|
|
16867
|
-
);
|
|
16868
|
-
}
|
|
16869
|
-
const methods = await fetchSignInMethodsForEmail2(this.auth, email);
|
|
16870
|
-
console.log("[AUTH] Fetch sign in methods for email:", email, methods);
|
|
16871
|
-
const hasGoogleMethod = methods.includes(GoogleAuthProvider.GOOGLE_SIGN_IN_METHOD);
|
|
16872
|
-
console.log("[AUTH] Has Google method:", hasGoogleMethod);
|
|
16873
|
-
if (!hasGoogleMethod) {
|
|
16874
|
-
console.log("[AUTH] No existing Google credential for email, aborting login:", email);
|
|
16875
|
-
throw new AuthError(
|
|
16876
|
-
"No account found for this Google user. Please complete registration first.",
|
|
16877
|
-
"AUTH/USER_NOT_FOUND",
|
|
16878
|
-
404
|
|
16879
|
-
);
|
|
16880
|
-
}
|
|
16881
16858
|
const credential = GoogleAuthProvider.credential(idToken);
|
|
16882
16859
|
const { user: firebaseUser } = await signInWithCredential(this.auth, credential);
|
|
16883
16860
|
console.log("[AUTH] Firebase user signed in:", firebaseUser.uid);
|
|
16884
|
-
|
|
16885
|
-
if (existingUser) {
|
|
16886
|
-
console.log("[AUTH] Existing user found, returning profile:", existingUser.uid);
|
|
16887
|
-
return existingUser;
|
|
16888
|
-
}
|
|
16889
|
-
console.log("[AUTH] No existing MetaEstetics user for Google account \u2013 signing out.");
|
|
16890
|
-
await firebaseSignOut(this.auth);
|
|
16891
|
-
throw new AuthError(
|
|
16892
|
-
'No account found. Please complete registration by starting with "Get Started".',
|
|
16893
|
-
"AUTH/USER_NOT_FOUND",
|
|
16894
|
-
404
|
|
16895
|
-
);
|
|
16861
|
+
return await this.userService.getOrCreateUser(firebaseUser, "patient" /* PATIENT */);
|
|
16896
16862
|
} catch (error) {
|
|
16897
16863
|
console.error("[AUTH] Error in signInWithGoogleIdToken:", error);
|
|
16898
16864
|
throw handleFirebaseError(error);
|
|
@@ -17130,8 +17096,8 @@ var AuthService = class extends BaseService {
|
|
|
17130
17096
|
}
|
|
17131
17097
|
}
|
|
17132
17098
|
/**
|
|
17133
|
-
*
|
|
17134
|
-
*
|
|
17099
|
+
* Signs in or registers a user with an Apple ID token.
|
|
17100
|
+
* If the user does not exist, a new user is created.
|
|
17135
17101
|
*/
|
|
17136
17102
|
async signInWithAppleIdToken(idToken, rawNonce, appleUserInfo) {
|
|
17137
17103
|
try {
|
|
@@ -17140,18 +17106,7 @@ var AuthService = class extends BaseService {
|
|
|
17140
17106
|
const credential = provider.credential({ idToken, rawNonce });
|
|
17141
17107
|
const { user: firebaseUser } = await signInWithCredential(this.auth, credential);
|
|
17142
17108
|
console.log("[AUTH] Firebase user signed in via Apple:", firebaseUser.uid);
|
|
17143
|
-
|
|
17144
|
-
if (existingUser) {
|
|
17145
|
-
console.log("[AUTH] Existing user found, returning profile:", existingUser.uid);
|
|
17146
|
-
return existingUser;
|
|
17147
|
-
}
|
|
17148
|
-
console.log("[AUTH] No existing MetaEstetics user for Apple account \u2013 signing out.");
|
|
17149
|
-
await firebaseSignOut(this.auth);
|
|
17150
|
-
throw new AuthError(
|
|
17151
|
-
'No account found. Please complete registration by starting with "Get Started".',
|
|
17152
|
-
"AUTH/USER_NOT_FOUND",
|
|
17153
|
-
404
|
|
17154
|
-
);
|
|
17109
|
+
return await this.userService.getOrCreateUser(firebaseUser, "patient" /* PATIENT */);
|
|
17155
17110
|
} catch (error) {
|
|
17156
17111
|
console.error("[AUTH] Error in signInWithAppleIdToken:", error);
|
|
17157
17112
|
throw handleFirebaseError(error);
|
package/package.json
CHANGED
|
@@ -563,9 +563,13 @@ export class AuthService extends BaseService {
|
|
|
563
563
|
/**
|
|
564
564
|
* Prijavljuje korisnika anonimno
|
|
565
565
|
*/
|
|
566
|
-
async signInAnonymously(): Promise<User> {
|
|
566
|
+
async signInAnonymously(options?: { skipProfileCreation?: boolean }): Promise<User> {
|
|
567
567
|
const { user: firebaseUser } = await firebaseSignInAnonymously(this.auth);
|
|
568
568
|
|
|
569
|
+
if (options?.skipProfileCreation) {
|
|
570
|
+
return this.userService.getOrCreateUser(firebaseUser, UserRole.PATIENT, { skipProfileCreation: true });
|
|
571
|
+
}
|
|
572
|
+
|
|
569
573
|
return this.userService.getOrCreateUser(firebaseUser);
|
|
570
574
|
}
|
|
571
575
|
|
|
@@ -1069,62 +1073,13 @@ export class AuthService extends BaseService {
|
|
|
1069
1073
|
try {
|
|
1070
1074
|
console.log('[AUTH] Signing in with Google ID Token');
|
|
1071
1075
|
|
|
1072
|
-
//
|
|
1073
|
-
let email: string | undefined;
|
|
1074
|
-
try {
|
|
1075
|
-
const payloadBase64 = idToken.split('.')[1];
|
|
1076
|
-
const payloadJson = globalThis.atob
|
|
1077
|
-
? globalThis.atob(payloadBase64)
|
|
1078
|
-
: Buffer.from(payloadBase64, 'base64').toString('utf8');
|
|
1079
|
-
const payload = JSON.parse(payloadJson);
|
|
1080
|
-
email = payload.email as string | undefined;
|
|
1081
|
-
} catch (decodeError) {
|
|
1082
|
-
console.warn('[AUTH] Failed to decode email from Google ID token:', decodeError);
|
|
1083
|
-
}
|
|
1084
|
-
|
|
1085
|
-
if (!email) {
|
|
1086
|
-
throw new AuthError(
|
|
1087
|
-
'Unable to read email from Google token. Please try again or use another sign-in method.',
|
|
1088
|
-
'AUTH/INVALID_GOOGLE_TOKEN',
|
|
1089
|
-
400,
|
|
1090
|
-
);
|
|
1091
|
-
}
|
|
1092
|
-
|
|
1093
|
-
// 2) Check if this email already has a Google credential in Firebase Auth.
|
|
1094
|
-
// If not, abort early so we *never* create an unwanted Auth user.
|
|
1095
|
-
const methods = await fetchSignInMethodsForEmail(this.auth, email);
|
|
1096
|
-
console.log('[AUTH] Fetch sign in methods for email:', email, methods);
|
|
1097
|
-
const hasGoogleMethod = methods.includes(GoogleAuthProvider.GOOGLE_SIGN_IN_METHOD);
|
|
1098
|
-
console.log('[AUTH] Has Google method:', hasGoogleMethod);
|
|
1099
|
-
if (!hasGoogleMethod) {
|
|
1100
|
-
console.log('[AUTH] No existing Google credential for email, aborting login:', email);
|
|
1101
|
-
throw new AuthError(
|
|
1102
|
-
'No account found for this Google user. Please complete registration first.',
|
|
1103
|
-
'AUTH/USER_NOT_FOUND',
|
|
1104
|
-
404,
|
|
1105
|
-
);
|
|
1106
|
-
}
|
|
1107
|
-
|
|
1108
|
-
// 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.
|
|
1109
1077
|
const credential = GoogleAuthProvider.credential(idToken);
|
|
1110
1078
|
const { user: firebaseUser } = await signInWithCredential(this.auth, credential);
|
|
1111
1079
|
console.log('[AUTH] Firebase user signed in:', firebaseUser.uid);
|
|
1112
1080
|
|
|
1113
|
-
//
|
|
1114
|
-
|
|
1115
|
-
if (existingUser) {
|
|
1116
|
-
console.log('[AUTH] Existing user found, returning profile:', existingUser.uid);
|
|
1117
|
-
return existingUser;
|
|
1118
|
-
}
|
|
1119
|
-
|
|
1120
|
-
// 5) If no profile exists we sign out immediately and error – but crucially no phantom user was created.
|
|
1121
|
-
console.log('[AUTH] No existing MetaEstetics user for Google account – signing out.');
|
|
1122
|
-
await firebaseSignOut(this.auth);
|
|
1123
|
-
throw new AuthError(
|
|
1124
|
-
'No account found. Please complete registration by starting with "Get Started".',
|
|
1125
|
-
'AUTH/USER_NOT_FOUND',
|
|
1126
|
-
404,
|
|
1127
|
-
);
|
|
1081
|
+
// Load or create domain user document
|
|
1082
|
+
return await this.userService.getOrCreateUser(firebaseUser, UserRole.PATIENT);
|
|
1128
1083
|
} catch (error) {
|
|
1129
1084
|
console.error('[AUTH] Error in signInWithGoogleIdToken:', error);
|
|
1130
1085
|
throw handleFirebaseError(error);
|
|
@@ -1414,8 +1369,8 @@ export class AuthService extends BaseService {
|
|
|
1414
1369
|
}
|
|
1415
1370
|
|
|
1416
1371
|
/**
|
|
1417
|
-
*
|
|
1418
|
-
*
|
|
1372
|
+
* Signs in or registers a user with an Apple ID token.
|
|
1373
|
+
* If the user does not exist, a new user is created.
|
|
1419
1374
|
*/
|
|
1420
1375
|
async signInWithAppleIdToken(
|
|
1421
1376
|
idToken: string,
|
|
@@ -1429,25 +1384,12 @@ export class AuthService extends BaseService {
|
|
|
1429
1384
|
const provider = new OAuthProvider('apple.com');
|
|
1430
1385
|
const credential = provider.credential({ idToken, rawNonce });
|
|
1431
1386
|
|
|
1432
|
-
// Sign in to Firebase
|
|
1387
|
+
// Sign in to Firebase — auto-creates Firebase Auth user if needed
|
|
1433
1388
|
const { user: firebaseUser } = await signInWithCredential(this.auth, credential);
|
|
1434
1389
|
console.log('[AUTH] Firebase user signed in via Apple:', firebaseUser.uid);
|
|
1435
1390
|
|
|
1436
|
-
// Load domain user document
|
|
1437
|
-
|
|
1438
|
-
if (existingUser) {
|
|
1439
|
-
console.log('[AUTH] Existing user found, returning profile:', existingUser.uid);
|
|
1440
|
-
return existingUser;
|
|
1441
|
-
}
|
|
1442
|
-
|
|
1443
|
-
// No user document — sign out and error
|
|
1444
|
-
console.log('[AUTH] No existing MetaEstetics user for Apple account – signing out.');
|
|
1445
|
-
await firebaseSignOut(this.auth);
|
|
1446
|
-
throw new AuthError(
|
|
1447
|
-
'No account found. Please complete registration by starting with "Get Started".',
|
|
1448
|
-
'AUTH/USER_NOT_FOUND',
|
|
1449
|
-
404,
|
|
1450
|
-
);
|
|
1391
|
+
// Load or create domain user document
|
|
1392
|
+
return await this.userService.getOrCreateUser(firebaseUser, UserRole.PATIENT);
|
|
1451
1393
|
} catch (error) {
|
|
1452
1394
|
console.error('[AUTH] Error in signInWithAppleIdToken:', error);
|
|
1453
1395
|
throw handleFirebaseError(error);
|
|
@@ -116,13 +116,19 @@ export class UserService extends BaseService {
|
|
|
116
116
|
/**
|
|
117
117
|
* Dohvata ili kreira korisnika na osnovu Firebase korisnika
|
|
118
118
|
*/
|
|
119
|
-
async getOrCreateUser(
|
|
119
|
+
async getOrCreateUser(
|
|
120
|
+
firebaseUser: FirebaseUser,
|
|
121
|
+
initialRole?: UserRole,
|
|
122
|
+
options?: { skipProfileCreation?: boolean },
|
|
123
|
+
): Promise<User> {
|
|
120
124
|
try {
|
|
121
125
|
const existingUser = await this.getUserById(firebaseUser.uid);
|
|
122
126
|
await this.updateUserLoginTimestamp(firebaseUser.uid);
|
|
123
127
|
return existingUser;
|
|
124
128
|
} catch (error) {
|
|
125
|
-
return this.createUser(firebaseUser, [initialRole || UserRole.PATIENT]
|
|
129
|
+
return this.createUser(firebaseUser, [initialRole || UserRole.PATIENT], {
|
|
130
|
+
skipProfileCreation: options?.skipProfileCreation,
|
|
131
|
+
});
|
|
126
132
|
}
|
|
127
133
|
}
|
|
128
134
|
|