@a-tech.jo/auth-sdk 1.0.9 → 1.0.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.
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 A-Tech Ecosystem
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -1 +1 @@
1
- {"version":3,"file":"AuthContext.d.ts","sourceRoot":"","sources":["../src/AuthContext.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAkE,MAAM,OAAO,CAAC;AACvF,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAElF,UAAU,eAAe;IACrB,MAAM,EAAE,UAAU,CAAC;IACnB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,IAAI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,EAAE,KAAK,CAAC,SAAS,CAAC;CAC7B,CAgFA,CAAC;AAEF,eAAO,MAAM,OAAO,uBAMnB,CAAC"}
package/dist/config.d.ts CHANGED
@@ -8,7 +8,7 @@ export declare const DEFAULT_ENVIRONMENT_URLS: Record<AuthEnvironment, string>;
8
8
  */
9
9
  export declare const DEFAULT_ENDPOINTS: EndpointConfig;
10
10
  /**
11
- * Default LocalStorage Keys
11
+ * Default StorageStorage Keys
12
12
  */
13
13
  export declare const DEFAULT_STORAGE_KEYS: StorageKeys;
14
14
  /**
package/dist/index.js CHANGED
@@ -156,19 +156,21 @@ var AuthProvider = ({ config = {}, children }) => {
156
156
  const [client] = (0, import_react.useState)(() => new AuthClient(config));
157
157
  const [token, setToken] = (0, import_react.useState)(null);
158
158
  const [user, setUser] = (0, import_react.useState)(null);
159
+ const resolvedConfig = (0, import_react.useMemo)(() => getSDKConfig(config), [config]);
160
+ const { accessToken: accessTokenKey, refreshToken: refreshTokenKey } = resolvedConfig.storageKeys;
159
161
  (0, import_react.useEffect)(() => {
160
162
  if (typeof window !== "undefined") {
161
- const savedToken = localStorage.getItem("auth_token");
163
+ const savedToken = sessionStorage.getItem(accessTokenKey);
162
164
  if (savedToken) setToken(savedToken);
163
165
  }
164
- }, []);
166
+ }, [accessTokenKey]);
165
167
  const saveSession = (res) => {
166
168
  if (res.token) {
167
169
  setToken(res.token);
168
170
  if (typeof window !== "undefined") {
169
- localStorage.setItem("auth_token", res.token);
171
+ sessionStorage.setItem(accessTokenKey, res.token);
170
172
  if (res.refreshToken) {
171
- localStorage.setItem("auth_refresh_token", res.refreshToken);
173
+ sessionStorage.setItem(refreshTokenKey, res.refreshToken);
172
174
  }
173
175
  }
174
176
  }
@@ -199,8 +201,8 @@ var AuthProvider = ({ config = {}, children }) => {
199
201
  setToken(null);
200
202
  setUser(null);
201
203
  if (typeof window !== "undefined") {
202
- localStorage.removeItem("auth_token");
203
- localStorage.removeItem("auth_refresh_token");
204
+ sessionStorage.removeItem(accessTokenKey);
205
+ sessionStorage.removeItem(refreshTokenKey);
204
206
  }
205
207
  };
206
208
  const isExpired = (0, import_react.useMemo)(() => isTokenExpired(token), [token]);
@@ -755,30 +757,24 @@ var SDKAuthContainer = ({
755
757
  };
756
758
 
757
759
  // src/services/auth.ts
758
- async function verifyToken(token, environment = "production", showLog = false) {
760
+ async function verifyToken(token, environment = "production") {
759
761
  const baseUrlMap = {
760
762
  local: "http://localhost:3000",
761
- stage: "https://stage.auth.atech-workspace.com",
762
- production: "https://auth.atech-workspace.com"
763
+ stage: "https://auth.atech-workspace.com",
764
+ production: "https://sso.a-tech.dev"
763
765
  // Replace with your production URL
764
766
  };
765
767
  const baseUrl = baseUrlMap[environment] || baseUrlMap.production;
766
- if (showLog) console.log(" AUTH URL: ", baseUrl);
767
768
  try {
768
- const headers = {
769
- "Content-Type": "application/json",
770
- Authorization: `Bearer ${token}`
771
- };
772
- const body = JSON.stringify({ token });
773
769
  const response = await fetch(`${baseUrl}/api/auth/verify`, {
774
770
  method: "POST",
775
- headers,
771
+ headers: {
772
+ "Content-Type": "application/json",
773
+ Authorization: `Bearer ${token}`
774
+ },
776
775
  body: JSON.stringify({ token })
777
776
  });
778
- if (showLog) console.log(" AUTH Headers: ", baseUrl);
779
- if (showLog) console.log(" AUTH body: ", body);
780
777
  const data = await response.json();
781
- if (showLog) console.log(" AUTH response: ", data);
782
778
  if (!response.ok) {
783
779
  return {
784
780
  valid: false,
@@ -787,7 +783,6 @@ async function verifyToken(token, environment = "production", showLog = false) {
787
783
  }
788
784
  return data;
789
785
  } catch (error) {
790
- if (showLog) console.log(" AUTH catch error: ", error);
791
786
  return {
792
787
  valid: false,
793
788
  error: error.message || "Network error while verifying token."
package/dist/index.mjs CHANGED
@@ -120,19 +120,21 @@ var AuthProvider = ({ config = {}, children }) => {
120
120
  const [client] = useState(() => new AuthClient(config));
121
121
  const [token, setToken] = useState(null);
122
122
  const [user, setUser] = useState(null);
123
+ const resolvedConfig = useMemo(() => getSDKConfig(config), [config]);
124
+ const { accessToken: accessTokenKey, refreshToken: refreshTokenKey } = resolvedConfig.storageKeys;
123
125
  useEffect(() => {
124
126
  if (typeof window !== "undefined") {
125
- const savedToken = localStorage.getItem("auth_token");
127
+ const savedToken = sessionStorage.getItem(accessTokenKey);
126
128
  if (savedToken) setToken(savedToken);
127
129
  }
128
- }, []);
130
+ }, [accessTokenKey]);
129
131
  const saveSession = (res) => {
130
132
  if (res.token) {
131
133
  setToken(res.token);
132
134
  if (typeof window !== "undefined") {
133
- localStorage.setItem("auth_token", res.token);
135
+ sessionStorage.setItem(accessTokenKey, res.token);
134
136
  if (res.refreshToken) {
135
- localStorage.setItem("auth_refresh_token", res.refreshToken);
137
+ sessionStorage.setItem(refreshTokenKey, res.refreshToken);
136
138
  }
137
139
  }
138
140
  }
@@ -163,8 +165,8 @@ var AuthProvider = ({ config = {}, children }) => {
163
165
  setToken(null);
164
166
  setUser(null);
165
167
  if (typeof window !== "undefined") {
166
- localStorage.removeItem("auth_token");
167
- localStorage.removeItem("auth_refresh_token");
168
+ sessionStorage.removeItem(accessTokenKey);
169
+ sessionStorage.removeItem(refreshTokenKey);
168
170
  }
169
171
  };
170
172
  const isExpired = useMemo(() => isTokenExpired(token), [token]);
@@ -719,30 +721,24 @@ var SDKAuthContainer = ({
719
721
  };
720
722
 
721
723
  // src/services/auth.ts
722
- async function verifyToken(token, environment = "production", showLog = false) {
724
+ async function verifyToken(token, environment = "production") {
723
725
  const baseUrlMap = {
724
726
  local: "http://localhost:3000",
725
- stage: "https://stage.auth.atech-workspace.com",
726
- production: "https://auth.atech-workspace.com"
727
+ stage: "https://auth.atech-workspace.com",
728
+ production: "https://sso.a-tech.dev"
727
729
  // Replace with your production URL
728
730
  };
729
731
  const baseUrl = baseUrlMap[environment] || baseUrlMap.production;
730
- if (showLog) console.log(" AUTH URL: ", baseUrl);
731
732
  try {
732
- const headers = {
733
- "Content-Type": "application/json",
734
- Authorization: `Bearer ${token}`
735
- };
736
- const body = JSON.stringify({ token });
737
733
  const response = await fetch(`${baseUrl}/api/auth/verify`, {
738
734
  method: "POST",
739
- headers,
735
+ headers: {
736
+ "Content-Type": "application/json",
737
+ Authorization: `Bearer ${token}`
738
+ },
740
739
  body: JSON.stringify({ token })
741
740
  });
742
- if (showLog) console.log(" AUTH Headers: ", baseUrl);
743
- if (showLog) console.log(" AUTH body: ", body);
744
741
  const data = await response.json();
745
- if (showLog) console.log(" AUTH response: ", data);
746
742
  if (!response.ok) {
747
743
  return {
748
744
  valid: false,
@@ -751,7 +747,6 @@ async function verifyToken(token, environment = "production", showLog = false) {
751
747
  }
752
748
  return data;
753
749
  } catch (error) {
754
- if (showLog) console.log(" AUTH catch error: ", error);
755
750
  return {
756
751
  valid: false,
757
752
  error: error.message || "Network error while verifying token."
@@ -6,5 +6,5 @@ import { VerifyTokenResponse } from "../types";
6
6
  * @param environment - Optional environment override ('local' | 'stage' | 'production').
7
7
  * @returns Promise containing verification status and user details.
8
8
  */
9
- export declare function verifyToken(token: string, environment?: "local" | "stage" | "production", showLog?: boolean): Promise<VerifyTokenResponse>;
9
+ export declare function verifyToken(token: string, environment?: "local" | "stage" | "production"): Promise<VerifyTokenResponse>;
10
10
  //# sourceMappingURL=auth.d.ts.map
@@ -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":"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,GAC7D,OAAO,CAAC,mBAAmB,CAAC,CAmC9B"}
package/package.json CHANGED
@@ -1,13 +1,15 @@
1
1
  {
2
2
  "name": "@a-tech.jo/auth-sdk",
3
- "version": "1.0.9",
3
+ "version": "1.0.11",
4
+ "license": "MIT",
4
5
  "description": "A-Tech Authentication SDK for React and Next.js",
5
6
  "main": "./dist/index.js",
6
7
  "module": "./dist/index.mjs",
7
8
  "types": "./dist/index.d.ts",
8
9
  "style": "./dist/styles.css",
9
10
  "files": [
10
- "dist"
11
+ "dist",
12
+ "LICENSE"
11
13
  ],
12
14
  "publishConfig": {
13
15
  "access": "public"