authscape 1.0.359 → 1.0.372

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/index.js CHANGED
@@ -6,17 +6,20 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.AuthScapeApp = AuthScapeApp;
8
8
  var _react = _interopRequireWildcard(require("react"));
9
- var _CircularProgress = _interopRequireDefault(require("@mui/material/CircularProgress"));
10
- var _Backdrop = _interopRequireDefault(require("@mui/material/Backdrop"));
11
9
  var _reactToastify = require("react-toastify");
12
- var _router = require("next/router");
13
10
  var _styles = require("@mui/material/styles");
14
- var _material = require("@mui/material");
15
11
  var _head = _interopRequireDefault(require("next/head"));
12
+ var _navigation = require("next/navigation");
13
+ var _axios = _interopRequireDefault(require("axios"));
14
+ var _queryString = _interopRequireDefault(require("query-string"));
15
+ var _nookies = require("nookies");
16
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
17
17
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
18
18
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
19
19
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
20
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
21
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
22
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
20
23
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
21
24
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
22
25
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
@@ -25,89 +28,169 @@ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefine
25
28
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
26
29
  function AuthScapeApp(_ref) {
27
30
  var Component = _ref.Component,
31
+ layout = _ref.layout,
28
32
  pageProps = _ref.pageProps,
29
33
  _ref$muiTheme = _ref.muiTheme,
30
34
  muiTheme = _ref$muiTheme === void 0 ? {} : _ref$muiTheme,
31
35
  _ref$enforceLoggedIn = _ref.enforceLoggedIn,
32
36
  enforceLoggedIn = _ref$enforceLoggedIn === void 0 ? false : _ref$enforceLoggedIn,
33
37
  _ref$enableAuth = _ref.enableAuth,
34
- enableAuth = _ref$enableAuth === void 0 ? true : _ref$enableAuth,
35
- _ref$onAuthentication = _ref.onAuthenticationLoaded,
36
- onAuthenticationLoaded = _ref$onAuthentication === void 0 ? null : _ref$onAuthentication,
37
- _ref$children = _ref.children,
38
- children = _ref$children === void 0 ? null : _ref$children;
38
+ enableAuth = _ref$enableAuth === void 0 ? true : _ref$enableAuth;
39
39
  var _useState = (0, _react.useState)(false),
40
40
  _useState2 = _slicedToArray(_useState, 2),
41
- isLoading = _useState2[0],
42
- setIsLoading = _useState2[1];
43
- var _useState3 = (0, _react.useState)(false),
44
- _useState4 = _slicedToArray(_useState3, 2),
45
- loadedUser = _useState4[0],
46
- setLoadedUser = _useState4[1];
47
- var _useState5 = (0, _react.useState)(null),
48
- _useState6 = _slicedToArray(_useState5, 2),
49
- currentUser = _useState6[0],
50
- setCurrentUser = _useState6[1];
51
- var _useState7 = (0, _react.useState)(false),
52
- _useState8 = _slicedToArray(_useState7, 2),
53
- loadingLogin = _useState8[0],
54
- setLoadingLogin = _useState8[1];
55
- var router = (0, _router.useRouter)();
56
- (0, _react.useEffect)(function () {}, [loadedUser]);
57
- (0, _react.useEffect)(function () {
58
- if (loadedUser && router.isReady) {
59
- if (process.env.googleAnalytics4 != null) {
60
- init(process.env.googleAnalytics4);
61
- }
62
- if (router.query.r != null) {
63
- localStorage.setItem("ref", router.query.r);
64
- }
65
-
66
- // sign in validation
67
- if (router.query.code != null) {
68
- setLoadingLogin(true);
69
- signInValidator(router.query.code);
70
- } else {
71
- if (enforceLoggedIn) {
72
- if (currentUser == null) {
73
- authService().login();
74
- }
41
+ frontEndLoadedState = _useState2[0],
42
+ setFrontEndLoadedState = _useState2[1];
43
+ var loadingAuth = (0, _react.useRef)(false);
44
+ var frontEndLoaded = (0, _react.useRef)(false);
45
+ var signedInUser = (0, _react.useRef)(null);
46
+ var queryCodeUsed = (0, _react.useRef)(null);
47
+ var searchParams = (0, _navigation.useSearchParams)();
48
+ var queryRef = searchParams.get('ref');
49
+ var queryCode = searchParams.get('code');
50
+ var pathname = (0, _navigation.usePathname)();
51
+ var signInValidator = /*#__PURE__*/function () {
52
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(queryCode) {
53
+ var codeVerifier, headers, queryString, response, domainHost, redirectUri;
54
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
55
+ while (1) switch (_context.prev = _context.next) {
56
+ case 0:
57
+ if (!(queryCodeUsed.current != queryCode)) {
58
+ _context.next = 4;
59
+ break;
60
+ }
61
+ queryCodeUsed.current = queryCode;
62
+ _context.next = 5;
63
+ break;
64
+ case 4:
65
+ return _context.abrupt("return");
66
+ case 5:
67
+ codeVerifier = window.localStorage.getItem("verifier");
68
+ if (!(queryCode != null && codeVerifier != null)) {
69
+ _context.next = 28;
70
+ break;
71
+ }
72
+ headers = {
73
+ 'Content-Type': 'application/x-www-form-urlencoded'
74
+ };
75
+ queryString = _queryString["default"].stringify({
76
+ code: queryCode,
77
+ grant_type: "authorization_code",
78
+ redirect_uri: window.location.origin + "/signin-oidc",
79
+ client_id: process.env.client_id,
80
+ client_secret: process.env.client_secret,
81
+ code_verifier: codeVerifier
82
+ });
83
+ _context.prev = 9;
84
+ _context.next = 12;
85
+ return _axios["default"].post(process.env.authorityUri + '/connect/token', queryString, {
86
+ headers: headers
87
+ });
88
+ case 12:
89
+ response = _context.sent;
90
+ domainHost = window.location.hostname.split('.').slice(-2).join('.');
91
+ window.localStorage.removeItem("verifier");
92
+ _context.next = 17;
93
+ return (0, _nookies.setCookie)(null, "access_token", response.data.access_token, {
94
+ maxAge: 2147483647,
95
+ path: '/',
96
+ domain: domainHost,
97
+ secure: true
98
+ });
99
+ case 17:
100
+ _context.next = 19;
101
+ return (0, _nookies.setCookie)(null, "expires_in", response.data.expires_in, {
102
+ maxAge: 2147483647,
103
+ path: '/',
104
+ domain: domainHost,
105
+ secure: true
106
+ });
107
+ case 19:
108
+ _context.next = 21;
109
+ return (0, _nookies.setCookie)(null, "refresh_token", response.data.refresh_token, {
110
+ maxAge: 2147483647,
111
+ path: '/',
112
+ domain: domainHost,
113
+ secure: true
114
+ });
115
+ case 21:
116
+ redirectUri = localStorage.getItem("redirectUri");
117
+ localStorage.clear();
118
+ if (redirectUri != null) {
119
+ window.location.href = redirectUri;
120
+ } else {
121
+ window.location.href = "/";
122
+ }
123
+ _context.next = 28;
124
+ break;
125
+ case 26:
126
+ _context.prev = 26;
127
+ _context.t0 = _context["catch"](9);
128
+ case 28:
129
+ case "end":
130
+ return _context.stop();
75
131
  }
76
- }
132
+ }, _callee, null, [[9, 26]]);
133
+ }));
134
+ return function signInValidator(_x2) {
135
+ return _ref2.apply(this, arguments);
136
+ };
137
+ }();
138
+ var validateUserSignedIn = /*#__PURE__*/function () {
139
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
140
+ var usr;
141
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
142
+ while (1) switch (_context2.prev = _context2.next) {
143
+ case 0:
144
+ loadingAuth.current = true;
145
+ if (!enableAuth) {
146
+ _context2.next = 6;
147
+ break;
148
+ }
149
+ _context2.next = 4;
150
+ return apiService().GetCurrentUser();
151
+ case 4:
152
+ usr = _context2.sent;
153
+ if (usr != null) {
154
+ signedInUser.current = usr;
155
+ }
156
+ case 6:
157
+ setFrontEndLoadedState(true);
158
+ frontEndLoaded.current = true;
159
+ case 8:
160
+ case "end":
161
+ return _context2.stop();
162
+ }
163
+ }, _callee2);
164
+ }));
165
+ return function validateUserSignedIn() {
166
+ return _ref3.apply(this, arguments);
167
+ };
168
+ }();
169
+ if (queryCode != null) {
170
+ signInValidator(queryCode);
171
+ } else {
172
+ if (!loadingAuth.current) {
173
+ validateUserSignedIn();
77
174
  }
78
- }, [loadedUser, router.isReady]);
175
+ }
79
176
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_head["default"], null, /*#__PURE__*/_react["default"].createElement("meta", {
80
177
  name: "viewport",
81
- content: "width=device-width, initial-scale=1"
178
+ content: "width=device-width, initial-scale=0.86, maximum-scale=5.0, minimum-scale=0.86"
82
179
  }), pageProps != null && pageProps.oemCompanyId != null && /*#__PURE__*/_react["default"].createElement("link", {
83
180
  href: process.env.apiUri + "/api/WhiteLabel/GetDataFromRecord?oemCompanyId=" + pageProps.oemCompanyId,
84
181
  rel: "stylesheet"
85
182
  })), /*#__PURE__*/_react["default"].createElement(_styles.ThemeProvider, {
86
183
  theme: muiTheme
87
- }, loadingLogin && /*#__PURE__*/_react["default"].createElement(_material.Box, null, "Please wait. Loading..."), !loadingLogin && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(AuthorizationComponent, {
88
- setCurrentUser: setCurrentUser,
89
- isEnabled: enableAuth,
90
- userLoaded: function userLoaded(signedInUser) {
91
- setLoadedUser(true);
92
- if (onAuthenticationLoaded != null) {
93
- onAuthenticationLoaded(signedInUser);
94
- }
95
- }
96
- }, children == null && /*#__PURE__*/_react["default"].createElement(Component, _extends({}, pageProps, {
97
- currentUser: currentUser,
98
- toast: _reactToastify.toast,
99
- setIsLoading: setIsLoading,
100
- loadedUser: loadedUser,
101
- logEvent: logEvent
102
- })), children != null && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, children)), /*#__PURE__*/_react["default"].createElement(_Backdrop["default"], {
103
- sx: {
104
- color: '#fff',
105
- zIndex: 99999
106
- },
107
- open: isLoading
108
- }, /*#__PURE__*/_react["default"].createElement(_CircularProgress["default"], {
109
- color: "inherit"
110
- })), /*#__PURE__*/_react["default"].createElement(_reactToastify.ToastContainer, null))), loadedUser && process.env.microsoftClarityTrackingCode != null && process.env.staging == "production" && /*#__PURE__*/_react["default"].createElement("script", {
184
+ }, frontEndLoadedState != null && frontEndLoadedState && pathname != "/signin-oidc" && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, layout != null && layout({
185
+ children: /*#__PURE__*/_react["default"].createElement(Component, _extends({}, pageProps, {
186
+ currentUser: signedInUser.current,
187
+ toast: _reactToastify.toast
188
+ })),
189
+ currentUser: signedInUser.current
190
+ }), layout == null && /*#__PURE__*/_react["default"].createElement(Component, _extends({}, pageProps, {
191
+ currentUser: signedInUser.current,
192
+ toast: _reactToastify.toast
193
+ }))), /*#__PURE__*/_react["default"].createElement(_reactToastify.ToastContainer, null)), frontEndLoaded.current && process.env.microsoftClarityTrackingCode != null && process.env.staging == "production" && /*#__PURE__*/_react["default"].createElement("script", {
111
194
  dangerouslySetInnerHTML: {
112
195
  __html: "\n (function(c,l,a,r,i,t,y){\n c[a] = c[a] || function () { (c[a].q = c[a].q || []).push(arguments) };\n t=l.createElement(r);\n t.async=1;\n t.src=\"https://www.clarity.ms/tag/\"+i;\n y=l.getElementsByTagName(r)[0];\n y.parentNode.insertBefore(t,y);\n })(window, document, \"clarity\", \"script\", \"" + process.env.microsoftClarityTrackingCode + "\");"
113
196
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "authscape",
3
- "version": "1.0.359",
3
+ "version": "1.0.372",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -14,7 +14,6 @@
14
14
  "@stripe/stripe-js": "^1.32.0",
15
15
  "js-file-download": "^0.4.12",
16
16
  "nookies": "^2.5.2",
17
- "react": "^18.2.0",
18
17
  "react-data-table-component": "^7.5.2",
19
18
  "react-dom": "^18.2.0"
20
19
  },
@@ -23,36 +22,40 @@
23
22
  "@babel/core": "^7.22.1",
24
23
  "@babel/preset-env": "^7.22.2",
25
24
  "@babel/preset-react": "^7.0.0",
26
- "react": "^18.2.0",
27
25
  "react-dom": "^18.2.0"
28
26
  },
29
27
  "dependencies": {
30
- "@dnd-kit/core": "^6.1.0",
31
- "@dnd-kit/sortable": "^8.0.0",
32
- "@dnd-kit/utilities": "^3.2.2",
28
+ "@emotion/react": "^11.11.3",
29
+ "@emotion/styled": "^11.11.0",
33
30
  "@microsoft/signalr": "^8.0.0",
34
31
  "@monaco-editor/react": "^4.5.1",
32
+ "@mui/icons-material": "^5.15.10",
33
+ "@mui/material": "^5.15.10",
34
+ "@mui/x-data-grid": "^6.19.4",
35
+ "@mui/x-date-pickers": "^6.19.4",
35
36
  "@silevis/reactgrid": "^4.1.3",
36
37
  "@stripe/react-stripe-js": "^1.9.0",
37
38
  "@stripe/stripe-js": "^1.32.0",
38
39
  "axios": "^1.6.1",
39
40
  "draft-js": "^0.11.7",
40
41
  "draftjs-to-html": "^0.9.1",
41
- "eslint-config-next": "^13.3.2",
42
+ "eslint-config-next": "^14.1.0",
42
43
  "ga-4-react": "^0.1.281",
43
44
  "html2canvas": "^1.4.1",
44
45
  "js-file-download": "^0.4.12",
45
46
  "jspdf": "^2.5.1",
46
- "next": "^13.3.2",
47
+ "next": "^14.1.0",
47
48
  "nookies": "^2.5.2",
48
49
  "query-string": "^7.1.1",
50
+ "react": "^18.2.0",
49
51
  "react-color": "^2.19.3",
50
52
  "react-cool-onclickoutside": "^1.7.0",
51
53
  "react-data-table-component": "^7.5.2",
52
54
  "react-device-detect": "^2.2.3",
53
55
  "react-draft-wysiwyg": "^1.15.0",
54
- "react-hook-form": "^7.44.2",
56
+ "react-hook-form": "^7.50.1",
55
57
  "react-toastify": "^9.1.3",
58
+ "styled-components": "^5.3.6",
56
59
  "use-places-autocomplete": "^4.0.0"
57
60
  }
58
61
  }
