strapi-plugin-firebase-authentication 1.1.9 → 1.1.11

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.
@@ -29490,9 +29490,8 @@ const settingsService = ({ strapi: strapi2 }) => {
29490
29490
  throw new ApplicationError2("Firebase configuration hash is missing");
29491
29491
  }
29492
29492
  const firebaseConfigJsonValue = await this.decryptJson(encryptionKey, firebaseConfigHash);
29493
- configData.firebaseConfigJson = firebaseConfigJsonValue;
29494
- res.firebaseConfigJson = configData;
29495
- res.firebase_config_json = configData;
29493
+ res.firebaseConfigJson = firebaseConfigJsonValue;
29494
+ res.firebase_config_json = firebaseConfigJsonValue;
29496
29495
  res.firebaseWebApiKey = res.firebase_web_api_key || null;
29497
29496
  res.passwordRequirementsRegex = res.passwordRequirementsRegex || passwordRequirementsRegex;
29498
29497
  res.passwordRequirementsMessage = res.passwordRequirementsMessage || passwordRequirementsMessage;
@@ -29851,9 +29850,71 @@ const userService = ({ strapi: strapi2 }) => {
29851
29850
  update: async (entityId, payload) => {
29852
29851
  try {
29853
29852
  ensureFirebaseInitialized();
29854
- const firebasePromise = strapi2.firebase.auth().updateUser(entityId, payload);
29855
- return Promise.allSettled([firebasePromise]);
29853
+ const firebaseData = await strapi2.plugin("firebase-authentication").service("firebaseUserDataService").getByFirebaseUID(entityId);
29854
+ if (!firebaseData?.user) {
29855
+ throw new NotFoundError(`User not found for Firebase UID: ${entityId}`);
29856
+ }
29857
+ const firebasePayload = {};
29858
+ if (payload.email !== void 0) firebasePayload.email = payload.email;
29859
+ if (payload.phoneNumber !== void 0) firebasePayload.phoneNumber = payload.phoneNumber;
29860
+ if (payload.displayName !== void 0) firebasePayload.displayName = payload.displayName;
29861
+ if (payload.photoURL !== void 0) firebasePayload.photoURL = payload.photoURL;
29862
+ if (payload.disabled !== void 0) firebasePayload.disabled = payload.disabled;
29863
+ if (payload.emailVerified !== void 0) firebasePayload.emailVerified = payload.emailVerified;
29864
+ if (payload.password !== void 0) firebasePayload.password = payload.password;
29865
+ const firebasePromise = strapi2.firebase.auth().updateUser(entityId, firebasePayload);
29866
+ const strapiPayload = {};
29867
+ if (payload.email !== void 0) {
29868
+ strapiPayload.email = payload.email;
29869
+ }
29870
+ if (payload.phoneNumber !== void 0) {
29871
+ strapiPayload.phoneNumber = payload.phoneNumber;
29872
+ }
29873
+ if (payload.displayName !== void 0) {
29874
+ if (payload.displayName) {
29875
+ const nameParts = payload.displayName.trim().split(" ");
29876
+ strapiPayload.firstName = nameParts[0] || "";
29877
+ strapiPayload.lastName = nameParts.slice(1).join(" ") || "";
29878
+ } else {
29879
+ strapiPayload.firstName = "";
29880
+ strapiPayload.lastName = "";
29881
+ }
29882
+ }
29883
+ if (typeof payload.disabled === "boolean") {
29884
+ strapiPayload.blocked = payload.disabled;
29885
+ }
29886
+ const strapiPromise = Object.keys(strapiPayload).length > 0 ? strapi2.db.query("plugin::users-permissions.user").update({
29887
+ where: { documentId: firebaseData.user.documentId },
29888
+ data: strapiPayload
29889
+ }) : Promise.resolve(firebaseData.user);
29890
+ const results = await Promise.allSettled([firebasePromise, strapiPromise]);
29891
+ strapi2.log.info("User update operation", {
29892
+ userId: entityId,
29893
+ firebaseStatus: results[0].status,
29894
+ strapiStatus: results[1].status,
29895
+ updatedFields: Object.keys(firebasePayload)
29896
+ });
29897
+ if (results[0].status === "rejected" || results[1].status === "rejected") {
29898
+ strapi2.log.error("Partial update failure detected", {
29899
+ userId: entityId,
29900
+ firebaseError: results[0].status === "rejected" ? results[0].reason : null,
29901
+ strapiError: results[1].status === "rejected" ? results[1].reason : null
29902
+ });
29903
+ }
29904
+ return results;
29856
29905
  } catch (e) {
29906
+ if (e.code === "auth/email-already-exists") {
29907
+ throw new ValidationError$1("Email address is already in use by another account");
29908
+ }
29909
+ if (e.code === "auth/phone-number-already-exists") {
29910
+ throw new ValidationError$1("Phone number is already in use by another account");
29911
+ }
29912
+ if (e.code === "auth/invalid-email") {
29913
+ throw new ValidationError$1("Invalid email address format");
29914
+ }
29915
+ if (e.code === "auth/invalid-phone-number") {
29916
+ throw new ValidationError$1("Invalid phone number format");
29917
+ }
29857
29918
  throw new ApplicationError$1(e.message.toString());
29858
29919
  }
29859
29920
  },
@@ -29871,8 +29932,8 @@ const userService = ({ strapi: strapi2 }) => {
29871
29932
  if (!firebaseData?.user) {
29872
29933
  throw new NotFoundError(`User not found for Firebase UID: ${entityId}`);
29873
29934
  }
29874
- return await strapi2.documents("plugin::users-permissions.user").update({
29875
- documentId: firebaseData.user.documentId,
29935
+ return await strapi2.db.query("plugin::users-permissions.user").update({
29936
+ where: { documentId: firebaseData.user.documentId },
29876
29937
  data: payload
29877
29938
  });
29878
29939
  } catch (e) {
@@ -29887,8 +29948,8 @@ const userService = ({ strapi: strapi2 }) => {
29887
29948
  throw new NotFoundError(`User not found for Firebase UID: ${entityId}`);
29888
29949
  }
29889
29950
  const firebasePromise = strapi2.firebase.auth().updateUser(entityId, payload);
29890
- const strapiPromise = strapi2.documents("plugin::users-permissions.user").update({
29891
- documentId: firebaseData.user.documentId,
29951
+ const strapiPromise = strapi2.db.query("plugin::users-permissions.user").update({
29952
+ where: { documentId: firebaseData.user.documentId },
29892
29953
  data: payload
29893
29954
  });
29894
29955
  return Promise.allSettled([firebasePromise, strapiPromise]);
@@ -29904,8 +29965,8 @@ const userService = ({ strapi: strapi2 }) => {
29904
29965
  throw new NotFoundError(`User not found for Firebase UID: ${entityId}`);
29905
29966
  }
29906
29967
  const firebasePromise = strapi2.firebase.auth().deleteUser(entityId);
29907
- const strapiPromise = strapi2.documents("plugin::users-permissions.user").delete({
29908
- documentId: firebaseData.user.documentId
29968
+ const strapiPromise = strapi2.db.query("plugin::users-permissions.user").delete({
29969
+ where: { documentId: firebaseData.user.documentId }
29909
29970
  });
29910
29971
  return Promise.allSettled([firebasePromise, strapiPromise]);
29911
29972
  } catch (e) {
@@ -29927,8 +29988,8 @@ const userService = ({ strapi: strapi2 }) => {
29927
29988
  if (!firebaseData?.user) {
29928
29989
  throw new NotFoundError(`User not found for Firebase UID: ${entityId}`);
29929
29990
  }
29930
- const response = await strapi2.documents("plugin::users-permissions.user").delete({
29931
- documentId: firebaseData.user.documentId
29991
+ const response = await strapi2.db.query("plugin::users-permissions.user").delete({
29992
+ where: { documentId: firebaseData.user.documentId }
29932
29993
  });
29933
29994
  return response;
29934
29995
  } catch (e) {
@@ -31349,7 +31410,7 @@ const firebaseUserDataService = ({ strapi: strapi2 }) => ({
31349
31410
  }
31350
31411
  });
31351
31412
  } catch (error2) {
31352
- if (error2.code === "23505") {
31413
+ if (error2.code === "23505" || error2.name === "ValidationError") {
31353
31414
  strapi2.log.warn(`Race condition detected for user ${userId}, retrying findFirst`);
31354
31415
  firebaseData = await strapi2.documents("plugin::firebase-authentication.firebase-user-data").findFirst({
31355
31416
  filters: { user: { documentId: { $eq: userId } } }
@@ -29458,9 +29458,8 @@ const settingsService = ({ strapi: strapi2 }) => {
29458
29458
  throw new ApplicationError2("Firebase configuration hash is missing");
29459
29459
  }
29460
29460
  const firebaseConfigJsonValue = await this.decryptJson(encryptionKey, firebaseConfigHash);
29461
- configData.firebaseConfigJson = firebaseConfigJsonValue;
29462
- res.firebaseConfigJson = configData;
29463
- res.firebase_config_json = configData;
29461
+ res.firebaseConfigJson = firebaseConfigJsonValue;
29462
+ res.firebase_config_json = firebaseConfigJsonValue;
29464
29463
  res.firebaseWebApiKey = res.firebase_web_api_key || null;
29465
29464
  res.passwordRequirementsRegex = res.passwordRequirementsRegex || passwordRequirementsRegex;
29466
29465
  res.passwordRequirementsMessage = res.passwordRequirementsMessage || passwordRequirementsMessage;
@@ -29819,9 +29818,71 @@ const userService = ({ strapi: strapi2 }) => {
29819
29818
  update: async (entityId, payload) => {
29820
29819
  try {
29821
29820
  ensureFirebaseInitialized();
29822
- const firebasePromise = strapi2.firebase.auth().updateUser(entityId, payload);
29823
- return Promise.allSettled([firebasePromise]);
29821
+ const firebaseData = await strapi2.plugin("firebase-authentication").service("firebaseUserDataService").getByFirebaseUID(entityId);
29822
+ if (!firebaseData?.user) {
29823
+ throw new NotFoundError(`User not found for Firebase UID: ${entityId}`);
29824
+ }
29825
+ const firebasePayload = {};
29826
+ if (payload.email !== void 0) firebasePayload.email = payload.email;
29827
+ if (payload.phoneNumber !== void 0) firebasePayload.phoneNumber = payload.phoneNumber;
29828
+ if (payload.displayName !== void 0) firebasePayload.displayName = payload.displayName;
29829
+ if (payload.photoURL !== void 0) firebasePayload.photoURL = payload.photoURL;
29830
+ if (payload.disabled !== void 0) firebasePayload.disabled = payload.disabled;
29831
+ if (payload.emailVerified !== void 0) firebasePayload.emailVerified = payload.emailVerified;
29832
+ if (payload.password !== void 0) firebasePayload.password = payload.password;
29833
+ const firebasePromise = strapi2.firebase.auth().updateUser(entityId, firebasePayload);
29834
+ const strapiPayload = {};
29835
+ if (payload.email !== void 0) {
29836
+ strapiPayload.email = payload.email;
29837
+ }
29838
+ if (payload.phoneNumber !== void 0) {
29839
+ strapiPayload.phoneNumber = payload.phoneNumber;
29840
+ }
29841
+ if (payload.displayName !== void 0) {
29842
+ if (payload.displayName) {
29843
+ const nameParts = payload.displayName.trim().split(" ");
29844
+ strapiPayload.firstName = nameParts[0] || "";
29845
+ strapiPayload.lastName = nameParts.slice(1).join(" ") || "";
29846
+ } else {
29847
+ strapiPayload.firstName = "";
29848
+ strapiPayload.lastName = "";
29849
+ }
29850
+ }
29851
+ if (typeof payload.disabled === "boolean") {
29852
+ strapiPayload.blocked = payload.disabled;
29853
+ }
29854
+ const strapiPromise = Object.keys(strapiPayload).length > 0 ? strapi2.db.query("plugin::users-permissions.user").update({
29855
+ where: { documentId: firebaseData.user.documentId },
29856
+ data: strapiPayload
29857
+ }) : Promise.resolve(firebaseData.user);
29858
+ const results = await Promise.allSettled([firebasePromise, strapiPromise]);
29859
+ strapi2.log.info("User update operation", {
29860
+ userId: entityId,
29861
+ firebaseStatus: results[0].status,
29862
+ strapiStatus: results[1].status,
29863
+ updatedFields: Object.keys(firebasePayload)
29864
+ });
29865
+ if (results[0].status === "rejected" || results[1].status === "rejected") {
29866
+ strapi2.log.error("Partial update failure detected", {
29867
+ userId: entityId,
29868
+ firebaseError: results[0].status === "rejected" ? results[0].reason : null,
29869
+ strapiError: results[1].status === "rejected" ? results[1].reason : null
29870
+ });
29871
+ }
29872
+ return results;
29824
29873
  } catch (e) {
29874
+ if (e.code === "auth/email-already-exists") {
29875
+ throw new ValidationError$1("Email address is already in use by another account");
29876
+ }
29877
+ if (e.code === "auth/phone-number-already-exists") {
29878
+ throw new ValidationError$1("Phone number is already in use by another account");
29879
+ }
29880
+ if (e.code === "auth/invalid-email") {
29881
+ throw new ValidationError$1("Invalid email address format");
29882
+ }
29883
+ if (e.code === "auth/invalid-phone-number") {
29884
+ throw new ValidationError$1("Invalid phone number format");
29885
+ }
29825
29886
  throw new ApplicationError$1(e.message.toString());
29826
29887
  }
29827
29888
  },
@@ -29839,8 +29900,8 @@ const userService = ({ strapi: strapi2 }) => {
29839
29900
  if (!firebaseData?.user) {
29840
29901
  throw new NotFoundError(`User not found for Firebase UID: ${entityId}`);
29841
29902
  }
29842
- return await strapi2.documents("plugin::users-permissions.user").update({
29843
- documentId: firebaseData.user.documentId,
29903
+ return await strapi2.db.query("plugin::users-permissions.user").update({
29904
+ where: { documentId: firebaseData.user.documentId },
29844
29905
  data: payload
29845
29906
  });
29846
29907
  } catch (e) {
@@ -29855,8 +29916,8 @@ const userService = ({ strapi: strapi2 }) => {
29855
29916
  throw new NotFoundError(`User not found for Firebase UID: ${entityId}`);
29856
29917
  }
29857
29918
  const firebasePromise = strapi2.firebase.auth().updateUser(entityId, payload);
29858
- const strapiPromise = strapi2.documents("plugin::users-permissions.user").update({
29859
- documentId: firebaseData.user.documentId,
29919
+ const strapiPromise = strapi2.db.query("plugin::users-permissions.user").update({
29920
+ where: { documentId: firebaseData.user.documentId },
29860
29921
  data: payload
29861
29922
  });
29862
29923
  return Promise.allSettled([firebasePromise, strapiPromise]);
@@ -29872,8 +29933,8 @@ const userService = ({ strapi: strapi2 }) => {
29872
29933
  throw new NotFoundError(`User not found for Firebase UID: ${entityId}`);
29873
29934
  }
29874
29935
  const firebasePromise = strapi2.firebase.auth().deleteUser(entityId);
29875
- const strapiPromise = strapi2.documents("plugin::users-permissions.user").delete({
29876
- documentId: firebaseData.user.documentId
29936
+ const strapiPromise = strapi2.db.query("plugin::users-permissions.user").delete({
29937
+ where: { documentId: firebaseData.user.documentId }
29877
29938
  });
29878
29939
  return Promise.allSettled([firebasePromise, strapiPromise]);
29879
29940
  } catch (e) {
@@ -29895,8 +29956,8 @@ const userService = ({ strapi: strapi2 }) => {
29895
29956
  if (!firebaseData?.user) {
29896
29957
  throw new NotFoundError(`User not found for Firebase UID: ${entityId}`);
29897
29958
  }
29898
- const response = await strapi2.documents("plugin::users-permissions.user").delete({
29899
- documentId: firebaseData.user.documentId
29959
+ const response = await strapi2.db.query("plugin::users-permissions.user").delete({
29960
+ where: { documentId: firebaseData.user.documentId }
29900
29961
  });
29901
29962
  return response;
29902
29963
  } catch (e) {
@@ -31317,7 +31378,7 @@ const firebaseUserDataService = ({ strapi: strapi2 }) => ({
31317
31378
  }
31318
31379
  });
31319
31380
  } catch (error2) {
31320
- if (error2.code === "23505") {
31381
+ if (error2.code === "23505" || error2.name === "ValidationError") {
31321
31382
  strapi2.log.warn(`Race condition detected for user ${userId}, retrying findFirst`);
31322
31383
  firebaseData = await strapi2.documents("plugin::firebase-authentication.firebase-user-data").findFirst({
31323
31384
  filters: { user: { documentId: { $eq: userId } } }
@@ -119,7 +119,7 @@ declare const _default: {
119
119
  };
120
120
  }>;
121
121
  updateFirebaseUser: (entityId: any, payload: any) => Promise<any>;
122
- update: (entityId: any, payload: any) => Promise<[PromiseSettledResult<any>]>;
122
+ update: (entityId: any, payload: any) => Promise<[PromiseSettledResult<any>, PromiseSettledResult<any>]>;
123
123
  resetPasswordFirebaseUser: (entityId: any, payload: any) => Promise<any>;
124
124
  resetPasswordStrapiUser: (entityId: any, payload: any) => Promise<any>;
125
125
  resetPassword: (entityId: any, payload: any) => Promise<[PromiseSettledResult<any>, PromiseSettledResult<any>]>;
@@ -42,7 +42,7 @@ declare const _default: {
42
42
  };
43
43
  }>;
44
44
  updateFirebaseUser: (entityId: any, payload: any) => Promise<any>;
45
- update: (entityId: any, payload: any) => Promise<[PromiseSettledResult<any>]>;
45
+ update: (entityId: any, payload: any) => Promise<[PromiseSettledResult<any>, PromiseSettledResult<any>]>;
46
46
  resetPasswordFirebaseUser: (entityId: any, payload: any) => Promise<any>;
47
47
  resetPasswordStrapiUser: (entityId: any, payload: any) => Promise<any>;
48
48
  resetPassword: (entityId: any, payload: any) => Promise<[PromiseSettledResult<any>, PromiseSettledResult<any>]>;
@@ -12,7 +12,7 @@ declare const _default: ({ strapi }: {
12
12
  };
13
13
  }>;
14
14
  updateFirebaseUser: (entityId: any, payload: any) => Promise<any>;
15
- update: (entityId: any, payload: any) => Promise<[PromiseSettledResult<any>]>;
15
+ update: (entityId: any, payload: any) => Promise<[PromiseSettledResult<any>, PromiseSettledResult<any>]>;
16
16
  resetPasswordFirebaseUser: (entityId: any, payload: any) => Promise<any>;
17
17
  resetPasswordStrapiUser: (entityId: any, payload: any) => Promise<any>;
18
18
  resetPassword: (entityId: any, payload: any) => Promise<[PromiseSettledResult<any>, PromiseSettledResult<any>]>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "strapi-plugin-firebase-authentication",
3
- "version": "1.1.9",
3
+ "version": "1.1.11",
4
4
  "description": "Allows easy integration between clients utilizing Firebase for authentication and Strapi",
5
5
  "license": "MIT",
6
6
  "repository": {