@ordentco/addons-auth-provider 0.9.135 → 0.9.136-mfe
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/config.ts +1 -1
- package/dist/config.js +2 -2
- package/dist/config.js.map +1 -1
- package/dist/services/auth.d.ts +15 -15
- package/dist/services/auth.js +2 -2
- package/dist/services/auth.js.map +1 -1
- package/dist/services/custom-axios.js +6 -5
- package/dist/services/custom-axios.js.map +1 -1
- package/dist/services/system.d.ts +1 -1
- package/dist/services/user.d.ts +2 -2
- package/dist/src/auth.d.ts +12 -3
- package/dist/src/auth.js +393 -269
- package/dist/src/auth.js.map +1 -1
- package/dist/src/index.d.ts +2 -2
- package/dist/src/index.js +8 -16
- package/dist/src/index.js.map +1 -1
- package/dist/src/types/onboarding.d.ts +11 -0
- package/dist/src/types/onboarding.js +14 -0
- package/dist/src/types/onboarding.js.map +1 -0
- package/dist/src/types/router.d.ts +10 -0
- package/dist/src/types/router.js +3 -0
- package/dist/src/types/router.js.map +1 -0
- package/dist/types/product.d.ts +8 -3
- package/dist/types/product.js +5 -0
- package/dist/types/product.js.map +1 -1
- package/dist/types/user.d.ts +1 -1
- package/dist/types/workflow.d.ts +1 -1
- package/dist/utils/auth.d.ts +2 -2
- package/dist/utils/auth.js.map +1 -1
- package/dist/utils/env.d.ts +1 -0
- package/dist/utils/env.js +55 -0
- package/dist/utils/env.js.map +1 -0
- package/package.json +4 -4
- package/services/auth.ts +4 -4
- package/services/custom-axios.ts +8 -8
- package/src/auth.tsx +509 -255
- package/src/index.ts +2 -2
- package/src/types/onboarding.ts +14 -0
- package/src/types/router.ts +10 -0
- package/types/product.ts +9 -4
- package/types/user.ts +1 -1
- package/types/workflow.ts +1 -1
- package/utils/auth.ts +109 -110
- package/utils/config.ts +0 -63
- package/utils/env.ts +63 -0
package/dist/src/auth.js
CHANGED
|
@@ -70,31 +70,28 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
70
70
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
71
71
|
};
|
|
72
72
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
73
|
-
exports.useAuth = exports.AuthProvider = exports.UserType = void 0;
|
|
73
|
+
exports.useAuth = exports.AuthProvider = exports.noopRouter = exports.UserType = void 0;
|
|
74
74
|
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
75
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
76
|
-
var react_1 = require("react");
|
|
77
|
-
var router_1 = require("next/router");
|
|
78
|
-
var services_1 = require("../services");
|
|
79
|
-
// import { message } from "antd";
|
|
80
|
-
var react_idle_timer_1 = require("react-idle-timer");
|
|
81
|
-
var auth_1 = require("../utils/auth");
|
|
82
|
-
var types_1 = require("../types");
|
|
83
|
-
// import { ArgsProps } from "antd/lib/message";
|
|
84
|
-
var mergeWith_1 = __importDefault(require("lodash/mergeWith"));
|
|
85
75
|
var concat_1 = __importDefault(require("lodash/concat"));
|
|
86
76
|
var get_1 = __importDefault(require("lodash/get"));
|
|
77
|
+
var mergeWith_1 = __importDefault(require("lodash/mergeWith"));
|
|
87
78
|
var snakeCase_1 = __importDefault(require("lodash/snakeCase"));
|
|
79
|
+
var react_1 = require("react");
|
|
80
|
+
var react_idle_timer_1 = require("react-idle-timer");
|
|
81
|
+
var services_1 = require("../services");
|
|
82
|
+
var types_1 = require("../types");
|
|
83
|
+
var auth_1 = require("../utils/auth");
|
|
88
84
|
var is_empty_1 = require("../utils/is-empty");
|
|
89
|
-
|
|
85
|
+
var onboarding_1 = require("./types/onboarding");
|
|
90
86
|
var FIFTEEN_MINUTES = 15 * 60 * 1000;
|
|
87
|
+
var SESSION_VALIDITY_MS = 5 * 60 * 1000; // 5 minutes
|
|
88
|
+
var initialProductAuthorities = (0, auth_1.createProductAuthorities)();
|
|
91
89
|
var UserType;
|
|
92
90
|
(function (UserType) {
|
|
93
91
|
UserType["BankAdmin"] = "bank-admin";
|
|
94
92
|
UserType["CustomerAdmin"] = "customer-admin";
|
|
95
93
|
UserType["CustomerUser"] = "customer-user";
|
|
96
94
|
})(UserType || (exports.UserType = UserType = {}));
|
|
97
|
-
var initialProductAuthorities = (0, auth_1.createProductAuthorities)();
|
|
98
95
|
var AUTH_INITIAL_VALUES = {
|
|
99
96
|
token: null,
|
|
100
97
|
authorities: new Map(),
|
|
@@ -107,153 +104,210 @@ var AUTH_INITIAL_VALUES = {
|
|
|
107
104
|
companyName: "",
|
|
108
105
|
userMode: "",
|
|
109
106
|
companyLevel: "",
|
|
107
|
+
onboardingTourStatus: onboarding_1.OnboardingTourStatus.Done,
|
|
110
108
|
userID: null,
|
|
111
109
|
roleID: null,
|
|
112
110
|
roleIDs: null,
|
|
113
111
|
holdingID: null,
|
|
114
112
|
isLoading: false,
|
|
113
|
+
isIntraday: false,
|
|
115
114
|
menus: [],
|
|
116
115
|
loggedIn: false,
|
|
117
116
|
guard: function () {
|
|
118
117
|
throw new Error("Function not implemented.");
|
|
119
118
|
},
|
|
120
|
-
passwordLogin: function (
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
119
|
+
passwordLogin: function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
120
|
+
return __generator(this, function (_a) {
|
|
121
|
+
throw new Error("Function not implemented.");
|
|
122
|
+
});
|
|
123
|
+
}); },
|
|
124
|
+
ssoLogin: function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
125
|
+
return __generator(this, function (_a) {
|
|
126
|
+
throw new Error("Function not implemented.");
|
|
127
|
+
});
|
|
128
|
+
}); },
|
|
129
|
+
logout: function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
130
|
+
return __generator(this, function (_a) {
|
|
131
|
+
throw new Error("Function not implemented.");
|
|
132
|
+
});
|
|
133
|
+
}); },
|
|
134
|
+
canIApprove: function () {
|
|
124
135
|
throw new Error("Function not implemented.");
|
|
125
136
|
},
|
|
126
|
-
|
|
137
|
+
canIDelete: function () {
|
|
127
138
|
throw new Error("Function not implemented.");
|
|
128
139
|
},
|
|
129
|
-
|
|
140
|
+
canIEdit: function () {
|
|
130
141
|
throw new Error("Function not implemented.");
|
|
131
142
|
},
|
|
132
143
|
menuData: [],
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
},
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
144
|
+
ssoQlolaLogin: function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
145
|
+
return __generator(this, function (_a) {
|
|
146
|
+
throw new Error("Function not implemented.");
|
|
147
|
+
});
|
|
148
|
+
}); },
|
|
149
|
+
verifyUserQuestion: function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
150
|
+
return __generator(this, function (_a) {
|
|
151
|
+
throw new Error("Function not implemented.");
|
|
152
|
+
});
|
|
153
|
+
}); },
|
|
154
|
+
verifyChangePasswordToken: function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
155
|
+
return __generator(this, function (_a) {
|
|
156
|
+
throw new Error("Function not implemented.");
|
|
157
|
+
});
|
|
158
|
+
}); },
|
|
159
|
+
forgotPassword: function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
160
|
+
return __generator(this, function (_a) {
|
|
161
|
+
throw new Error("Function not implemented.");
|
|
162
|
+
});
|
|
163
|
+
}); },
|
|
164
|
+
login: function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
165
|
+
return __generator(this, function (_a) {
|
|
166
|
+
throw new Error("Function not implemented.");
|
|
167
|
+
});
|
|
168
|
+
}); },
|
|
169
|
+
checkToChangePassword: function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
170
|
+
return __generator(this, function (_a) {
|
|
171
|
+
throw new Error("Function not implemented.");
|
|
172
|
+
});
|
|
173
|
+
}); },
|
|
174
|
+
passwordLoginWithCheck: function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
175
|
+
return __generator(this, function (_a) {
|
|
176
|
+
throw new Error("Function not implemented.");
|
|
177
|
+
});
|
|
178
|
+
}); },
|
|
179
|
+
requestChangePassword: function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
180
|
+
return __generator(this, function (_a) {
|
|
181
|
+
throw new Error("Function not implemented.");
|
|
182
|
+
});
|
|
183
|
+
}); },
|
|
184
|
+
action: null,
|
|
185
|
+
onLeaveAction: null,
|
|
186
|
+
setOnLeaveAction: null,
|
|
187
|
+
countryCode: "",
|
|
188
|
+
setToken: function () {
|
|
161
189
|
throw new Error("Function not implemented.");
|
|
162
190
|
},
|
|
163
|
-
setIsLoading: function (
|
|
191
|
+
setIsLoading: function () {
|
|
164
192
|
throw new Error("Function not implemented.");
|
|
165
193
|
},
|
|
166
|
-
|
|
194
|
+
setUserType: function () {
|
|
167
195
|
throw new Error("Function not implemented.");
|
|
168
196
|
},
|
|
169
|
-
action: null,
|
|
170
|
-
onLeaveAction: null,
|
|
171
|
-
setOnLeaveAction: null,
|
|
172
|
-
countryCode: "",
|
|
173
197
|
companyCode: "",
|
|
174
198
|
region: "",
|
|
175
|
-
checkToken: function () {
|
|
176
|
-
|
|
177
|
-
|
|
199
|
+
checkToken: function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
200
|
+
return __generator(this, function (_a) {
|
|
201
|
+
throw new Error("Function not implemented.");
|
|
202
|
+
});
|
|
203
|
+
}); },
|
|
178
204
|
};
|
|
179
205
|
// export const getStaticProps:GetStaticProps<{}> = async () => {
|
|
180
206
|
//
|
|
181
207
|
// }
|
|
182
208
|
var AuthContext = (0, react_1.createContext)(AUTH_INITIAL_VALUES);
|
|
209
|
+
exports.noopRouter = {
|
|
210
|
+
push: function () { },
|
|
211
|
+
replace: function () { },
|
|
212
|
+
basePath: "",
|
|
213
|
+
asPath: "",
|
|
214
|
+
events: {
|
|
215
|
+
on: function () { },
|
|
216
|
+
off: function () { },
|
|
217
|
+
},
|
|
218
|
+
};
|
|
183
219
|
var AuthProvider = function (_a) {
|
|
184
|
-
var children = _a.children, apiUrl = _a.apiUrl;
|
|
185
|
-
var
|
|
186
|
-
var _b = (0, react_1.useState)(function () {
|
|
220
|
+
var children = _a.children, apiUrl = _a.apiUrl, _b = _a.router, router = _b === void 0 ? exports.noopRouter : _b, _c = _a.loginRoute, loginRoute = _c === void 0 ? "/main-page" : _c, _d = _a.baseRoute, baseRoute = _d === void 0 ? "/" : _d;
|
|
221
|
+
var _e = (0, react_1.useState)(function () {
|
|
187
222
|
if (typeof window !== "undefined") {
|
|
188
|
-
|
|
189
|
-
return t;
|
|
223
|
+
return localStorage.getItem("access-token");
|
|
190
224
|
}
|
|
191
225
|
return null;
|
|
192
|
-
}), token =
|
|
226
|
+
}), token = _e[0], setToken = _e[1];
|
|
193
227
|
var authService = (0, react_1.useMemo)(function () { return (0, services_1.AuthService)(); }, [apiUrl, token]);
|
|
194
|
-
var
|
|
195
|
-
var
|
|
196
|
-
var
|
|
197
|
-
var
|
|
198
|
-
var
|
|
199
|
-
var
|
|
200
|
-
var
|
|
201
|
-
var
|
|
202
|
-
var
|
|
203
|
-
var
|
|
204
|
-
var
|
|
205
|
-
var
|
|
206
|
-
var
|
|
207
|
-
var
|
|
208
|
-
var
|
|
209
|
-
var
|
|
210
|
-
var
|
|
211
|
-
var
|
|
212
|
-
var
|
|
213
|
-
var
|
|
214
|
-
var
|
|
215
|
-
var
|
|
216
|
-
var
|
|
217
|
-
var
|
|
228
|
+
var _f = (0, react_1.useState)(function () { return new Map(); }), authorities = _f[0], setAuthorities = _f[1];
|
|
229
|
+
var _g = (0, react_1.useState)("Guest"), username = _g[0], setUsername = _g[1];
|
|
230
|
+
var _h = (0, react_1.useState)(null), userType = _h[0], setUserType = _h[1];
|
|
231
|
+
var _j = (0, react_1.useState)(null), companyID = _j[0], setCompanyID = _j[1];
|
|
232
|
+
var _k = (0, react_1.useState)(""), companyName = _k[0], setCompanyName = _k[1];
|
|
233
|
+
var _l = (0, react_1.useState)(""), userMode = _l[0], setUserMode = _l[1];
|
|
234
|
+
var _m = (0, react_1.useState)(""), companyLevel = _m[0], setCompanyLevel = _m[1];
|
|
235
|
+
var _o = (0, react_1.useState)(onboarding_1.OnboardingTourStatus.Done), onboardingTourStatus = _o[0], setOnboardingTourStatus = _o[1];
|
|
236
|
+
var _p = (0, react_1.useState)(null), userID = _p[0], setUserID = _p[1];
|
|
237
|
+
var _q = (0, react_1.useState)(null), roleID = _q[0], setRoleID = _q[1];
|
|
238
|
+
var _r = (0, react_1.useState)([]), roleIDs = _r[0], setRoleIDs = _r[1];
|
|
239
|
+
var _s = (0, react_1.useState)(null), holdingID = _s[0], setHoldingID = _s[1];
|
|
240
|
+
var _t = (0, react_1.useState)(false), alertMenuError = _t[0], setAlertMenuError = _t[1];
|
|
241
|
+
var _u = (0, react_1.useState)(false), _openModal = _u[0], setOpenModal = _u[1];
|
|
242
|
+
var _v = (0, react_1.useState)([]), menus = _v[0], setMenus = _v[1];
|
|
243
|
+
var _w = (0, react_1.useState)(FIFTEEN_MINUTES), isMinutes = _w[0], setIsMinutes = _w[1];
|
|
244
|
+
var _x = (0, react_1.useState)(false), isIntraday = _x[0], setIsIntraday = _x[1];
|
|
245
|
+
var _y = (0, react_1.useState)(false), isLoading = _y[0], setIsLoading = _y[1];
|
|
246
|
+
var _z = (0, react_1.useState)(initialProductAuthorities), productAuthorities = _z[0], setProductAuthorities = _z[1];
|
|
247
|
+
var _0 = (0, react_1.useState)(false), isAuthoritiesReady = _0[0], setIsAuthoritiesReady = _0[1];
|
|
248
|
+
var _1 = (0, react_1.useState)(null), sessionLastValidatedAt = _1[0], setSessionLastValidatedAt = _1[1];
|
|
249
|
+
var _2 = (0, react_1.useState)([]), menuData = _2[0], setMenuData = _2[1];
|
|
250
|
+
var _3 = (0, react_1.useState)({}), action = _3[0], _setAction = _3[1];
|
|
251
|
+
var _4 = (0, react_1.useState)({}), onLeaveAction = _4[0], setOnLeaveAction = _4[1];
|
|
252
|
+
var _5 = (0, react_1.useState)(""), countryCode = _5[0], setCountryCode = _5[1];
|
|
253
|
+
var _6 = (0, react_1.useState)(""), companyCode = _6[0], setCompanyCode = _6[1];
|
|
254
|
+
var _7 = (0, react_1.useState)(""), region = _7[0], setRegion = _7[1];
|
|
218
255
|
var prevPathnameRef = (0, react_1.useRef)("");
|
|
219
256
|
var loggedIn = (0, react_1.useMemo)(function () { return !!token; }, [token]);
|
|
220
257
|
var guard = (0, react_1.useCallback)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
221
|
-
var
|
|
258
|
+
var response, error_1, agent, menu, newMenuData, newMenus, refreshToken_1, refresh, newToken, newRefreshToken, _a, username_1, companyCode_1, userID_1, companyID_1, a, productRoles, privilegesRecords, productTypeEnumValuesFromProductRoles, productTypeEnumValuesFromHardcode, remainingProductTypeEnum, productTypeEnumKeyFromHardcode, productTypeEnumKeyFromProductRoles, allProductTypeEnum, menuDataMultipaymentCreate_1, menuDataMultipayment, multipaymentProducts;
|
|
222
259
|
var _b, _c, _d, _e, _f, _g, _h, _j;
|
|
223
260
|
return __generator(this, function (_k) {
|
|
224
261
|
switch (_k.label) {
|
|
225
262
|
case 0:
|
|
226
|
-
|
|
263
|
+
// Session Freshness Check
|
|
264
|
+
if (sessionLastValidatedAt &&
|
|
265
|
+
Date.now() - sessionLastValidatedAt < SESSION_VALIDITY_MS) {
|
|
266
|
+
// Ensure authorities are marked as ready if the router reset them
|
|
267
|
+
if (!isAuthoritiesReady)
|
|
268
|
+
setIsAuthoritiesReady(true);
|
|
269
|
+
return [2 /*return*/]; // The context is fresh, so we exit immediately.
|
|
270
|
+
}
|
|
271
|
+
// No Token Check
|
|
272
|
+
if (!token) {
|
|
273
|
+
router.push(loginRoute);
|
|
274
|
+
return [2 /*return*/];
|
|
275
|
+
}
|
|
276
|
+
// --- Start Validation Flow ---
|
|
227
277
|
setIsAuthoritiesReady(false);
|
|
228
278
|
_k.label = 1;
|
|
229
279
|
case 1:
|
|
230
280
|
_k.trys.push([1, 3, , 4]);
|
|
231
281
|
return [4 /*yield*/, authService.validateToken()];
|
|
232
282
|
case 2:
|
|
233
|
-
|
|
283
|
+
response = _k.sent();
|
|
234
284
|
return [3 /*break*/, 4];
|
|
235
285
|
case 3:
|
|
236
286
|
error_1 = _k.sent();
|
|
237
287
|
agent = typeof window !== "undefined" && localStorage.getItem("agent");
|
|
238
|
-
if (agent === "qlola" &&
|
|
288
|
+
if (agent === "qlola" &&
|
|
289
|
+
![200].includes(((_c = (_b = error_1 === null || error_1 === void 0 ? void 0 : error_1.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.code) || ((_d = error_1 === null || error_1 === void 0 ? void 0 : error_1.response) === null || _d === void 0 ? void 0 : _d.status))) {
|
|
239
290
|
localStorage.removeItem("access-token");
|
|
240
291
|
localStorage.removeItem("refresh-token");
|
|
241
292
|
setToken(function () { return null; });
|
|
293
|
+
setSessionLastValidatedAt(null);
|
|
242
294
|
return [2 /*return*/, window.close()];
|
|
243
295
|
}
|
|
244
296
|
console.log({ error: error_1 });
|
|
245
|
-
|
|
297
|
+
response = error_1;
|
|
246
298
|
return [3 /*break*/, 4];
|
|
247
299
|
case 4: return [4 /*yield*/, authService.validateMenu(token)];
|
|
248
300
|
case 5:
|
|
249
301
|
menu = _k.sent();
|
|
250
302
|
if (menu.data.code !== 200 || !menu)
|
|
251
303
|
setAlertMenuError(true);
|
|
252
|
-
newMenuData = (0, get_1.default)(menu,
|
|
253
|
-
newMenus = newMenuData
|
|
304
|
+
newMenuData = (0, get_1.default)(menu, "data.data", []);
|
|
305
|
+
newMenus = newMenuData
|
|
306
|
+
.filter(function (item) { return item.productName !== ""; })
|
|
307
|
+
.map(function (item) { return item.productName; });
|
|
254
308
|
setMenus(newMenus);
|
|
255
309
|
setMenuData(newMenuData);
|
|
256
|
-
if (!(
|
|
310
|
+
if (!(response.status === 401)) return [3 /*break*/, 8];
|
|
257
311
|
if (!(typeof window !== "undefined")) return [3 /*break*/, 7];
|
|
258
312
|
refreshToken_1 = localStorage.getItem("refresh-token");
|
|
259
313
|
if (!refreshToken_1) return [3 /*break*/, 7];
|
|
@@ -268,40 +322,43 @@ var AuthProvider = function (_a) {
|
|
|
268
322
|
_k.label = 7;
|
|
269
323
|
case 7: return [3 /*break*/, 9];
|
|
270
324
|
case 8:
|
|
271
|
-
if (
|
|
325
|
+
if (response.status !== 200) {
|
|
272
326
|
localStorage.removeItem("access-token");
|
|
273
327
|
localStorage.removeItem("refresh-token");
|
|
274
328
|
setToken(function () { return null; });
|
|
275
|
-
|
|
329
|
+
setSessionLastValidatedAt(null);
|
|
330
|
+
router === null || router === void 0 ? void 0 : router.push("".concat(loginRoute, "?logout=true"));
|
|
276
331
|
return [2 /*return*/];
|
|
277
332
|
}
|
|
278
333
|
_k.label = 9;
|
|
279
334
|
case 9:
|
|
280
|
-
if (
|
|
281
|
-
_a =
|
|
335
|
+
if (response === null || response === void 0 ? void 0 : response.data) {
|
|
336
|
+
_a = response.data, username_1 = _a.username, companyCode_1 = _a.companyCode, userID_1 = _a.userID, companyID_1 = _a.companyID;
|
|
282
337
|
localStorage.setItem("login", "".concat(username_1, "-").concat(companyCode_1, "-").concat(userID_1, "-").concat(companyID_1));
|
|
283
338
|
}
|
|
284
|
-
setRoleID(function () { return
|
|
285
|
-
setRoleIDs(function () { return
|
|
286
|
-
setCompanyID(function () { var _a; return (_a =
|
|
287
|
-
setCompanyName(function () { var _a; return (_a =
|
|
288
|
-
setUserID(function () { var _a; return (_a =
|
|
289
|
-
setHoldingID(function () { var _a; return (_a =
|
|
290
|
-
setUsername(function () { var _a; return ((_a =
|
|
291
|
-
setUserType(function () { var _a; return ((_a =
|
|
292
|
-
setCountryCode(function () { return
|
|
293
|
-
setCompanyCode(function () { var _a; return ((_a =
|
|
294
|
-
setRegion(function () { return
|
|
295
|
-
setUserMode(function () { var _a; return ((_a =
|
|
296
|
-
setCompanyLevel(function () { var _a; return ((_a =
|
|
297
|
-
|
|
298
|
-
|
|
339
|
+
setRoleID(function () { return response.data.roleIDs[0]; });
|
|
340
|
+
setRoleIDs(function () { return response.data.roleIDs; });
|
|
341
|
+
setCompanyID(function () { var _a; return (_a = response.data) === null || _a === void 0 ? void 0 : _a.companyID; });
|
|
342
|
+
setCompanyName(function () { var _a; return (_a = response.data) === null || _a === void 0 ? void 0 : _a.companyName; });
|
|
343
|
+
setUserID(function () { var _a; return (_a = response.data) === null || _a === void 0 ? void 0 : _a.userID; });
|
|
344
|
+
setHoldingID(function () { var _a; return (_a = response.data) === null || _a === void 0 ? void 0 : _a.holdingID; });
|
|
345
|
+
setUsername(function () { var _a; return ((_a = response.data) === null || _a === void 0 ? void 0 : _a.username) || "Guest"; });
|
|
346
|
+
setUserType(function () { var _a; return ((_a = response.data) === null || _a === void 0 ? void 0 : _a.userType) || null; });
|
|
347
|
+
setCountryCode(function () { return response.data.countryCode; });
|
|
348
|
+
setCompanyCode(function () { var _a; return ((_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.companyCode) || ""; });
|
|
349
|
+
setRegion(function () { return response.data.region || ""; });
|
|
350
|
+
setUserMode(function () { var _a; return ((_a = response.data) === null || _a === void 0 ? void 0 : _a.userMode) || ""; });
|
|
351
|
+
setCompanyLevel(function () { var _a; return ((_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.companyLevel) || ""; });
|
|
352
|
+
setIsIntraday(function () { var _a; return ((_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.isIntraday) || false; });
|
|
353
|
+
setOnboardingTourStatus(function () { var _a; return ((_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.onboardingTourStatus) || onboarding_1.OnboardingTourStatus.Done; });
|
|
354
|
+
a = new Map();
|
|
355
|
+
productRoles = ((_j = response.data) === null || _j === void 0 ? void 0 : _j.productRoles) || [];
|
|
299
356
|
productRoles.forEach(function (r) {
|
|
300
|
-
|
|
357
|
+
a.set(r.productName, r.authorities);
|
|
301
358
|
});
|
|
302
|
-
setAuthorities(function () { return
|
|
303
|
-
|
|
304
|
-
productTypeEnumValuesFromProductRoles = Array.from(
|
|
359
|
+
setAuthorities(function () { return a; });
|
|
360
|
+
privilegesRecords = __assign({}, productAuthorities);
|
|
361
|
+
productTypeEnumValuesFromProductRoles = Array.from(a.keys());
|
|
305
362
|
productTypeEnumValuesFromHardcode = Array.from(Object.values(types_1.ProductTypeEnum));
|
|
306
363
|
remainingProductTypeEnum = [
|
|
307
364
|
productTypeEnumValuesFromProductRoles,
|
|
@@ -313,7 +370,7 @@ var AuthProvider = function (_a) {
|
|
|
313
370
|
// FIXME: delete this logic beacuse expose all product, need to get from variable productRoles / a!
|
|
314
371
|
allProductTypeEnum.forEach(function (_a) {
|
|
315
372
|
var productKey = _a[0], productValue = _a[1];
|
|
316
|
-
var productRole =
|
|
373
|
+
var productRole = a.get(productValue) || [];
|
|
317
374
|
productRole = productRole.map(function (e) { return e.split(":")[0]; });
|
|
318
375
|
var productAuthority = {};
|
|
319
376
|
Object.entries(types_1.AuthorityLevelEnum).forEach(function (_a) {
|
|
@@ -321,23 +378,24 @@ var AuthProvider = function (_a) {
|
|
|
321
378
|
productAuthority[key] = productRole.includes(value);
|
|
322
379
|
});
|
|
323
380
|
productAuthority["anyAuthority"] = productRole.length > 0;
|
|
324
|
-
productAuthority["allAuthority"] =
|
|
325
|
-
|
|
381
|
+
productAuthority["allAuthority"] =
|
|
382
|
+
productRole.length >= Object.entries(types_1.AuthorityLevelEnum).length;
|
|
383
|
+
privilegesRecords[productKey] = productAuthority;
|
|
326
384
|
});
|
|
327
385
|
// Combine Authority All Product Multipayment
|
|
328
|
-
if (!(0, is_empty_1.isEmpty)(newMenuData.find(function (item) {
|
|
329
|
-
|
|
386
|
+
if (!(0, is_empty_1.isEmpty)(newMenuData.find(function (item) {
|
|
387
|
+
return item.productName === types_1.MultipaymentAuthorityEnum["create"];
|
|
388
|
+
}))) {
|
|
389
|
+
menuDataMultipaymentCreate_1 = newMenuData.find(function (item) { return item.productName === types_1.MultipaymentAuthorityEnum["create"]; });
|
|
330
390
|
menuDataMultipayment = newMenuData.filter(function (item) { return item.parentID === menuDataMultipaymentCreate_1.menuID; });
|
|
331
391
|
multipaymentProducts = menuDataMultipayment.map(function (item) { return item["name"]; });
|
|
332
392
|
multipaymentProducts.map(function (item) {
|
|
333
|
-
|
|
393
|
+
privilegesRecords["MULTIPAYMENT"] = (0, mergeWith_1.default)(privilegesRecords["MULTIPAYMENT"], privilegesRecords[(0, snakeCase_1.default)(item).toUpperCase()], function (objValue, srcValue) { return objValue || srcValue; });
|
|
334
394
|
});
|
|
335
395
|
}
|
|
336
|
-
setProductAuthorities(
|
|
396
|
+
setProductAuthorities(privilegesRecords);
|
|
337
397
|
setIsAuthoritiesReady(true);
|
|
338
|
-
|
|
339
|
-
case 10:
|
|
340
|
-
router.push("/main-page");
|
|
398
|
+
setSessionLastValidatedAt(Date.now());
|
|
341
399
|
return [2 /*return*/];
|
|
342
400
|
}
|
|
343
401
|
});
|
|
@@ -354,7 +412,7 @@ var AuthProvider = function (_a) {
|
|
|
354
412
|
var productKey = (0, snakeCase_1.default)(product).toUpperCase();
|
|
355
413
|
if (!productKey)
|
|
356
414
|
return false;
|
|
357
|
-
// @ts-
|
|
415
|
+
// @ts-expect-error product authorities key is a enum keyof
|
|
358
416
|
var authority = productAuthorities[productKey];
|
|
359
417
|
if (!authority)
|
|
360
418
|
return false;
|
|
@@ -370,19 +428,33 @@ var AuthProvider = function (_a) {
|
|
|
370
428
|
});
|
|
371
429
|
if (roleIDs.length > 0) {
|
|
372
430
|
var participants = __spreadArray(__spreadArray(__spreadArray([], (((_a = flows === null || flows === void 0 ? void 0 : flows.approver) === null || _a === void 0 ? void 0 : _a.participants) ? (_b = flows === null || flows === void 0 ? void 0 : flows.approver) === null || _b === void 0 ? void 0 : _b.participants : []), true), (((_c = flows === null || flows === void 0 ? void 0 : flows.verifier) === null || _c === void 0 ? void 0 : _c.participants) ? (_d = flows === null || flows === void 0 ? void 0 : flows.verifier) === null || _d === void 0 ? void 0 : _d.participants : []), true), (((_e = flows === null || flows === void 0 ? void 0 : flows.releaser) === null || _e === void 0 ? void 0 : _e.participants) ? (_f = flows === null || flows === void 0 ? void 0 : flows.releaser) === null || _f === void 0 ? void 0 : _f.participants : []), true);
|
|
373
|
-
var participant = participants.find(function (p) {
|
|
431
|
+
var participant = participants.find(function (p) {
|
|
432
|
+
return roleIDs.includes("".concat(p.roleID)) &&
|
|
433
|
+
p.step === currentStep &&
|
|
434
|
+
p.userName === username;
|
|
435
|
+
});
|
|
374
436
|
alreadyApprove = !!(participant === null || participant === void 0 ? void 0 : participant.approvedAt);
|
|
375
437
|
}
|
|
376
|
-
if (participantUserIDs
|
|
438
|
+
if (participantUserIDs === null || participantUserIDs === void 0 ? void 0 : participantUserIDs.includes(userID))
|
|
377
439
|
return false;
|
|
378
|
-
if (Number(userID) === Number(createdBy.userID) &&
|
|
440
|
+
if (Number(userID) === Number(createdBy.userID) &&
|
|
441
|
+
currentStep !== "releaser")
|
|
379
442
|
return false;
|
|
380
|
-
var isCanIApprove = (approve &&
|
|
443
|
+
var isCanIApprove = (approve &&
|
|
444
|
+
currentStep === types_1.StepType.Signer &&
|
|
445
|
+
roleAllowed &&
|
|
446
|
+
!alreadyApprove &&
|
|
447
|
+
!isMaker) ||
|
|
381
448
|
(verify &&
|
|
382
|
-
(currentStep === types_1.StepType.Verifier ||
|
|
449
|
+
(currentStep === types_1.StepType.Verifier ||
|
|
450
|
+
currentStep === types_1.StepType.Checker) &&
|
|
383
451
|
roleAllowed &&
|
|
384
|
-
!alreadyApprove &&
|
|
385
|
-
|
|
452
|
+
!alreadyApprove &&
|
|
453
|
+
!isMaker) ||
|
|
454
|
+
(release &&
|
|
455
|
+
currentStep === types_1.StepType.Releaser &&
|
|
456
|
+
roleAllowed &&
|
|
457
|
+
!alreadyApprove);
|
|
386
458
|
if (status) {
|
|
387
459
|
return isCanIApprove && status === types_1.TaskStatus.Pending;
|
|
388
460
|
}
|
|
@@ -392,7 +464,7 @@ var AuthProvider = function (_a) {
|
|
|
392
464
|
var productKey = (0, snakeCase_1.default)(product).toUpperCase();
|
|
393
465
|
if (!productKey)
|
|
394
466
|
return false;
|
|
395
|
-
// @ts-
|
|
467
|
+
// @ts-expect-error product authorities key is a enum keyof
|
|
396
468
|
var authority = productAuthorities[productKey];
|
|
397
469
|
if (!authority)
|
|
398
470
|
return false;
|
|
@@ -411,15 +483,15 @@ var AuthProvider = function (_a) {
|
|
|
411
483
|
var productKey = (0, snakeCase_1.default)(product).toUpperCase();
|
|
412
484
|
if (!productKey)
|
|
413
485
|
return false;
|
|
414
|
-
// @ts-
|
|
486
|
+
// @ts-expect-error product authorities key is a enum keyof
|
|
415
487
|
var authority = productAuthorities[productKey];
|
|
416
488
|
if (!authority)
|
|
417
489
|
return false;
|
|
418
490
|
var modify = (0, get_1.default)(authority, "modify");
|
|
419
|
-
return (status === types_1.TaskStatus.Draft || status === types_1.TaskStatus.Returned) && modify;
|
|
491
|
+
return ((status === types_1.TaskStatus.Draft || status === types_1.TaskStatus.Returned) && modify);
|
|
420
492
|
};
|
|
421
493
|
var passwordLogin = (0, react_1.useCallback)(function (username, password, tokenFCM) { return __awaiter(void 0, void 0, void 0, function () {
|
|
422
|
-
var
|
|
494
|
+
var response_1, error_2;
|
|
423
495
|
return __generator(this, function (_a) {
|
|
424
496
|
switch (_a.label) {
|
|
425
497
|
case 0:
|
|
@@ -429,11 +501,11 @@ var AuthProvider = function (_a) {
|
|
|
429
501
|
_a.trys.push([1, 3, 4, 5]);
|
|
430
502
|
return [4 /*yield*/, authService.passwordLogin(username, password, tokenFCM)];
|
|
431
503
|
case 2:
|
|
432
|
-
|
|
433
|
-
setToken(function () { return
|
|
434
|
-
localStorage.setItem("access-token",
|
|
435
|
-
localStorage.setItem("refresh-token",
|
|
436
|
-
router.push(
|
|
504
|
+
response_1 = _a.sent();
|
|
505
|
+
setToken(function () { return response_1.data.data.accessToken; });
|
|
506
|
+
localStorage.setItem("access-token", response_1.data.data.accessToken);
|
|
507
|
+
localStorage.setItem("refresh-token", response_1.data.data.refreshToken);
|
|
508
|
+
router.push(baseRoute);
|
|
437
509
|
return [3 /*break*/, 5];
|
|
438
510
|
case 3:
|
|
439
511
|
error_2 = _a.sent();
|
|
@@ -462,23 +534,24 @@ var AuthProvider = function (_a) {
|
|
|
462
534
|
return setIsMinutes(FIFTEEN_MINUTES);
|
|
463
535
|
};
|
|
464
536
|
var ssoLogin = (0, react_1.useCallback)(function (userId, sessionId, dtTime, onError) { return __awaiter(void 0, void 0, void 0, function () {
|
|
465
|
-
var
|
|
537
|
+
var response_2, error_3;
|
|
466
538
|
return __generator(this, function (_a) {
|
|
467
539
|
switch (_a.label) {
|
|
468
540
|
case 0:
|
|
469
541
|
_a.trys.push([0, 2, , 3]);
|
|
470
542
|
return [4 /*yield*/, authService.ssoLogin(userId, sessionId, dtTime)];
|
|
471
543
|
case 1:
|
|
472
|
-
|
|
473
|
-
if (
|
|
474
|
-
if (
|
|
544
|
+
response_2 = _a.sent();
|
|
545
|
+
if (response_2.status !== 200) {
|
|
546
|
+
if (response_2.status === 409) {
|
|
475
547
|
setOpenModal(true);
|
|
548
|
+
}
|
|
476
549
|
return [2 /*return*/];
|
|
477
550
|
}
|
|
478
|
-
setToken(function () { return
|
|
479
|
-
localStorage.setItem("access-token",
|
|
480
|
-
localStorage.setItem("refresh-token",
|
|
481
|
-
router.push(
|
|
551
|
+
setToken(function () { return response_2.data.data.accessToken; });
|
|
552
|
+
localStorage.setItem("access-token", response_2.data.data.accessToken);
|
|
553
|
+
localStorage.setItem("refresh-token", response_2.data.data.refreshToken);
|
|
554
|
+
router.push(baseRoute);
|
|
482
555
|
return [3 /*break*/, 3];
|
|
483
556
|
case 2:
|
|
484
557
|
error_3 = _a.sent();
|
|
@@ -496,7 +569,7 @@ var AuthProvider = function (_a) {
|
|
|
496
569
|
args_1[_i] = arguments[_i];
|
|
497
570
|
}
|
|
498
571
|
return __awaiter(void 0, __spreadArray([], args_1, true), void 0, function (path) {
|
|
499
|
-
if (path === void 0) { path = "
|
|
572
|
+
if (path === void 0) { path = "".concat(loginRoute, "?logout=true"); }
|
|
500
573
|
return __generator(this, function (_a) {
|
|
501
574
|
try {
|
|
502
575
|
// await authService.logout();
|
|
@@ -516,6 +589,7 @@ var AuthProvider = function (_a) {
|
|
|
516
589
|
sessionStorage.clear();
|
|
517
590
|
router.push(path);
|
|
518
591
|
setToken(function () { return null; });
|
|
592
|
+
setSessionLastValidatedAt(null);
|
|
519
593
|
setMenus(function () { return []; });
|
|
520
594
|
setMenuData(function () { return []; });
|
|
521
595
|
setAuthorities(function () { return new Map(); });
|
|
@@ -526,27 +600,27 @@ var AuthProvider = function (_a) {
|
|
|
526
600
|
}, [authService, router]);
|
|
527
601
|
var checkToChangePassword = function (username, password, tokenFCM, branchCode) { return __awaiter(void 0, void 0, void 0, function () {
|
|
528
602
|
var checks, result, error_4;
|
|
529
|
-
var _a;
|
|
530
|
-
return __generator(this, function (
|
|
531
|
-
switch (
|
|
603
|
+
var _a, _b;
|
|
604
|
+
return __generator(this, function (_c) {
|
|
605
|
+
switch (_c.label) {
|
|
532
606
|
case 0:
|
|
533
607
|
setIsLoading(true);
|
|
534
|
-
|
|
608
|
+
_c.label = 1;
|
|
535
609
|
case 1:
|
|
536
|
-
|
|
610
|
+
_c.trys.push([1, 3, 4, 5]);
|
|
537
611
|
return [4 /*yield*/, authService.checkToChangePasswordLogin(username, password, branchCode)];
|
|
538
612
|
case 2:
|
|
539
|
-
checks =
|
|
613
|
+
checks = _c.sent();
|
|
540
614
|
result = checks === null || checks === void 0 ? void 0 : checks.data;
|
|
541
615
|
if ((_a = result === null || result === void 0 ? void 0 : result.data) === null || _a === void 0 ? void 0 : _a.IsRedirectToChangePassword) {
|
|
542
|
-
router.replace("/main-page/change-password?branch=".concat(branchCode));
|
|
616
|
+
(_b = router === null || router === void 0 ? void 0 : router.replace) === null || _b === void 0 ? void 0 : _b.call(router, "/main-page/change-password?branch=".concat(branchCode));
|
|
543
617
|
}
|
|
544
618
|
else {
|
|
545
619
|
passwordLogin(username, password, tokenFCM);
|
|
546
620
|
}
|
|
547
621
|
return [3 /*break*/, 5];
|
|
548
622
|
case 3:
|
|
549
|
-
error_4 =
|
|
623
|
+
error_4 = _c.sent();
|
|
550
624
|
return [3 /*break*/, 5];
|
|
551
625
|
case 4:
|
|
552
626
|
setTimeout(function () {
|
|
@@ -559,24 +633,25 @@ var AuthProvider = function (_a) {
|
|
|
559
633
|
}); };
|
|
560
634
|
var requestChangePassword = (0, react_1.useCallback)(function (_a) { return __awaiter(void 0, void 0, void 0, function () {
|
|
561
635
|
var response, error_5;
|
|
636
|
+
var _b;
|
|
562
637
|
var payload = __rest(_a, []);
|
|
563
|
-
return __generator(this, function (
|
|
564
|
-
switch (
|
|
638
|
+
return __generator(this, function (_c) {
|
|
639
|
+
switch (_c.label) {
|
|
565
640
|
case 0:
|
|
566
641
|
setIsLoading(true);
|
|
567
|
-
|
|
642
|
+
_c.label = 1;
|
|
568
643
|
case 1:
|
|
569
|
-
|
|
644
|
+
_c.trys.push([1, 3, 4, 5]);
|
|
570
645
|
return [4 /*yield*/, authService.requestChangePassword(payload)];
|
|
571
646
|
case 2:
|
|
572
|
-
response =
|
|
647
|
+
response = _c.sent();
|
|
573
648
|
if (payload.type !== "new-login") {
|
|
574
649
|
// message.success(response.data.message);
|
|
575
|
-
router.replace("/main-page");
|
|
650
|
+
(_b = router === null || router === void 0 ? void 0 : router.replace) === null || _b === void 0 ? void 0 : _b.call(router, "/main-page");
|
|
576
651
|
}
|
|
577
652
|
return [2 /*return*/, response];
|
|
578
653
|
case 3:
|
|
579
|
-
error_5 =
|
|
654
|
+
error_5 = _c.sent();
|
|
580
655
|
if (error_5 instanceof Error && payload.type !== "new-login")
|
|
581
656
|
// message.error(error.message);
|
|
582
657
|
return [2 /*return*/, Promise.reject(error_5)];
|
|
@@ -590,24 +665,25 @@ var AuthProvider = function (_a) {
|
|
|
590
665
|
}); }, [authService, router]);
|
|
591
666
|
var forgotPassword = function (_a) { return __awaiter(void 0, void 0, void 0, function () {
|
|
592
667
|
var response, error_6;
|
|
668
|
+
var _b;
|
|
593
669
|
var payload = __rest(_a, []);
|
|
594
|
-
return __generator(this, function (
|
|
595
|
-
switch (
|
|
670
|
+
return __generator(this, function (_c) {
|
|
671
|
+
switch (_c.label) {
|
|
596
672
|
case 0:
|
|
597
673
|
setIsLoading(true);
|
|
598
|
-
|
|
674
|
+
_c.label = 1;
|
|
599
675
|
case 1:
|
|
600
|
-
|
|
676
|
+
_c.trys.push([1, 3, 4, 5]);
|
|
601
677
|
return [4 /*yield*/, authService.forgotPassword(payload)];
|
|
602
678
|
case 2:
|
|
603
|
-
response =
|
|
679
|
+
response = _c.sent();
|
|
604
680
|
if (payload.type === "new-login") {
|
|
605
681
|
return [2 /*return*/, response];
|
|
606
682
|
}
|
|
607
683
|
// message.success(response.data.message);
|
|
608
|
-
return [2 /*return*/, router.replace("/main-page")];
|
|
684
|
+
return [2 /*return*/, (_b = router === null || router === void 0 ? void 0 : router.replace) === null || _b === void 0 ? void 0 : _b.call(router, "/main-page")];
|
|
609
685
|
case 3:
|
|
610
|
-
error_6 =
|
|
686
|
+
error_6 = _c.sent();
|
|
611
687
|
if (payload.type === "new-login") {
|
|
612
688
|
return [2 /*return*/, Promise.reject(error_6)];
|
|
613
689
|
}
|
|
@@ -616,7 +692,6 @@ var AuthProvider = function (_a) {
|
|
|
616
692
|
// "The information you have provided is incorrect, please try again."
|
|
617
693
|
// );
|
|
618
694
|
}
|
|
619
|
-
;
|
|
620
695
|
return [3 /*break*/, 5];
|
|
621
696
|
case 4:
|
|
622
697
|
setIsLoading(false);
|
|
@@ -670,14 +745,17 @@ var AuthProvider = function (_a) {
|
|
|
670
745
|
response = _a.sent();
|
|
671
746
|
isValid = response.data.isValid;
|
|
672
747
|
if (!isValid) {
|
|
673
|
-
router.push(
|
|
748
|
+
router.push(loginRoute);
|
|
674
749
|
return [2 /*return*/];
|
|
675
750
|
}
|
|
676
751
|
return [2 /*return*/, response];
|
|
677
752
|
case 3:
|
|
678
753
|
error_7 = _a.sent();
|
|
679
|
-
|
|
680
|
-
|
|
754
|
+
if (error_7 instanceof Error) {
|
|
755
|
+
console.error(error_7);
|
|
756
|
+
// message.error(error.response.data.message);
|
|
757
|
+
router.push(loginRoute);
|
|
758
|
+
}
|
|
681
759
|
return [3 /*break*/, 5];
|
|
682
760
|
case 4:
|
|
683
761
|
setIsLoading(false);
|
|
@@ -687,35 +765,35 @@ var AuthProvider = function (_a) {
|
|
|
687
765
|
});
|
|
688
766
|
}); }, [authService, router]);
|
|
689
767
|
var passwordLoginWithCheck = function (username, password, tokenFCM, branchCode) { return __awaiter(void 0, void 0, void 0, function () {
|
|
690
|
-
var
|
|
691
|
-
var _a;
|
|
692
|
-
return __generator(this, function (
|
|
693
|
-
switch (
|
|
768
|
+
var response_3, checksChangePassword, resultChangePassword, error_8;
|
|
769
|
+
var _a, _b;
|
|
770
|
+
return __generator(this, function (_c) {
|
|
771
|
+
switch (_c.label) {
|
|
694
772
|
case 0:
|
|
695
773
|
setIsLoading(true);
|
|
696
|
-
|
|
774
|
+
_c.label = 1;
|
|
697
775
|
case 1:
|
|
698
|
-
|
|
776
|
+
_c.trys.push([1, 4, 5, 6]);
|
|
699
777
|
return [4 /*yield*/, authService.passwordLogin(username, password, tokenFCM)];
|
|
700
778
|
case 2:
|
|
701
|
-
|
|
779
|
+
response_3 = _c.sent();
|
|
702
780
|
return [4 /*yield*/, authService.checkToChangePasswordLogin(username, password, branchCode)];
|
|
703
781
|
case 3:
|
|
704
|
-
checksChangePassword =
|
|
782
|
+
checksChangePassword = _c.sent();
|
|
705
783
|
resultChangePassword = checksChangePassword === null || checksChangePassword === void 0 ? void 0 : checksChangePassword.data;
|
|
706
784
|
if ((_a = resultChangePassword === null || resultChangePassword === void 0 ? void 0 : resultChangePassword.data) === null || _a === void 0 ? void 0 : _a.IsRedirectToChangePassword) {
|
|
707
|
-
router.replace("/main-page/change-password?branch=".concat(branchCode));
|
|
785
|
+
(_b = router === null || router === void 0 ? void 0 : router.replace) === null || _b === void 0 ? void 0 : _b.call(router, "/main-page/change-password?branch=".concat(branchCode));
|
|
708
786
|
}
|
|
709
787
|
else {
|
|
710
|
-
setToken(function () { return
|
|
711
|
-
localStorage.setItem("access-token",
|
|
712
|
-
localStorage.setItem("refresh-token",
|
|
788
|
+
setToken(function () { return response_3.data.data.accessToken; });
|
|
789
|
+
localStorage.setItem("access-token", response_3.data.data.accessToken);
|
|
790
|
+
localStorage.setItem("refresh-token", response_3.data.data.refreshToken);
|
|
713
791
|
localStorage.setItem("locale", "id");
|
|
714
|
-
router.push(
|
|
792
|
+
router.push(baseRoute);
|
|
715
793
|
}
|
|
716
794
|
return [3 /*break*/, 6];
|
|
717
795
|
case 4:
|
|
718
|
-
error_8 =
|
|
796
|
+
error_8 = _c.sent();
|
|
719
797
|
return [3 /*break*/, 6];
|
|
720
798
|
case 5:
|
|
721
799
|
setIsLoading(false);
|
|
@@ -725,19 +803,19 @@ var AuthProvider = function (_a) {
|
|
|
725
803
|
});
|
|
726
804
|
}); };
|
|
727
805
|
var ssoQlolaLogin = function (request) { return __awaiter(void 0, void 0, void 0, function () {
|
|
728
|
-
var
|
|
806
|
+
var response_4, err_2;
|
|
729
807
|
return __generator(this, function (_a) {
|
|
730
808
|
switch (_a.label) {
|
|
731
809
|
case 0:
|
|
732
810
|
_a.trys.push([0, 2, , 3]);
|
|
733
811
|
return [4 /*yield*/, authService.ssoLoginQlola(request)];
|
|
734
812
|
case 1:
|
|
735
|
-
|
|
736
|
-
setToken(function () { return
|
|
737
|
-
localStorage.setItem("access-token",
|
|
738
|
-
localStorage.setItem("refresh-token",
|
|
739
|
-
localStorage.setItem("agent",
|
|
740
|
-
router.push(
|
|
813
|
+
response_4 = _a.sent();
|
|
814
|
+
setToken(function () { return response_4.data.data.accessToken; });
|
|
815
|
+
localStorage.setItem("access-token", response_4.data.data.accessToken);
|
|
816
|
+
localStorage.setItem("refresh-token", response_4.data.data.refreshToken);
|
|
817
|
+
localStorage.setItem("agent", response_4.data.agent);
|
|
818
|
+
router.push(baseRoute);
|
|
741
819
|
return [2 /*return*/];
|
|
742
820
|
case 2:
|
|
743
821
|
err_2 = _a.sent();
|
|
@@ -747,7 +825,7 @@ var AuthProvider = function (_a) {
|
|
|
747
825
|
});
|
|
748
826
|
}); };
|
|
749
827
|
var login = function (username, password, branchCode, type) { return __awaiter(void 0, void 0, void 0, function () {
|
|
750
|
-
var
|
|
828
|
+
var response_5, data, token_1, error_9;
|
|
751
829
|
return __generator(this, function (_a) {
|
|
752
830
|
switch (_a.label) {
|
|
753
831
|
case 0:
|
|
@@ -757,23 +835,23 @@ var AuthProvider = function (_a) {
|
|
|
757
835
|
_a.trys.push([1, 3, 4, 5]);
|
|
758
836
|
return [4 /*yield*/, authService.login(username, password, branchCode)];
|
|
759
837
|
case 2:
|
|
760
|
-
|
|
761
|
-
setToken(function () { return
|
|
838
|
+
response_5 = _a.sent();
|
|
839
|
+
setToken(function () { return response_5.data.data.accessToken; });
|
|
762
840
|
// setCookie(null, "access-token", response.data.data.accessToken);
|
|
763
841
|
document.cookie = "loggedIn=true";
|
|
764
|
-
data =
|
|
842
|
+
data = response_5.data.data;
|
|
765
843
|
document.cookie = "accessToken=;";
|
|
766
|
-
localStorage.setItem("access-token",
|
|
767
|
-
localStorage.setItem("refresh-token",
|
|
844
|
+
localStorage.setItem("access-token", response_5.data.data.accessToken);
|
|
845
|
+
localStorage.setItem("refresh-token", response_5.data.data.refreshToken);
|
|
768
846
|
if (data.isRedirectToChangePassword) {
|
|
769
847
|
token_1 = data.changePasswordToken;
|
|
770
|
-
router.push("/
|
|
848
|
+
router.push("".concat(loginRoute, "/change-password?token=").concat(token_1));
|
|
771
849
|
return [2 /*return*/];
|
|
772
850
|
}
|
|
773
851
|
if (type === "new-login") {
|
|
774
|
-
return [2 /*return*/,
|
|
852
|
+
return [2 /*return*/, response_5];
|
|
775
853
|
}
|
|
776
|
-
router.push(
|
|
854
|
+
router.push(baseRoute);
|
|
777
855
|
return [2 /*return*/];
|
|
778
856
|
case 3:
|
|
779
857
|
error_9 = _a.sent();
|
|
@@ -788,7 +866,6 @@ var AuthProvider = function (_a) {
|
|
|
788
866
|
}
|
|
789
867
|
});
|
|
790
868
|
}); };
|
|
791
|
-
//@ts-ignore
|
|
792
869
|
var checkToken = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
793
870
|
var token_2, resp, error_10;
|
|
794
871
|
var _a, _b, _c, _d, _e, _f;
|
|
@@ -813,12 +890,11 @@ var AuthProvider = function (_a) {
|
|
|
813
890
|
if ([504].includes(((_e = (_d = error_10 === null || error_10 === void 0 ? void 0 : error_10.response) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e.code) || ((_f = error_10 === null || error_10 === void 0 ? void 0 : error_10.response) === null || _f === void 0 ? void 0 : _f.status) || error_10.status)) {
|
|
814
891
|
return [2 /*return*/, checkToken()];
|
|
815
892
|
}
|
|
816
|
-
return [2 /*return*/, router.push("
|
|
893
|
+
return [2 /*return*/, router.push("".concat(loginRoute, "?logout=true"))];
|
|
817
894
|
case 4: return [2 /*return*/];
|
|
818
895
|
}
|
|
819
896
|
});
|
|
820
897
|
}); };
|
|
821
|
-
//@ts-ignore
|
|
822
898
|
var refreshToken = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
823
899
|
var refreshToken_2, resp, error_11;
|
|
824
900
|
var _a, _b, _c;
|
|
@@ -841,77 +917,125 @@ var AuthProvider = function (_a) {
|
|
|
841
917
|
localStorage.removeItem("access-token");
|
|
842
918
|
localStorage.removeItem("refresh-token");
|
|
843
919
|
Promise.reject(error_11);
|
|
844
|
-
return [2 /*return*/, router.push("
|
|
845
|
-
case 3:
|
|
920
|
+
return [2 /*return*/, router.push("".concat(loginRoute, "?logout=true"))];
|
|
921
|
+
case 3:
|
|
922
|
+
setIsLoading(false);
|
|
923
|
+
return [7 /*endfinally*/];
|
|
846
924
|
case 4: return [2 /*return*/];
|
|
847
925
|
}
|
|
848
926
|
});
|
|
849
927
|
}); };
|
|
850
928
|
(0, react_1.useEffect)(function () {
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
}
|
|
854
|
-
else {
|
|
855
|
-
prevPathnameRef.current = router.asPath;
|
|
856
|
-
}
|
|
929
|
+
var _a, _b;
|
|
930
|
+
prevPathnameRef.current = router.asPath || "";
|
|
857
931
|
var handleRouteChangeStart = function (url) {
|
|
858
|
-
var newPath = url.split("?")[0];
|
|
932
|
+
var newPath = url.split("?")[0];
|
|
859
933
|
var currentPath = prevPathnameRef.current.split("?")[0];
|
|
860
934
|
if (newPath !== currentPath) {
|
|
861
|
-
setIsAuthoritiesReady(false);
|
|
862
935
|
prevPathnameRef.current = url;
|
|
863
936
|
}
|
|
864
937
|
};
|
|
865
|
-
router.events.on("routeChangeStart", handleRouteChangeStart);
|
|
938
|
+
(_b = (_a = router.events) === null || _a === void 0 ? void 0 : _a.on) === null || _b === void 0 ? void 0 : _b.call(_a, "routeChangeStart", handleRouteChangeStart);
|
|
866
939
|
return function () {
|
|
867
|
-
|
|
940
|
+
var _a, _b;
|
|
941
|
+
(_b = (_a = router.events) === null || _a === void 0 ? void 0 : _a.off) === null || _b === void 0 ? void 0 : _b.call(_a, "routeChangeStart", handleRouteChangeStart);
|
|
868
942
|
};
|
|
869
943
|
}, [router]);
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
944
|
+
var valueMemoized = (0, react_1.useMemo)(function () { return ({
|
|
945
|
+
token: token,
|
|
946
|
+
alertMenuError: alertMenuError,
|
|
947
|
+
authorities: authorities,
|
|
948
|
+
isAuthoritiesReady: isAuthoritiesReady,
|
|
949
|
+
productAuthorities: productAuthorities,
|
|
950
|
+
username: username,
|
|
951
|
+
userType: userType,
|
|
952
|
+
menus: menus,
|
|
953
|
+
loggedIn: loggedIn,
|
|
954
|
+
companyID: companyID,
|
|
955
|
+
companyName: companyName,
|
|
956
|
+
userMode: userMode,
|
|
957
|
+
companyLevel: companyLevel,
|
|
958
|
+
roleID: roleID,
|
|
959
|
+
holdingID: holdingID,
|
|
960
|
+
isLoading: isLoading,
|
|
961
|
+
isIntraday: isIntraday,
|
|
962
|
+
onboardingTourStatus: onboardingTourStatus,
|
|
963
|
+
userID: userID,
|
|
964
|
+
guard: guard,
|
|
965
|
+
passwordLogin: passwordLogin,
|
|
966
|
+
ssoLogin: ssoLogin,
|
|
967
|
+
logout: logout,
|
|
968
|
+
canIApprove: canIApprove,
|
|
969
|
+
roleIDs: roleIDs,
|
|
970
|
+
menuData: menuData,
|
|
971
|
+
ssoQlolaLogin: ssoQlolaLogin,
|
|
972
|
+
login: login,
|
|
973
|
+
forgotPassword: forgotPassword,
|
|
974
|
+
verifyUserQuestion: verifyUserQuestion,
|
|
975
|
+
verifyChangePasswordToken: verifyChangePasswordToken,
|
|
976
|
+
checkToChangePassword: checkToChangePassword,
|
|
977
|
+
passwordLoginWithCheck: passwordLoginWithCheck,
|
|
978
|
+
requestChangePassword: requestChangePassword,
|
|
979
|
+
canIDelete: canIDelete,
|
|
980
|
+
canIEdit: canIEdit,
|
|
981
|
+
action: action,
|
|
982
|
+
onLeaveAction: onLeaveAction,
|
|
983
|
+
setOnLeaveAction: setOnLeaveAction,
|
|
984
|
+
countryCode: countryCode,
|
|
985
|
+
setIsLoading: setIsLoading,
|
|
986
|
+
setUserType: setUserType,
|
|
987
|
+
setToken: setToken,
|
|
988
|
+
companyCode: companyCode,
|
|
989
|
+
region: region,
|
|
990
|
+
checkToken: checkToken,
|
|
991
|
+
}); }, [
|
|
992
|
+
token,
|
|
993
|
+
alertMenuError,
|
|
994
|
+
authorities,
|
|
995
|
+
isAuthoritiesReady,
|
|
996
|
+
productAuthorities,
|
|
997
|
+
username,
|
|
998
|
+
userType,
|
|
999
|
+
menus,
|
|
1000
|
+
loggedIn,
|
|
1001
|
+
companyID,
|
|
1002
|
+
companyName,
|
|
1003
|
+
userMode,
|
|
1004
|
+
companyLevel,
|
|
1005
|
+
roleID,
|
|
1006
|
+
holdingID,
|
|
1007
|
+
isLoading,
|
|
1008
|
+
userID,
|
|
1009
|
+
guard,
|
|
1010
|
+
passwordLogin,
|
|
1011
|
+
ssoLogin,
|
|
1012
|
+
logout,
|
|
1013
|
+
canIApprove,
|
|
1014
|
+
roleIDs,
|
|
1015
|
+
menuData,
|
|
1016
|
+
ssoQlolaLogin,
|
|
1017
|
+
login,
|
|
1018
|
+
forgotPassword,
|
|
1019
|
+
verifyUserQuestion,
|
|
1020
|
+
verifyChangePasswordToken,
|
|
1021
|
+
checkToChangePassword,
|
|
1022
|
+
passwordLoginWithCheck,
|
|
1023
|
+
requestChangePassword,
|
|
1024
|
+
canIDelete,
|
|
1025
|
+
canIEdit,
|
|
1026
|
+
action,
|
|
1027
|
+
onLeaveAction,
|
|
1028
|
+
setOnLeaveAction,
|
|
1029
|
+
countryCode,
|
|
1030
|
+
setIsLoading,
|
|
1031
|
+
setUserType,
|
|
1032
|
+
setToken,
|
|
1033
|
+
companyCode,
|
|
1034
|
+
region,
|
|
1035
|
+
checkToken,
|
|
1036
|
+
onboardingTourStatus,
|
|
1037
|
+
]);
|
|
1038
|
+
return ((0, jsx_runtime_1.jsx)(react_idle_timer_1.IdleTimerProvider, { onPrompt: onPrompt, onIdle: onIdle, onActive: onActive, onAction: onAction, timeout: isMinutes, children: (0, jsx_runtime_1.jsx)(AuthContext.Provider, { value: valueMemoized, children: children }) }));
|
|
915
1039
|
};
|
|
916
1040
|
exports.AuthProvider = AuthProvider;
|
|
917
1041
|
var useAuth = function () { return (0, react_1.useContext)(AuthContext); };
|