@a-tech.jo/auth-sdk 1.0.9 → 1.0.10

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
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
 
20
30
  // src/index.ts
@@ -755,6 +765,7 @@ var SDKAuthContainer = ({
755
765
  };
756
766
 
757
767
  // src/services/auth.ts
768
+ var import_axios = __toESM(require("axios"));
758
769
  async function verifyToken(token, environment = "production", showLog = false) {
759
770
  const baseUrlMap = {
760
771
  local: "http://localhost:3000",
@@ -763,34 +774,26 @@ async function verifyToken(token, environment = "production", showLog = false) {
763
774
  // Replace with your production URL
764
775
  };
765
776
  const baseUrl = baseUrlMap[environment] || baseUrlMap.production;
766
- if (showLog) console.log(" AUTH URL: ", baseUrl);
777
+ const fullUrl = `${baseUrl}/api/auth/verify`;
778
+ if (showLog) console.log(" AUTH BASE URL: ", baseUrl);
779
+ if (showLog) console.log(" AUTH FULL URL: ", fullUrl);
767
780
  try {
768
781
  const headers = {
769
782
  "Content-Type": "application/json",
770
783
  Authorization: `Bearer ${token}`
771
784
  };
772
- const body = JSON.stringify({ token });
773
- const response = await fetch(`${baseUrl}/api/auth/verify`, {
774
- method: "POST",
775
- headers,
776
- body: JSON.stringify({ token })
777
- });
778
- if (showLog) console.log(" AUTH Headers: ", baseUrl);
779
- if (showLog) console.log(" AUTH body: ", body);
780
- const data = await response.json();
781
- if (showLog) console.log(" AUTH response: ", data);
782
- if (!response.ok) {
783
- return {
784
- valid: false,
785
- error: data.error || "Token verification failed."
786
- };
787
- }
788
- return data;
785
+ const body = { token };
786
+ if (showLog) console.log(" AUTH Headers: ", headers);
787
+ if (showLog) console.log(" AUTH body: ", JSON.stringify(body));
788
+ const response = await import_axios.default.post(fullUrl, body, { headers });
789
+ if (showLog) console.log(" AUTH response: ", response.data);
790
+ return response.data;
789
791
  } catch (error) {
790
792
  if (showLog) console.log(" AUTH catch error: ", error);
793
+ const errorMessage = error.response?.data?.error || error.message || "Network error while verifying token.";
791
794
  return {
792
795
  valid: false,
793
- error: error.message || "Network error while verifying token."
796
+ error: errorMessage
794
797
  };
795
798
  }
796
799
  }
package/dist/index.mjs CHANGED
@@ -719,6 +719,7 @@ var SDKAuthContainer = ({
719
719
  };
720
720
 
721
721
  // src/services/auth.ts
722
+ import axios from "axios";
722
723
  async function verifyToken(token, environment = "production", showLog = false) {
723
724
  const baseUrlMap = {
724
725
  local: "http://localhost:3000",
@@ -727,34 +728,26 @@ async function verifyToken(token, environment = "production", showLog = false) {
727
728
  // Replace with your production URL
728
729
  };
729
730
  const baseUrl = baseUrlMap[environment] || baseUrlMap.production;
730
- if (showLog) console.log(" AUTH URL: ", baseUrl);
731
+ const fullUrl = `${baseUrl}/api/auth/verify`;
732
+ if (showLog) console.log(" AUTH BASE URL: ", baseUrl);
733
+ if (showLog) console.log(" AUTH FULL URL: ", fullUrl);
731
734
  try {
732
735
  const headers = {
733
736
  "Content-Type": "application/json",
734
737
  Authorization: `Bearer ${token}`
735
738
  };
736
- const body = JSON.stringify({ token });
737
- const response = await fetch(`${baseUrl}/api/auth/verify`, {
738
- method: "POST",
739
- headers,
740
- body: JSON.stringify({ token })
741
- });
742
- if (showLog) console.log(" AUTH Headers: ", baseUrl);
743
- if (showLog) console.log(" AUTH body: ", body);
744
- const data = await response.json();
745
- if (showLog) console.log(" AUTH response: ", data);
746
- if (!response.ok) {
747
- return {
748
- valid: false,
749
- error: data.error || "Token verification failed."
750
- };
751
- }
752
- return data;
739
+ const body = { token };
740
+ if (showLog) console.log(" AUTH Headers: ", headers);
741
+ if (showLog) console.log(" AUTH body: ", JSON.stringify(body));
742
+ const response = await axios.post(fullUrl, body, { headers });
743
+ if (showLog) console.log(" AUTH response: ", response.data);
744
+ return response.data;
753
745
  } catch (error) {
754
746
  if (showLog) console.log(" AUTH catch error: ", error);
747
+ const errorMessage = error.response?.data?.error || error.message || "Network error while verifying token.";
755
748
  return {
756
749
  valid: false,
757
- error: error.message || "Network error while verifying token."
750
+ error: errorMessage
758
751
  };
759
752
  }
760
753
  }
@@ -1 +1 @@
1
- {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/services/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAE/C;;;;;;GAMG;AACH,wBAAsB,WAAW,CAC7B,KAAK,EAAE,MAAM,EACb,WAAW,GAAE,OAAO,GAAG,OAAO,GAAG,YAA2B,EAC5D,OAAO,GAAE,OAAe,GACzB,OAAO,CAAC,mBAAmB,CAAC,CAyC9B"}
1
+ {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/services/auth.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAE/C;;;;;;GAMG;AACH,wBAAsB,WAAW,CAC7B,KAAK,EAAE,MAAM,EACb,WAAW,GAAE,OAAO,GAAG,OAAO,GAAG,YAA2B,EAC5D,OAAO,GAAE,OAAe,GACzB,OAAO,CAAC,mBAAmB,CAAC,CAyC9B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@a-tech.jo/auth-sdk",
3
- "version": "1.0.9",
3
+ "version": "1.0.10",
4
4
  "description": "A-Tech Authentication SDK for React and Next.js",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -44,5 +44,8 @@
44
44
  "react-dom": "^19.0.0",
45
45
  "tsup": "^8.3.0",
46
46
  "typescript": "^5.0.0"
47
+ },
48
+ "dependencies": {
49
+ "axios": "^1.20.0"
47
50
  }
48
- }
51
+ }