@a-tech.jo/auth-sdk 1.0.10 → 1.0.12
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 +21 -0
- package/dist/AuthContext.d.ts.map +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/index.js +26 -35
- package/dist/index.mjs +26 -25
- package/dist/services/auth.d.ts +1 -1
- package/dist/services/auth.d.ts.map +1 -1
- package/package.json +5 -6
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;
|
|
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;AAGlF,UAAU,eAAe;IACrB,MAAM,EAAE,UAAU,CAAC;IACnB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,IAAI,EAAE,GAAG,GAAG,IAAI,CAAC;IACjB,KAAK,EAAE,CAAC,OAAO,EAAE,YAAY,KAAK,OAAO,CAAC,YAAY,CAAC,CAAC;IACxD,QAAQ,EAAE,CAAC,OAAO,EAAE,eAAe,KAAK,OAAO,CAAC,YAAY,CAAC,CAAC;IAC9D,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,eAAe,EAAE,OAAO,CAAC;IACzB,SAAS,EAAE,OAAO,CAAC;CACtB;AA2BD,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC;IAChC,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,QAAQ,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
|
|
11
|
+
* Default StorageStorage Keys
|
|
12
12
|
*/
|
|
13
13
|
export declare const DEFAULT_STORAGE_KEYS: StorageKeys;
|
|
14
14
|
/**
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
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
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
|
|
30
20
|
// src/index.ts
|
|
@@ -166,19 +156,21 @@ var AuthProvider = ({ config = {}, children }) => {
|
|
|
166
156
|
const [client] = (0, import_react.useState)(() => new AuthClient(config));
|
|
167
157
|
const [token, setToken] = (0, import_react.useState)(null);
|
|
168
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;
|
|
169
161
|
(0, import_react.useEffect)(() => {
|
|
170
162
|
if (typeof window !== "undefined") {
|
|
171
|
-
const savedToken =
|
|
163
|
+
const savedToken = sessionStorage.getItem(accessTokenKey);
|
|
172
164
|
if (savedToken) setToken(savedToken);
|
|
173
165
|
}
|
|
174
|
-
}, []);
|
|
166
|
+
}, [accessTokenKey]);
|
|
175
167
|
const saveSession = (res) => {
|
|
176
168
|
if (res.token) {
|
|
177
169
|
setToken(res.token);
|
|
178
170
|
if (typeof window !== "undefined") {
|
|
179
|
-
|
|
171
|
+
sessionStorage.setItem(accessTokenKey, res.token);
|
|
180
172
|
if (res.refreshToken) {
|
|
181
|
-
|
|
173
|
+
sessionStorage.setItem(refreshTokenKey, res.refreshToken);
|
|
182
174
|
}
|
|
183
175
|
}
|
|
184
176
|
}
|
|
@@ -209,8 +201,8 @@ var AuthProvider = ({ config = {}, children }) => {
|
|
|
209
201
|
setToken(null);
|
|
210
202
|
setUser(null);
|
|
211
203
|
if (typeof window !== "undefined") {
|
|
212
|
-
|
|
213
|
-
|
|
204
|
+
sessionStorage.removeItem(accessTokenKey);
|
|
205
|
+
sessionStorage.removeItem(refreshTokenKey);
|
|
214
206
|
}
|
|
215
207
|
};
|
|
216
208
|
const isExpired = (0, import_react.useMemo)(() => isTokenExpired(token), [token]);
|
|
@@ -765,35 +757,34 @@ var SDKAuthContainer = ({
|
|
|
765
757
|
};
|
|
766
758
|
|
|
767
759
|
// src/services/auth.ts
|
|
768
|
-
|
|
769
|
-
async function verifyToken(token, environment = "production", showLog = false) {
|
|
760
|
+
async function verifyToken(token, environment = "production") {
|
|
770
761
|
const baseUrlMap = {
|
|
771
762
|
local: "http://localhost:3000",
|
|
772
763
|
stage: "https://stage.auth.atech-workspace.com",
|
|
773
764
|
production: "https://auth.atech-workspace.com"
|
|
774
|
-
// Replace with your production URL
|
|
775
765
|
};
|
|
776
766
|
const baseUrl = baseUrlMap[environment] || baseUrlMap.production;
|
|
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);
|
|
780
767
|
try {
|
|
781
|
-
const
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
768
|
+
const response = await fetch(`${baseUrl}/api/auth/verify`, {
|
|
769
|
+
method: "POST",
|
|
770
|
+
headers: {
|
|
771
|
+
"Content-Type": "application/json",
|
|
772
|
+
Authorization: `Bearer ${token}`
|
|
773
|
+
},
|
|
774
|
+
body: JSON.stringify({ token })
|
|
775
|
+
});
|
|
776
|
+
const data = await response.json();
|
|
777
|
+
if (!response.ok) {
|
|
778
|
+
return {
|
|
779
|
+
valid: false,
|
|
780
|
+
error: data.error || "Token verification failed."
|
|
781
|
+
};
|
|
782
|
+
}
|
|
783
|
+
return data;
|
|
791
784
|
} catch (error) {
|
|
792
|
-
if (showLog) console.log(" AUTH catch error: ", error);
|
|
793
|
-
const errorMessage = error.response?.data?.error || error.message || "Network error while verifying token.";
|
|
794
785
|
return {
|
|
795
786
|
valid: false,
|
|
796
|
-
error:
|
|
787
|
+
error: error.message || "Network error while verifying token."
|
|
797
788
|
};
|
|
798
789
|
}
|
|
799
790
|
}
|
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 =
|
|
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
|
-
|
|
135
|
+
sessionStorage.setItem(accessTokenKey, res.token);
|
|
134
136
|
if (res.refreshToken) {
|
|
135
|
-
|
|
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
|
-
|
|
167
|
-
|
|
168
|
+
sessionStorage.removeItem(accessTokenKey);
|
|
169
|
+
sessionStorage.removeItem(refreshTokenKey);
|
|
168
170
|
}
|
|
169
171
|
};
|
|
170
172
|
const isExpired = useMemo(() => isTokenExpired(token), [token]);
|
|
@@ -719,35 +721,34 @@ var SDKAuthContainer = ({
|
|
|
719
721
|
};
|
|
720
722
|
|
|
721
723
|
// src/services/auth.ts
|
|
722
|
-
|
|
723
|
-
async function verifyToken(token, environment = "production", showLog = false) {
|
|
724
|
+
async function verifyToken(token, environment = "production") {
|
|
724
725
|
const baseUrlMap = {
|
|
725
726
|
local: "http://localhost:3000",
|
|
726
727
|
stage: "https://stage.auth.atech-workspace.com",
|
|
727
728
|
production: "https://auth.atech-workspace.com"
|
|
728
|
-
// Replace with your production URL
|
|
729
729
|
};
|
|
730
730
|
const baseUrl = baseUrlMap[environment] || baseUrlMap.production;
|
|
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);
|
|
734
731
|
try {
|
|
735
|
-
const
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
732
|
+
const response = await fetch(`${baseUrl}/api/auth/verify`, {
|
|
733
|
+
method: "POST",
|
|
734
|
+
headers: {
|
|
735
|
+
"Content-Type": "application/json",
|
|
736
|
+
Authorization: `Bearer ${token}`
|
|
737
|
+
},
|
|
738
|
+
body: JSON.stringify({ token })
|
|
739
|
+
});
|
|
740
|
+
const data = await response.json();
|
|
741
|
+
if (!response.ok) {
|
|
742
|
+
return {
|
|
743
|
+
valid: false,
|
|
744
|
+
error: data.error || "Token verification failed."
|
|
745
|
+
};
|
|
746
|
+
}
|
|
747
|
+
return data;
|
|
745
748
|
} catch (error) {
|
|
746
|
-
if (showLog) console.log(" AUTH catch error: ", error);
|
|
747
|
-
const errorMessage = error.response?.data?.error || error.message || "Network error while verifying token.";
|
|
748
749
|
return {
|
|
749
750
|
valid: false,
|
|
750
|
-
error:
|
|
751
|
+
error: error.message || "Network error while verifying token."
|
|
751
752
|
};
|
|
752
753
|
}
|
|
753
754
|
}
|
package/dist/services/auth.d.ts
CHANGED
|
@@ -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"
|
|
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":"
|
|
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.
|
|
3
|
+
"version": "1.0.12",
|
|
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"
|
|
@@ -44,8 +46,5 @@
|
|
|
44
46
|
"react-dom": "^19.0.0",
|
|
45
47
|
"tsup": "^8.3.0",
|
|
46
48
|
"typescript": "^5.0.0"
|
|
47
|
-
},
|
|
48
|
-
"dependencies": {
|
|
49
|
-
"axios": "^1.20.0"
|
|
50
49
|
}
|
|
51
|
-
}
|
|
50
|
+
}
|