@nibssplc/cams-sdk-react 0.0.1-beta.50 → 0.0.1-beta.51
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/hooks/useCAMSAuth.d.ts +2 -0
- package/dist/index.cjs.js +21 -10
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +21 -10
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
|
@@ -5,6 +5,8 @@ export interface UseCAMSAuthOptions {
|
|
|
5
5
|
onAuthSuccess?: (token: string) => void;
|
|
6
6
|
onAuthError?: (error: CAMSError) => void;
|
|
7
7
|
onTokenExpired?: () => void;
|
|
8
|
+
autoClose?: boolean;
|
|
9
|
+
idleTimeout?: number;
|
|
8
10
|
}
|
|
9
11
|
export interface UseCAMSAuthReturn {
|
|
10
12
|
login: (config: CAMSConfig) => Promise<void>;
|
package/dist/index.cjs.js
CHANGED
|
@@ -127,11 +127,16 @@ function useCAMSAuth(options) {
|
|
|
127
127
|
var _a;
|
|
128
128
|
setToken(res.userProfile.tokens.Bearer);
|
|
129
129
|
setIsAuthenticated(true);
|
|
130
|
+
setIsLoading(false);
|
|
130
131
|
(_a = options.onAuthSuccess) === null || _a === void 0 ? void 0 : _a.call(options, res.userProfile.tokens.Bearer);
|
|
131
132
|
},
|
|
132
133
|
onAuthError: function (error) {
|
|
133
134
|
var _a;
|
|
134
135
|
setError(error);
|
|
136
|
+
setIsAuthenticated(false);
|
|
137
|
+
setToken("");
|
|
138
|
+
setProfile(null);
|
|
139
|
+
setIsLoading(false);
|
|
135
140
|
(_a = options.onAuthError) === null || _a === void 0 ? void 0 : _a.call(options, error);
|
|
136
141
|
},
|
|
137
142
|
onTokenExpired: function () {
|
|
@@ -151,29 +156,35 @@ function useCAMSAuth(options) {
|
|
|
151
156
|
}
|
|
152
157
|
}, [options.storageKey]);
|
|
153
158
|
var login = React__default.useCallback(function (config) { return __awaiter(_this, void 0, void 0, function () {
|
|
154
|
-
var userProfile, err_1;
|
|
155
|
-
|
|
156
|
-
|
|
159
|
+
var loginConfig, userProfile, err_1;
|
|
160
|
+
var _a;
|
|
161
|
+
return __generator(this, function (_b) {
|
|
162
|
+
switch (_b.label) {
|
|
157
163
|
case 0:
|
|
158
164
|
if (!sessionManagerRef.current)
|
|
159
165
|
return [2 /*return*/];
|
|
160
166
|
setIsLoading(true);
|
|
161
167
|
setError(null);
|
|
162
|
-
|
|
168
|
+
_b.label = 1;
|
|
163
169
|
case 1:
|
|
164
|
-
|
|
165
|
-
|
|
170
|
+
_b.trys.push([1, 4, 5, 6]);
|
|
171
|
+
loginConfig = __assign(__assign({}, config), {
|
|
172
|
+
// autoClose: options.autoClose ?? config.autoClose,
|
|
173
|
+
idleTimeout: (_a = options.idleTimeout) !== null && _a !== void 0 ? _a : config.idleTimeout });
|
|
174
|
+
return [4 /*yield*/, sessionManagerRef.current.login(loginConfig)];
|
|
166
175
|
case 2:
|
|
167
|
-
|
|
176
|
+
_b.sent();
|
|
168
177
|
return [4 /*yield*/, sessionManagerRef.current.getProfile()];
|
|
169
178
|
case 3:
|
|
170
|
-
userProfile =
|
|
179
|
+
userProfile = _b.sent();
|
|
171
180
|
setProfile(userProfile);
|
|
172
181
|
return [3 /*break*/, 6];
|
|
173
182
|
case 4:
|
|
174
|
-
err_1 =
|
|
183
|
+
err_1 = _b.sent();
|
|
175
184
|
setError(err_1);
|
|
176
185
|
setIsAuthenticated(false);
|
|
186
|
+
setToken("");
|
|
187
|
+
setProfile(null);
|
|
177
188
|
return [3 /*break*/, 6];
|
|
178
189
|
case 5:
|
|
179
190
|
setIsLoading(false);
|
|
@@ -181,7 +192,7 @@ function useCAMSAuth(options) {
|
|
|
181
192
|
case 6: return [2 /*return*/];
|
|
182
193
|
}
|
|
183
194
|
});
|
|
184
|
-
}); }, []);
|
|
195
|
+
}); }, [options.idleTimeout]);
|
|
185
196
|
var logout = React__default.useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
186
197
|
return __generator(this, function (_a) {
|
|
187
198
|
switch (_a.label) {
|