@ordentco/addons-auth-provider 0.9.133 → 0.9.134-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 -4
- package/dist/src/auth.js +393 -273
- 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 +9 -0
- package/dist/src/types/onboarding.js +12 -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 -260
- package/src/index.ts +2 -2
- package/src/types/onboarding.ts +12 -0
- package/src/types/router.ts +10 -0
- package/types/product.ts +5 -0
- 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,155 +104,210 @@ var AUTH_INITIAL_VALUES = {
|
|
|
107
104
|
companyName: "",
|
|
108
105
|
userMode: "",
|
|
109
106
|
companyLevel: "",
|
|
110
|
-
|
|
107
|
+
onboardingTourStatus: onboarding_1.OnboardingTourStatus.Done,
|
|
111
108
|
userID: null,
|
|
112
109
|
roleID: null,
|
|
113
110
|
roleIDs: null,
|
|
114
111
|
holdingID: null,
|
|
115
112
|
isLoading: false,
|
|
113
|
+
isIntraday: false,
|
|
116
114
|
menus: [],
|
|
117
115
|
loggedIn: false,
|
|
118
116
|
guard: function () {
|
|
119
117
|
throw new Error("Function not implemented.");
|
|
120
118
|
},
|
|
121
|
-
passwordLogin: function (
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
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 () {
|
|
125
135
|
throw new Error("Function not implemented.");
|
|
126
136
|
},
|
|
127
|
-
|
|
137
|
+
canIDelete: function () {
|
|
128
138
|
throw new Error("Function not implemented.");
|
|
129
139
|
},
|
|
130
|
-
|
|
140
|
+
canIEdit: function () {
|
|
131
141
|
throw new Error("Function not implemented.");
|
|
132
142
|
},
|
|
133
143
|
menuData: [],
|
|
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
|
-
|
|
161
|
-
|
|
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 () {
|
|
162
189
|
throw new Error("Function not implemented.");
|
|
163
190
|
},
|
|
164
|
-
setIsLoading: function (
|
|
191
|
+
setIsLoading: function () {
|
|
165
192
|
throw new Error("Function not implemented.");
|
|
166
193
|
},
|
|
167
|
-
|
|
194
|
+
setUserType: function () {
|
|
168
195
|
throw new Error("Function not implemented.");
|
|
169
196
|
},
|
|
170
|
-
action: null,
|
|
171
|
-
onLeaveAction: null,
|
|
172
|
-
setOnLeaveAction: null,
|
|
173
|
-
countryCode: "",
|
|
174
197
|
companyCode: "",
|
|
175
198
|
region: "",
|
|
176
|
-
checkToken: function () {
|
|
177
|
-
|
|
178
|
-
|
|
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
|
+
}); },
|
|
179
204
|
};
|
|
180
205
|
// export const getStaticProps:GetStaticProps<{}> = async () => {
|
|
181
206
|
//
|
|
182
207
|
// }
|
|
183
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
|
+
};
|
|
184
219
|
var AuthProvider = function (_a) {
|
|
185
|
-
var children = _a.children, apiUrl = _a.apiUrl;
|
|
186
|
-
var
|
|
187
|
-
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 () {
|
|
188
222
|
if (typeof window !== "undefined") {
|
|
189
|
-
|
|
190
|
-
return t;
|
|
223
|
+
return localStorage.getItem("access-token");
|
|
191
224
|
}
|
|
192
225
|
return null;
|
|
193
|
-
}), token =
|
|
226
|
+
}), token = _e[0], setToken = _e[1];
|
|
194
227
|
var authService = (0, react_1.useMemo)(function () { return (0, services_1.AuthService)(); }, [apiUrl, token]);
|
|
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
|
|
218
|
-
var
|
|
219
|
-
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];
|
|
220
255
|
var prevPathnameRef = (0, react_1.useRef)("");
|
|
221
256
|
var loggedIn = (0, react_1.useMemo)(function () { return !!token; }, [token]);
|
|
222
257
|
var guard = (0, react_1.useCallback)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
223
|
-
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;
|
|
224
259
|
var _b, _c, _d, _e, _f, _g, _h, _j;
|
|
225
260
|
return __generator(this, function (_k) {
|
|
226
261
|
switch (_k.label) {
|
|
227
262
|
case 0:
|
|
228
|
-
|
|
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 ---
|
|
229
277
|
setIsAuthoritiesReady(false);
|
|
230
278
|
_k.label = 1;
|
|
231
279
|
case 1:
|
|
232
280
|
_k.trys.push([1, 3, , 4]);
|
|
233
281
|
return [4 /*yield*/, authService.validateToken()];
|
|
234
282
|
case 2:
|
|
235
|
-
|
|
283
|
+
response = _k.sent();
|
|
236
284
|
return [3 /*break*/, 4];
|
|
237
285
|
case 3:
|
|
238
286
|
error_1 = _k.sent();
|
|
239
287
|
agent = typeof window !== "undefined" && localStorage.getItem("agent");
|
|
240
|
-
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))) {
|
|
241
290
|
localStorage.removeItem("access-token");
|
|
242
291
|
localStorage.removeItem("refresh-token");
|
|
243
292
|
setToken(function () { return null; });
|
|
293
|
+
setSessionLastValidatedAt(null);
|
|
244
294
|
return [2 /*return*/, window.close()];
|
|
245
295
|
}
|
|
246
296
|
console.log({ error: error_1 });
|
|
247
|
-
|
|
297
|
+
response = error_1;
|
|
248
298
|
return [3 /*break*/, 4];
|
|
249
299
|
case 4: return [4 /*yield*/, authService.validateMenu(token)];
|
|
250
300
|
case 5:
|
|
251
301
|
menu = _k.sent();
|
|
252
302
|
if (menu.data.code !== 200 || !menu)
|
|
253
303
|
setAlertMenuError(true);
|
|
254
|
-
newMenuData = (0, get_1.default)(menu,
|
|
255
|
-
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; });
|
|
256
308
|
setMenus(newMenus);
|
|
257
309
|
setMenuData(newMenuData);
|
|
258
|
-
if (!(
|
|
310
|
+
if (!(response.status === 401)) return [3 /*break*/, 8];
|
|
259
311
|
if (!(typeof window !== "undefined")) return [3 /*break*/, 7];
|
|
260
312
|
refreshToken_1 = localStorage.getItem("refresh-token");
|
|
261
313
|
if (!refreshToken_1) return [3 /*break*/, 7];
|
|
@@ -270,41 +322,43 @@ var AuthProvider = function (_a) {
|
|
|
270
322
|
_k.label = 7;
|
|
271
323
|
case 7: return [3 /*break*/, 9];
|
|
272
324
|
case 8:
|
|
273
|
-
if (
|
|
325
|
+
if (response.status !== 200) {
|
|
274
326
|
localStorage.removeItem("access-token");
|
|
275
327
|
localStorage.removeItem("refresh-token");
|
|
276
328
|
setToken(function () { return null; });
|
|
277
|
-
|
|
329
|
+
setSessionLastValidatedAt(null);
|
|
330
|
+
router === null || router === void 0 ? void 0 : router.push("".concat(loginRoute, "?logout=true"));
|
|
278
331
|
return [2 /*return*/];
|
|
279
332
|
}
|
|
280
333
|
_k.label = 9;
|
|
281
334
|
case 9:
|
|
282
|
-
if (
|
|
283
|
-
_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;
|
|
284
337
|
localStorage.setItem("login", "".concat(username_1, "-").concat(companyCode_1, "-").concat(userID_1, "-").concat(companyID_1));
|
|
285
338
|
}
|
|
286
|
-
setRoleID(function () { return
|
|
287
|
-
setRoleIDs(function () { return
|
|
288
|
-
setCompanyID(function () { var _a; return (_a =
|
|
289
|
-
setCompanyName(function () { var _a; return (_a =
|
|
290
|
-
setUserID(function () { var _a; return (_a =
|
|
291
|
-
setHoldingID(function () { var _a; return (_a =
|
|
292
|
-
setUsername(function () { var _a; return ((_a =
|
|
293
|
-
setUserType(function () { var _a; return ((_a =
|
|
294
|
-
setCountryCode(function () { return
|
|
295
|
-
setCompanyCode(function () { var _a; return ((_a =
|
|
296
|
-
setRegion(function () { return
|
|
297
|
-
setUserMode(function () { var _a; return ((_a =
|
|
298
|
-
setCompanyLevel(function () { var _a; return ((_a =
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
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) || [];
|
|
302
356
|
productRoles.forEach(function (r) {
|
|
303
|
-
|
|
357
|
+
a.set(r.productName, r.authorities);
|
|
304
358
|
});
|
|
305
|
-
setAuthorities(function () { return
|
|
306
|
-
|
|
307
|
-
productTypeEnumValuesFromProductRoles = Array.from(
|
|
359
|
+
setAuthorities(function () { return a; });
|
|
360
|
+
privilegesRecords = __assign({}, productAuthorities);
|
|
361
|
+
productTypeEnumValuesFromProductRoles = Array.from(a.keys());
|
|
308
362
|
productTypeEnumValuesFromHardcode = Array.from(Object.values(types_1.ProductTypeEnum));
|
|
309
363
|
remainingProductTypeEnum = [
|
|
310
364
|
productTypeEnumValuesFromProductRoles,
|
|
@@ -316,7 +370,7 @@ var AuthProvider = function (_a) {
|
|
|
316
370
|
// FIXME: delete this logic beacuse expose all product, need to get from variable productRoles / a!
|
|
317
371
|
allProductTypeEnum.forEach(function (_a) {
|
|
318
372
|
var productKey = _a[0], productValue = _a[1];
|
|
319
|
-
var productRole =
|
|
373
|
+
var productRole = a.get(productValue) || [];
|
|
320
374
|
productRole = productRole.map(function (e) { return e.split(":")[0]; });
|
|
321
375
|
var productAuthority = {};
|
|
322
376
|
Object.entries(types_1.AuthorityLevelEnum).forEach(function (_a) {
|
|
@@ -324,23 +378,24 @@ var AuthProvider = function (_a) {
|
|
|
324
378
|
productAuthority[key] = productRole.includes(value);
|
|
325
379
|
});
|
|
326
380
|
productAuthority["anyAuthority"] = productRole.length > 0;
|
|
327
|
-
productAuthority["allAuthority"] =
|
|
328
|
-
|
|
381
|
+
productAuthority["allAuthority"] =
|
|
382
|
+
productRole.length >= Object.entries(types_1.AuthorityLevelEnum).length;
|
|
383
|
+
privilegesRecords[productKey] = productAuthority;
|
|
329
384
|
});
|
|
330
385
|
// Combine Authority All Product Multipayment
|
|
331
|
-
if (!(0, is_empty_1.isEmpty)(newMenuData.find(function (item) {
|
|
332
|
-
|
|
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"]; });
|
|
333
390
|
menuDataMultipayment = newMenuData.filter(function (item) { return item.parentID === menuDataMultipaymentCreate_1.menuID; });
|
|
334
391
|
multipaymentProducts = menuDataMultipayment.map(function (item) { return item["name"]; });
|
|
335
392
|
multipaymentProducts.map(function (item) {
|
|
336
|
-
|
|
393
|
+
privilegesRecords["MULTIPAYMENT"] = (0, mergeWith_1.default)(privilegesRecords["MULTIPAYMENT"], privilegesRecords[(0, snakeCase_1.default)(item).toUpperCase()], function (objValue, srcValue) { return objValue || srcValue; });
|
|
337
394
|
});
|
|
338
395
|
}
|
|
339
|
-
setProductAuthorities(
|
|
396
|
+
setProductAuthorities(privilegesRecords);
|
|
340
397
|
setIsAuthoritiesReady(true);
|
|
341
|
-
|
|
342
|
-
case 10:
|
|
343
|
-
router.push("/main-page");
|
|
398
|
+
setSessionLastValidatedAt(Date.now());
|
|
344
399
|
return [2 /*return*/];
|
|
345
400
|
}
|
|
346
401
|
});
|
|
@@ -357,7 +412,7 @@ var AuthProvider = function (_a) {
|
|
|
357
412
|
var productKey = (0, snakeCase_1.default)(product).toUpperCase();
|
|
358
413
|
if (!productKey)
|
|
359
414
|
return false;
|
|
360
|
-
// @ts-
|
|
415
|
+
// @ts-expect-error product authorities key is a enum keyof
|
|
361
416
|
var authority = productAuthorities[productKey];
|
|
362
417
|
if (!authority)
|
|
363
418
|
return false;
|
|
@@ -373,19 +428,33 @@ var AuthProvider = function (_a) {
|
|
|
373
428
|
});
|
|
374
429
|
if (roleIDs.length > 0) {
|
|
375
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);
|
|
376
|
-
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
|
+
});
|
|
377
436
|
alreadyApprove = !!(participant === null || participant === void 0 ? void 0 : participant.approvedAt);
|
|
378
437
|
}
|
|
379
|
-
if (participantUserIDs
|
|
438
|
+
if (participantUserIDs === null || participantUserIDs === void 0 ? void 0 : participantUserIDs.includes(userID))
|
|
380
439
|
return false;
|
|
381
|
-
if (Number(userID) === Number(createdBy.userID) &&
|
|
440
|
+
if (Number(userID) === Number(createdBy.userID) &&
|
|
441
|
+
currentStep !== "releaser")
|
|
382
442
|
return false;
|
|
383
|
-
var isCanIApprove = (approve &&
|
|
443
|
+
var isCanIApprove = (approve &&
|
|
444
|
+
currentStep === types_1.StepType.Signer &&
|
|
445
|
+
roleAllowed &&
|
|
446
|
+
!alreadyApprove &&
|
|
447
|
+
!isMaker) ||
|
|
384
448
|
(verify &&
|
|
385
|
-
(currentStep === types_1.StepType.Verifier ||
|
|
449
|
+
(currentStep === types_1.StepType.Verifier ||
|
|
450
|
+
currentStep === types_1.StepType.Checker) &&
|
|
386
451
|
roleAllowed &&
|
|
387
|
-
!alreadyApprove &&
|
|
388
|
-
|
|
452
|
+
!alreadyApprove &&
|
|
453
|
+
!isMaker) ||
|
|
454
|
+
(release &&
|
|
455
|
+
currentStep === types_1.StepType.Releaser &&
|
|
456
|
+
roleAllowed &&
|
|
457
|
+
!alreadyApprove);
|
|
389
458
|
if (status) {
|
|
390
459
|
return isCanIApprove && status === types_1.TaskStatus.Pending;
|
|
391
460
|
}
|
|
@@ -395,7 +464,7 @@ var AuthProvider = function (_a) {
|
|
|
395
464
|
var productKey = (0, snakeCase_1.default)(product).toUpperCase();
|
|
396
465
|
if (!productKey)
|
|
397
466
|
return false;
|
|
398
|
-
// @ts-
|
|
467
|
+
// @ts-expect-error product authorities key is a enum keyof
|
|
399
468
|
var authority = productAuthorities[productKey];
|
|
400
469
|
if (!authority)
|
|
401
470
|
return false;
|
|
@@ -414,15 +483,15 @@ var AuthProvider = function (_a) {
|
|
|
414
483
|
var productKey = (0, snakeCase_1.default)(product).toUpperCase();
|
|
415
484
|
if (!productKey)
|
|
416
485
|
return false;
|
|
417
|
-
// @ts-
|
|
486
|
+
// @ts-expect-error product authorities key is a enum keyof
|
|
418
487
|
var authority = productAuthorities[productKey];
|
|
419
488
|
if (!authority)
|
|
420
489
|
return false;
|
|
421
490
|
var modify = (0, get_1.default)(authority, "modify");
|
|
422
|
-
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);
|
|
423
492
|
};
|
|
424
493
|
var passwordLogin = (0, react_1.useCallback)(function (username, password, tokenFCM) { return __awaiter(void 0, void 0, void 0, function () {
|
|
425
|
-
var
|
|
494
|
+
var response_1, error_2;
|
|
426
495
|
return __generator(this, function (_a) {
|
|
427
496
|
switch (_a.label) {
|
|
428
497
|
case 0:
|
|
@@ -432,11 +501,11 @@ var AuthProvider = function (_a) {
|
|
|
432
501
|
_a.trys.push([1, 3, 4, 5]);
|
|
433
502
|
return [4 /*yield*/, authService.passwordLogin(username, password, tokenFCM)];
|
|
434
503
|
case 2:
|
|
435
|
-
|
|
436
|
-
setToken(function () { return
|
|
437
|
-
localStorage.setItem("access-token",
|
|
438
|
-
localStorage.setItem("refresh-token",
|
|
439
|
-
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);
|
|
440
509
|
return [3 /*break*/, 5];
|
|
441
510
|
case 3:
|
|
442
511
|
error_2 = _a.sent();
|
|
@@ -465,23 +534,24 @@ var AuthProvider = function (_a) {
|
|
|
465
534
|
return setIsMinutes(FIFTEEN_MINUTES);
|
|
466
535
|
};
|
|
467
536
|
var ssoLogin = (0, react_1.useCallback)(function (userId, sessionId, dtTime, onError) { return __awaiter(void 0, void 0, void 0, function () {
|
|
468
|
-
var
|
|
537
|
+
var response_2, error_3;
|
|
469
538
|
return __generator(this, function (_a) {
|
|
470
539
|
switch (_a.label) {
|
|
471
540
|
case 0:
|
|
472
541
|
_a.trys.push([0, 2, , 3]);
|
|
473
542
|
return [4 /*yield*/, authService.ssoLogin(userId, sessionId, dtTime)];
|
|
474
543
|
case 1:
|
|
475
|
-
|
|
476
|
-
if (
|
|
477
|
-
if (
|
|
544
|
+
response_2 = _a.sent();
|
|
545
|
+
if (response_2.status !== 200) {
|
|
546
|
+
if (response_2.status === 409) {
|
|
478
547
|
setOpenModal(true);
|
|
548
|
+
}
|
|
479
549
|
return [2 /*return*/];
|
|
480
550
|
}
|
|
481
|
-
setToken(function () { return
|
|
482
|
-
localStorage.setItem("access-token",
|
|
483
|
-
localStorage.setItem("refresh-token",
|
|
484
|
-
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);
|
|
485
555
|
return [3 /*break*/, 3];
|
|
486
556
|
case 2:
|
|
487
557
|
error_3 = _a.sent();
|
|
@@ -499,7 +569,7 @@ var AuthProvider = function (_a) {
|
|
|
499
569
|
args_1[_i] = arguments[_i];
|
|
500
570
|
}
|
|
501
571
|
return __awaiter(void 0, __spreadArray([], args_1, true), void 0, function (path) {
|
|
502
|
-
if (path === void 0) { path = "
|
|
572
|
+
if (path === void 0) { path = "".concat(loginRoute, "?logout=true"); }
|
|
503
573
|
return __generator(this, function (_a) {
|
|
504
574
|
try {
|
|
505
575
|
// await authService.logout();
|
|
@@ -519,6 +589,7 @@ var AuthProvider = function (_a) {
|
|
|
519
589
|
sessionStorage.clear();
|
|
520
590
|
router.push(path);
|
|
521
591
|
setToken(function () { return null; });
|
|
592
|
+
setSessionLastValidatedAt(null);
|
|
522
593
|
setMenus(function () { return []; });
|
|
523
594
|
setMenuData(function () { return []; });
|
|
524
595
|
setAuthorities(function () { return new Map(); });
|
|
@@ -529,27 +600,27 @@ var AuthProvider = function (_a) {
|
|
|
529
600
|
}, [authService, router]);
|
|
530
601
|
var checkToChangePassword = function (username, password, tokenFCM, branchCode) { return __awaiter(void 0, void 0, void 0, function () {
|
|
531
602
|
var checks, result, error_4;
|
|
532
|
-
var _a;
|
|
533
|
-
return __generator(this, function (
|
|
534
|
-
switch (
|
|
603
|
+
var _a, _b;
|
|
604
|
+
return __generator(this, function (_c) {
|
|
605
|
+
switch (_c.label) {
|
|
535
606
|
case 0:
|
|
536
607
|
setIsLoading(true);
|
|
537
|
-
|
|
608
|
+
_c.label = 1;
|
|
538
609
|
case 1:
|
|
539
|
-
|
|
610
|
+
_c.trys.push([1, 3, 4, 5]);
|
|
540
611
|
return [4 /*yield*/, authService.checkToChangePasswordLogin(username, password, branchCode)];
|
|
541
612
|
case 2:
|
|
542
|
-
checks =
|
|
613
|
+
checks = _c.sent();
|
|
543
614
|
result = checks === null || checks === void 0 ? void 0 : checks.data;
|
|
544
615
|
if ((_a = result === null || result === void 0 ? void 0 : result.data) === null || _a === void 0 ? void 0 : _a.IsRedirectToChangePassword) {
|
|
545
|
-
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));
|
|
546
617
|
}
|
|
547
618
|
else {
|
|
548
619
|
passwordLogin(username, password, tokenFCM);
|
|
549
620
|
}
|
|
550
621
|
return [3 /*break*/, 5];
|
|
551
622
|
case 3:
|
|
552
|
-
error_4 =
|
|
623
|
+
error_4 = _c.sent();
|
|
553
624
|
return [3 /*break*/, 5];
|
|
554
625
|
case 4:
|
|
555
626
|
setTimeout(function () {
|
|
@@ -562,24 +633,25 @@ var AuthProvider = function (_a) {
|
|
|
562
633
|
}); };
|
|
563
634
|
var requestChangePassword = (0, react_1.useCallback)(function (_a) { return __awaiter(void 0, void 0, void 0, function () {
|
|
564
635
|
var response, error_5;
|
|
636
|
+
var _b;
|
|
565
637
|
var payload = __rest(_a, []);
|
|
566
|
-
return __generator(this, function (
|
|
567
|
-
switch (
|
|
638
|
+
return __generator(this, function (_c) {
|
|
639
|
+
switch (_c.label) {
|
|
568
640
|
case 0:
|
|
569
641
|
setIsLoading(true);
|
|
570
|
-
|
|
642
|
+
_c.label = 1;
|
|
571
643
|
case 1:
|
|
572
|
-
|
|
644
|
+
_c.trys.push([1, 3, 4, 5]);
|
|
573
645
|
return [4 /*yield*/, authService.requestChangePassword(payload)];
|
|
574
646
|
case 2:
|
|
575
|
-
response =
|
|
647
|
+
response = _c.sent();
|
|
576
648
|
if (payload.type !== "new-login") {
|
|
577
649
|
// message.success(response.data.message);
|
|
578
|
-
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");
|
|
579
651
|
}
|
|
580
652
|
return [2 /*return*/, response];
|
|
581
653
|
case 3:
|
|
582
|
-
error_5 =
|
|
654
|
+
error_5 = _c.sent();
|
|
583
655
|
if (error_5 instanceof Error && payload.type !== "new-login")
|
|
584
656
|
// message.error(error.message);
|
|
585
657
|
return [2 /*return*/, Promise.reject(error_5)];
|
|
@@ -593,24 +665,25 @@ var AuthProvider = function (_a) {
|
|
|
593
665
|
}); }, [authService, router]);
|
|
594
666
|
var forgotPassword = function (_a) { return __awaiter(void 0, void 0, void 0, function () {
|
|
595
667
|
var response, error_6;
|
|
668
|
+
var _b;
|
|
596
669
|
var payload = __rest(_a, []);
|
|
597
|
-
return __generator(this, function (
|
|
598
|
-
switch (
|
|
670
|
+
return __generator(this, function (_c) {
|
|
671
|
+
switch (_c.label) {
|
|
599
672
|
case 0:
|
|
600
673
|
setIsLoading(true);
|
|
601
|
-
|
|
674
|
+
_c.label = 1;
|
|
602
675
|
case 1:
|
|
603
|
-
|
|
676
|
+
_c.trys.push([1, 3, 4, 5]);
|
|
604
677
|
return [4 /*yield*/, authService.forgotPassword(payload)];
|
|
605
678
|
case 2:
|
|
606
|
-
response =
|
|
679
|
+
response = _c.sent();
|
|
607
680
|
if (payload.type === "new-login") {
|
|
608
681
|
return [2 /*return*/, response];
|
|
609
682
|
}
|
|
610
683
|
// message.success(response.data.message);
|
|
611
|
-
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")];
|
|
612
685
|
case 3:
|
|
613
|
-
error_6 =
|
|
686
|
+
error_6 = _c.sent();
|
|
614
687
|
if (payload.type === "new-login") {
|
|
615
688
|
return [2 /*return*/, Promise.reject(error_6)];
|
|
616
689
|
}
|
|
@@ -619,7 +692,6 @@ var AuthProvider = function (_a) {
|
|
|
619
692
|
// "The information you have provided is incorrect, please try again."
|
|
620
693
|
// );
|
|
621
694
|
}
|
|
622
|
-
;
|
|
623
695
|
return [3 /*break*/, 5];
|
|
624
696
|
case 4:
|
|
625
697
|
setIsLoading(false);
|
|
@@ -673,14 +745,17 @@ var AuthProvider = function (_a) {
|
|
|
673
745
|
response = _a.sent();
|
|
674
746
|
isValid = response.data.isValid;
|
|
675
747
|
if (!isValid) {
|
|
676
|
-
router.push(
|
|
748
|
+
router.push(loginRoute);
|
|
677
749
|
return [2 /*return*/];
|
|
678
750
|
}
|
|
679
751
|
return [2 /*return*/, response];
|
|
680
752
|
case 3:
|
|
681
753
|
error_7 = _a.sent();
|
|
682
|
-
|
|
683
|
-
|
|
754
|
+
if (error_7 instanceof Error) {
|
|
755
|
+
console.error(error_7);
|
|
756
|
+
// message.error(error.response.data.message);
|
|
757
|
+
router.push(loginRoute);
|
|
758
|
+
}
|
|
684
759
|
return [3 /*break*/, 5];
|
|
685
760
|
case 4:
|
|
686
761
|
setIsLoading(false);
|
|
@@ -690,35 +765,35 @@ var AuthProvider = function (_a) {
|
|
|
690
765
|
});
|
|
691
766
|
}); }, [authService, router]);
|
|
692
767
|
var passwordLoginWithCheck = function (username, password, tokenFCM, branchCode) { return __awaiter(void 0, void 0, void 0, function () {
|
|
693
|
-
var
|
|
694
|
-
var _a;
|
|
695
|
-
return __generator(this, function (
|
|
696
|
-
switch (
|
|
768
|
+
var response_3, checksChangePassword, resultChangePassword, error_8;
|
|
769
|
+
var _a, _b;
|
|
770
|
+
return __generator(this, function (_c) {
|
|
771
|
+
switch (_c.label) {
|
|
697
772
|
case 0:
|
|
698
773
|
setIsLoading(true);
|
|
699
|
-
|
|
774
|
+
_c.label = 1;
|
|
700
775
|
case 1:
|
|
701
|
-
|
|
776
|
+
_c.trys.push([1, 4, 5, 6]);
|
|
702
777
|
return [4 /*yield*/, authService.passwordLogin(username, password, tokenFCM)];
|
|
703
778
|
case 2:
|
|
704
|
-
|
|
779
|
+
response_3 = _c.sent();
|
|
705
780
|
return [4 /*yield*/, authService.checkToChangePasswordLogin(username, password, branchCode)];
|
|
706
781
|
case 3:
|
|
707
|
-
checksChangePassword =
|
|
782
|
+
checksChangePassword = _c.sent();
|
|
708
783
|
resultChangePassword = checksChangePassword === null || checksChangePassword === void 0 ? void 0 : checksChangePassword.data;
|
|
709
784
|
if ((_a = resultChangePassword === null || resultChangePassword === void 0 ? void 0 : resultChangePassword.data) === null || _a === void 0 ? void 0 : _a.IsRedirectToChangePassword) {
|
|
710
|
-
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));
|
|
711
786
|
}
|
|
712
787
|
else {
|
|
713
|
-
setToken(function () { return
|
|
714
|
-
localStorage.setItem("access-token",
|
|
715
|
-
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);
|
|
716
791
|
localStorage.setItem("locale", "id");
|
|
717
|
-
router.push(
|
|
792
|
+
router.push(baseRoute);
|
|
718
793
|
}
|
|
719
794
|
return [3 /*break*/, 6];
|
|
720
795
|
case 4:
|
|
721
|
-
error_8 =
|
|
796
|
+
error_8 = _c.sent();
|
|
722
797
|
return [3 /*break*/, 6];
|
|
723
798
|
case 5:
|
|
724
799
|
setIsLoading(false);
|
|
@@ -728,19 +803,19 @@ var AuthProvider = function (_a) {
|
|
|
728
803
|
});
|
|
729
804
|
}); };
|
|
730
805
|
var ssoQlolaLogin = function (request) { return __awaiter(void 0, void 0, void 0, function () {
|
|
731
|
-
var
|
|
806
|
+
var response_4, err_2;
|
|
732
807
|
return __generator(this, function (_a) {
|
|
733
808
|
switch (_a.label) {
|
|
734
809
|
case 0:
|
|
735
810
|
_a.trys.push([0, 2, , 3]);
|
|
736
811
|
return [4 /*yield*/, authService.ssoLoginQlola(request)];
|
|
737
812
|
case 1:
|
|
738
|
-
|
|
739
|
-
setToken(function () { return
|
|
740
|
-
localStorage.setItem("access-token",
|
|
741
|
-
localStorage.setItem("refresh-token",
|
|
742
|
-
localStorage.setItem("agent",
|
|
743
|
-
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);
|
|
744
819
|
return [2 /*return*/];
|
|
745
820
|
case 2:
|
|
746
821
|
err_2 = _a.sent();
|
|
@@ -750,7 +825,7 @@ var AuthProvider = function (_a) {
|
|
|
750
825
|
});
|
|
751
826
|
}); };
|
|
752
827
|
var login = function (username, password, branchCode, type) { return __awaiter(void 0, void 0, void 0, function () {
|
|
753
|
-
var
|
|
828
|
+
var response_5, data, token_1, error_9;
|
|
754
829
|
return __generator(this, function (_a) {
|
|
755
830
|
switch (_a.label) {
|
|
756
831
|
case 0:
|
|
@@ -760,23 +835,23 @@ var AuthProvider = function (_a) {
|
|
|
760
835
|
_a.trys.push([1, 3, 4, 5]);
|
|
761
836
|
return [4 /*yield*/, authService.login(username, password, branchCode)];
|
|
762
837
|
case 2:
|
|
763
|
-
|
|
764
|
-
setToken(function () { return
|
|
838
|
+
response_5 = _a.sent();
|
|
839
|
+
setToken(function () { return response_5.data.data.accessToken; });
|
|
765
840
|
// setCookie(null, "access-token", response.data.data.accessToken);
|
|
766
841
|
document.cookie = "loggedIn=true";
|
|
767
|
-
data =
|
|
842
|
+
data = response_5.data.data;
|
|
768
843
|
document.cookie = "accessToken=;";
|
|
769
|
-
localStorage.setItem("access-token",
|
|
770
|
-
localStorage.setItem("refresh-token",
|
|
844
|
+
localStorage.setItem("access-token", response_5.data.data.accessToken);
|
|
845
|
+
localStorage.setItem("refresh-token", response_5.data.data.refreshToken);
|
|
771
846
|
if (data.isRedirectToChangePassword) {
|
|
772
847
|
token_1 = data.changePasswordToken;
|
|
773
|
-
router.push("/
|
|
848
|
+
router.push("".concat(loginRoute, "/change-password?token=").concat(token_1));
|
|
774
849
|
return [2 /*return*/];
|
|
775
850
|
}
|
|
776
851
|
if (type === "new-login") {
|
|
777
|
-
return [2 /*return*/,
|
|
852
|
+
return [2 /*return*/, response_5];
|
|
778
853
|
}
|
|
779
|
-
router.push(
|
|
854
|
+
router.push(baseRoute);
|
|
780
855
|
return [2 /*return*/];
|
|
781
856
|
case 3:
|
|
782
857
|
error_9 = _a.sent();
|
|
@@ -791,7 +866,6 @@ var AuthProvider = function (_a) {
|
|
|
791
866
|
}
|
|
792
867
|
});
|
|
793
868
|
}); };
|
|
794
|
-
//@ts-ignore
|
|
795
869
|
var checkToken = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
796
870
|
var token_2, resp, error_10;
|
|
797
871
|
var _a, _b, _c, _d, _e, _f;
|
|
@@ -816,12 +890,11 @@ var AuthProvider = function (_a) {
|
|
|
816
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)) {
|
|
817
891
|
return [2 /*return*/, checkToken()];
|
|
818
892
|
}
|
|
819
|
-
return [2 /*return*/, router.push("
|
|
893
|
+
return [2 /*return*/, router.push("".concat(loginRoute, "?logout=true"))];
|
|
820
894
|
case 4: return [2 /*return*/];
|
|
821
895
|
}
|
|
822
896
|
});
|
|
823
897
|
}); };
|
|
824
|
-
//@ts-ignore
|
|
825
898
|
var refreshToken = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
826
899
|
var refreshToken_2, resp, error_11;
|
|
827
900
|
var _a, _b, _c;
|
|
@@ -844,78 +917,125 @@ var AuthProvider = function (_a) {
|
|
|
844
917
|
localStorage.removeItem("access-token");
|
|
845
918
|
localStorage.removeItem("refresh-token");
|
|
846
919
|
Promise.reject(error_11);
|
|
847
|
-
return [2 /*return*/, router.push("
|
|
848
|
-
case 3:
|
|
920
|
+
return [2 /*return*/, router.push("".concat(loginRoute, "?logout=true"))];
|
|
921
|
+
case 3:
|
|
922
|
+
setIsLoading(false);
|
|
923
|
+
return [7 /*endfinally*/];
|
|
849
924
|
case 4: return [2 /*return*/];
|
|
850
925
|
}
|
|
851
926
|
});
|
|
852
927
|
}); };
|
|
853
928
|
(0, react_1.useEffect)(function () {
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
}
|
|
857
|
-
else {
|
|
858
|
-
prevPathnameRef.current = router.asPath;
|
|
859
|
-
}
|
|
929
|
+
var _a, _b;
|
|
930
|
+
prevPathnameRef.current = router.asPath || "";
|
|
860
931
|
var handleRouteChangeStart = function (url) {
|
|
861
|
-
var newPath = url.split("?")[0];
|
|
932
|
+
var newPath = url.split("?")[0];
|
|
862
933
|
var currentPath = prevPathnameRef.current.split("?")[0];
|
|
863
934
|
if (newPath !== currentPath) {
|
|
864
|
-
setIsAuthoritiesReady(false);
|
|
865
935
|
prevPathnameRef.current = url;
|
|
866
936
|
}
|
|
867
937
|
};
|
|
868
|
-
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);
|
|
869
939
|
return function () {
|
|
870
|
-
|
|
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);
|
|
871
942
|
};
|
|
872
943
|
}, [router]);
|
|
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
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
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 }) }));
|
|
919
1039
|
};
|
|
920
1040
|
exports.AuthProvider = AuthProvider;
|
|
921
1041
|
var useAuth = function () { return (0, react_1.useContext)(AuthContext); };
|