@baasix/sdk 0.1.2 → 0.1.4

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.js CHANGED
@@ -601,9 +601,9 @@ var AuthModule = class {
601
601
  async getUser() {
602
602
  try {
603
603
  const response = await this.client.get("/auth/me");
604
- this.currentUser = response.data;
605
- await this.storage.set(STORAGE_KEYS.USER, JSON.stringify(response.data));
606
- return response.data;
604
+ this.currentUser = response.user;
605
+ await this.storage.set(STORAGE_KEYS.USER, JSON.stringify(response.user));
606
+ return response.user;
607
607
  } catch (error) {
608
608
  if (error instanceof BaasixError && error.status === 401) {
609
609
  await this.clearAuth();
@@ -612,6 +612,19 @@ var AuthModule = class {
612
612
  throw error;
613
613
  }
614
614
  }
615
+ /**
616
+ * Alias for getUser() - Get the current authenticated user from the server
617
+ * Calls the /auth/me endpoint
618
+ *
619
+ * @example
620
+ * ```typescript
621
+ * const user = await baasix.auth.me();
622
+ * console.log(user?.email);
623
+ * ```
624
+ */
625
+ async me() {
626
+ return this.getUser();
627
+ }
615
628
  /**
616
629
  * Get the cached current user (does not make an API call)
617
630
  *
@@ -760,7 +773,7 @@ var AuthModule = class {
760
773
  */
761
774
  async forgotPassword(options) {
762
775
  await this.client.post(
763
- "/auth/forgot-password",
776
+ "/auth/password/reset",
764
777
  {
765
778
  email: options.email,
766
779
  link: options.redirectUrl
@@ -778,8 +791,8 @@ var AuthModule = class {
778
791
  */
779
792
  async resetPassword(token, newPassword) {
780
793
  await this.client.post(
781
- "/auth/reset-password",
782
- { token, password: newPassword },
794
+ `/auth/password/reset/${encodeURIComponent(token)}`,
795
+ { password: newPassword },
783
796
  { skipAuth: true }
784
797
  );
785
798
  }
@@ -792,28 +805,11 @@ var AuthModule = class {
792
805
  * ```
793
806
  */
794
807
  async changePassword(currentPassword, newPassword) {
795
- await this.client.post("/auth/change-password", {
808
+ await this.client.post("/auth/password/change", {
796
809
  currentPassword,
797
810
  newPassword
798
811
  });
799
812
  }
800
- /**
801
- * Update the current user's profile
802
- *
803
- * @example
804
- * ```typescript
805
- * const updatedUser = await baasix.auth.updateProfile({
806
- * firstName: 'Jane',
807
- * lastName: 'Doe'
808
- * });
809
- * ```
810
- */
811
- async updateProfile(data) {
812
- const response = await this.client.patch("/auth/me", data);
813
- await this.storage.set(STORAGE_KEYS.USER, JSON.stringify(response.data));
814
- this.emitAuthStateChange("USER_UPDATED", response.data);
815
- return response.data;
816
- }
817
813
  /**
818
814
  * Get available tenants for the current user (multi-tenant mode)
819
815
  *
@@ -824,7 +820,7 @@ var AuthModule = class {
824
820
  */
825
821
  async getTenants() {
826
822
  const response = await this.client.get("/auth/tenants");
827
- return response.data;
823
+ return response.tenants;
828
824
  }
829
825
  /**
830
826
  * Switch to a different tenant (multi-tenant mode)
@@ -945,7 +941,7 @@ var AuthModule = class {
945
941
  * ```
946
942
  */
947
943
  async requestEmailVerification(redirectUrl) {
948
- await this.client.post("/auth/request-verify-email", {
944
+ await this.client.post("/auth/email/verify", {
949
945
  link: redirectUrl
950
946
  });
951
947
  }
@@ -961,8 +957,7 @@ var AuthModule = class {
961
957
  * ```
962
958
  */
963
959
  async verifyEmail(token) {
964
- await this.client.get("/auth/verify-email", {
965
- params: { token },
960
+ await this.client.get(`/auth/email/verify/${encodeURIComponent(token)}`, {
966
961
  skipAuth: true
967
962
  });
968
963
  }
@@ -977,7 +972,7 @@ var AuthModule = class {
977
972
  async checkSession() {
978
973
  try {
979
974
  const response = await this.client.get("/auth/check");
980
- return response.data.valid;
975
+ return response.valid;
981
976
  } catch {
982
977
  return false;
983
978
  }
@@ -1022,16 +1017,15 @@ var AuthModule = class {
1022
1017
  */
1023
1018
  async verifyInvite(token, redirectUrl) {
1024
1019
  const response = await this.client.get(
1025
- "/auth/verify-invite",
1020
+ `/auth/verify-invite/${encodeURIComponent(token)}`,
1026
1021
  {
1027
1022
  params: {
1028
- token,
1029
1023
  link: redirectUrl
1030
1024
  },
1031
1025
  skipAuth: true
1032
1026
  }
1033
1027
  );
1034
- return response.data;
1028
+ return response;
1035
1029
  }
1036
1030
  /**
1037
1031
  * Accept an invitation (for existing users)
@@ -1044,7 +1038,7 @@ var AuthModule = class {
1044
1038
  async acceptInvite(token) {
1045
1039
  const response = await this.client.post(
1046
1040
  "/auth/accept-invite",
1047
- { token }
1041
+ { inviteToken: token }
1048
1042
  );
1049
1043
  await this.storeTokens(response);
1050
1044
  this.emitAuthStateChange("SIGNED_IN", response.user);