@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
package/dist/index.esm.js
CHANGED
|
@@ -108,11 +108,16 @@ function useCAMSAuth(options) {
|
|
|
108
108
|
var _a;
|
|
109
109
|
setToken(res.userProfile.tokens.Bearer);
|
|
110
110
|
setIsAuthenticated(true);
|
|
111
|
+
setIsLoading(false);
|
|
111
112
|
(_a = options.onAuthSuccess) === null || _a === void 0 ? void 0 : _a.call(options, res.userProfile.tokens.Bearer);
|
|
112
113
|
},
|
|
113
114
|
onAuthError: function (error) {
|
|
114
115
|
var _a;
|
|
115
116
|
setError(error);
|
|
117
|
+
setIsAuthenticated(false);
|
|
118
|
+
setToken("");
|
|
119
|
+
setProfile(null);
|
|
120
|
+
setIsLoading(false);
|
|
116
121
|
(_a = options.onAuthError) === null || _a === void 0 ? void 0 : _a.call(options, error);
|
|
117
122
|
},
|
|
118
123
|
onTokenExpired: function () {
|
|
@@ -132,29 +137,35 @@ function useCAMSAuth(options) {
|
|
|
132
137
|
}
|
|
133
138
|
}, [options.storageKey]);
|
|
134
139
|
var login = useCallback(function (config) { return __awaiter(_this, void 0, void 0, function () {
|
|
135
|
-
var userProfile, err_1;
|
|
136
|
-
|
|
137
|
-
|
|
140
|
+
var loginConfig, userProfile, err_1;
|
|
141
|
+
var _a;
|
|
142
|
+
return __generator(this, function (_b) {
|
|
143
|
+
switch (_b.label) {
|
|
138
144
|
case 0:
|
|
139
145
|
if (!sessionManagerRef.current)
|
|
140
146
|
return [2 /*return*/];
|
|
141
147
|
setIsLoading(true);
|
|
142
148
|
setError(null);
|
|
143
|
-
|
|
149
|
+
_b.label = 1;
|
|
144
150
|
case 1:
|
|
145
|
-
|
|
146
|
-
|
|
151
|
+
_b.trys.push([1, 4, 5, 6]);
|
|
152
|
+
loginConfig = __assign(__assign({}, config), {
|
|
153
|
+
// autoClose: options.autoClose ?? config.autoClose,
|
|
154
|
+
idleTimeout: (_a = options.idleTimeout) !== null && _a !== void 0 ? _a : config.idleTimeout });
|
|
155
|
+
return [4 /*yield*/, sessionManagerRef.current.login(loginConfig)];
|
|
147
156
|
case 2:
|
|
148
|
-
|
|
157
|
+
_b.sent();
|
|
149
158
|
return [4 /*yield*/, sessionManagerRef.current.getProfile()];
|
|
150
159
|
case 3:
|
|
151
|
-
userProfile =
|
|
160
|
+
userProfile = _b.sent();
|
|
152
161
|
setProfile(userProfile);
|
|
153
162
|
return [3 /*break*/, 6];
|
|
154
163
|
case 4:
|
|
155
|
-
err_1 =
|
|
164
|
+
err_1 = _b.sent();
|
|
156
165
|
setError(err_1);
|
|
157
166
|
setIsAuthenticated(false);
|
|
167
|
+
setToken("");
|
|
168
|
+
setProfile(null);
|
|
158
169
|
return [3 /*break*/, 6];
|
|
159
170
|
case 5:
|
|
160
171
|
setIsLoading(false);
|
|
@@ -162,7 +173,7 @@ function useCAMSAuth(options) {
|
|
|
162
173
|
case 6: return [2 /*return*/];
|
|
163
174
|
}
|
|
164
175
|
});
|
|
165
|
-
}); }, []);
|
|
176
|
+
}); }, [options.idleTimeout]);
|
|
166
177
|
var logout = useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
167
178
|
return __generator(this, function (_a) {
|
|
168
179
|
switch (_a.label) {
|