@@ -1,64 +1,142 @@
1
- import React, { useEffect, useState, useRef } from 'react';
2
- import CircularProgress from '@mui/material/CircularProgress';
3
- import Backdrop from '@mui/material/Backdrop';
1
+ import React, {useState, useRef} from 'react';
4
2
  import { ToastContainer, toast } from 'react-toastify';
5
- import { useRouter } from 'next/router';
6
3
  import { ThemeProvider } from '@mui/material/styles';
7
- import { Box } from '@mui/material';
8
4
  import Head from "next/head";
5
+ import { useSearchParams, usePathname } from 'next/navigation';
6
+ import axios from 'axios';
7
+ import querystring from "query-string";
8
+ import { setCookie } from 'nookies'
9
9
 
10
- export function AuthScapeApp({Component, pageProps, muiTheme = {}, enforceLoggedIn = false, enableAuth = true, onAuthenticationLoaded = null, children = null}) {
10
+ export function AuthScapeApp ({Component, layout, pageProps, muiTheme = {}, enforceLoggedIn = false, enableAuth = true}) {
11
11
 
12
- const [isLoading, setIsLoading] = useState(false);
13
- const [loadedUser, setLoadedUser] = useState(false);
14
- const [currentUser, setCurrentUser] = useState(null);
15
- const [loadingLogin, setLoadingLogin] = useState(false);
16
- const router = useRouter();
12
+ const [frontEndLoadedState, setFrontEndLoadedState] = useState(false);
17
13
 
18
- useEffect(() => {
19
-
20
- }, [loadedUser]);
14
+ const loadingAuth = useRef(false);
15
+ const frontEndLoaded = useRef(false);
16
+ const signedInUser = useRef(null);
17
+
18
+ const queryCodeUsed = useRef(null);
19
+
20
+ const searchParams = useSearchParams();
21
+ const queryRef = searchParams.get('ref');
22
+ const queryCode = searchParams.get('code');
21
23
 
24
+
25
+
26
+ const pathname = usePathname();
22
27
 
23
- useEffect(() => {
24
28
 
25
- if (loadedUser && router.isReady)
29
+ const signInValidator = async (queryCode) => {
30
+
31
+ if (queryCodeUsed.current != queryCode)
26
32
  {
27
- if (process.env.googleAnalytics4 != null)
28
- {
29
- init(process.env.googleAnalytics4);
30
- }
31
-
32
- if (router.query.r != null)
33
- {
34
- localStorage.setItem("ref", router.query.r);
35
- }
33
+ queryCodeUsed.current = queryCode;
34
+ }
35
+ else
36
+ {
37
+ return;
38
+ }
36
39
 
37
- // sign in validation
38
- if (router.query.code != null)
39
- {
40
- setLoadingLogin(true);
41
- signInValidator(router.query.code);
42
- }
43
- else
40
+ let codeVerifier = window.localStorage.getItem("verifier");
41
+ if (queryCode != null && codeVerifier != null)
44
42
  {
45
- if (enforceLoggedIn)
43
+ const headers = {'Content-Type': 'application/x-www-form-urlencoded'}
44
+
45
+ let queryString = querystring.stringify({
46
+ code: queryCode,
47
+ grant_type: "authorization_code",
48
+ redirect_uri: window.location.origin + "/signin-oidc",
49
+ client_id: process.env.client_id,
50
+ client_secret: process.env.client_secret,
51
+ code_verifier: codeVerifier
52
+ });
53
+
54
+ try
55
+ {
56
+ let response = await axios.post(process.env.authorityUri + '/connect/token', queryString, {
57
+ headers: headers
58
+ });
59
+
60
+ let domainHost = window.location.hostname.split('.').slice(-2).join('.');
61
+ window.localStorage.removeItem("verifier");
62
+
63
+ await setCookie(null, "access_token", response.data.access_token,
46
64
  {
47
- if (currentUser == null)
48
- {
49
- authService().login();
50
- }
65
+ maxAge: 2147483647,
66
+ path: '/',
67
+ domain: domainHost,
68
+ secure: true
69
+ });
70
+
71
+ await setCookie(null, "expires_in", response.data.expires_in,
72
+ {
73
+ maxAge: 2147483647,
74
+ path: '/',
75
+ domain: domainHost,
76
+ secure: true
77
+ });
78
+
79
+ await setCookie(null, "refresh_token", response.data.refresh_token,
80
+ {
81
+ maxAge: 2147483647,
82
+ path: '/',
83
+ domain: domainHost,
84
+ secure: true
85
+ });
86
+
87
+
88
+ let redirectUri = localStorage.getItem("redirectUri")
89
+ localStorage.clear();
90
+ if (redirectUri != null)
91
+ {
92
+ window.location.href = redirectUri;
93
+ }
94
+ else
95
+ {
96
+ window.location.href = "/";
51
97
  }
52
98
  }
99
+ catch(exp)
100
+ {
101
+ //alert(exp)
102
+ }
53
103
  }
54
-
55
- }, [loadedUser, router.isReady])
104
+ }
56
105
 
57
106
 
107
+ const validateUserSignedIn = async () => {
108
+
109
+ loadingAuth.current = true;
110
+
111
+ if (enableAuth)
112
+ {
113
+ let usr = await apiService().GetCurrentUser();
114
+ if (usr != null)
115
+ {
116
+ signedInUser.current = usr;
117
+ }
118
+ }
119
+
120
+ setFrontEndLoadedState(true);
121
+ frontEndLoaded.current = true;
122
+ }
123
+
124
+ if (queryCode != null)
125
+ {
126
+ signInValidator(queryCode);
127
+ }
128
+ else
129
+ {
130
+ if (!loadingAuth.current)
131
+ {
132
+ validateUserSignedIn();
133
+ }
134
+ }
135
+
58
136
  return (
59
137
  <>
60
138
  <Head>
61
- <meta name="viewport" content="width=device-width, initial-scale=1" />
139
+ <meta name="viewport" content="width=device-width, initial-scale=0.86, maximum-scale=5.0, minimum-scale=0.86"></meta>
62
140
  {(pageProps != null && pageProps.oemCompanyId != null) &&
63
141
  <link
64
142
  href={process.env.apiUri + "/api/WhiteLabel/GetDataFromRecord?oemCompanyId=" + pageProps.oemCompanyId}
@@ -68,43 +146,23 @@ export function AuthScapeApp({Component, pageProps, muiTheme = {}, enforceLogged
68
146
  </Head>
69
147
 
70
148
  <ThemeProvider theme={muiTheme}>
71
-
72
- {loadingLogin &&
73
- <Box>
74
- Please wait. Loading...
75
- </Box>
76
- }
77
-
78
- {!loadingLogin &&
149
+ {frontEndLoadedState != null && frontEndLoadedState && pathname != "/signin-oidc" &&
79
150
  <>
80
- <AuthorizationComponent setCurrentUser={setCurrentUser} isEnabled={enableAuth} userLoaded={(signedInUser) => {
81
- setLoadedUser(true);
82
-
83
- if (onAuthenticationLoaded != null)
84
- {
85
- onAuthenticationLoaded(signedInUser);
86
- }
87
- }}>
88
- {children == null &&
89
- <Component {...pageProps} currentUser={currentUser} toast={toast} setIsLoading={setIsLoading} loadedUser={loadedUser} logEvent={logEvent} />
90
- }
91
- {children != null &&
92
- <>
93
- {children}
94
- </>
95
- }
96
- </AuthorizationComponent>
97
-
98
- <Backdrop sx={{ color: '#fff', zIndex: 99999 }} open={isLoading}>
99
- <CircularProgress color="inherit" />
100
- </Backdrop>
101
-
102
- <ToastContainer />
151
+ {layout != null && layout({
152
+ children: <Component {...pageProps} currentUser={signedInUser.current} toast={toast} />,
153
+ currentUser: signedInUser.current
154
+ })}
155
+
156
+ {layout == null &&
157
+ <Component {...pageProps} currentUser={signedInUser.current} toast={toast} />
158
+ }
103
159
  </>
104
160
  }
161
+ <ToastContainer />
162
+
105
163
  </ThemeProvider>
106
164
 
107
- {(loadedUser && process.env.microsoftClarityTrackingCode != null && process.env.staging == "production") &&
165
+ {(frontEndLoaded.current && process.env.microsoftClarityTrackingCode != null && process.env.staging == "production") &&
108
166
  <script
109
167
  dangerouslySetInnerHTML={{
110
168
  __html: `