authscape 1.0.704 → 1.0.708

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
@@ -42,19 +42,25 @@ function AuthScapeApp(_ref) {
42
42
  _ref$enforceLoggedIn = _ref.enforceLoggedIn,
43
43
  enforceLoggedIn = _ref$enforceLoggedIn === void 0 ? false : _ref$enforceLoggedIn,
44
44
  _ref$enableAuth = _ref.enableAuth,
45
- enableAuth = _ref$enableAuth === void 0 ? true : _ref$enableAuth;
45
+ enableAuth = _ref$enableAuth === void 0 ? true : _ref$enableAuth,
46
+ _ref$enableConsentDia = _ref.enableConsentDialog,
47
+ enableConsentDialog = _ref$enableConsentDia === void 0 ? false : _ref$enableConsentDia;
46
48
  var _useState = (0, _react.useState)(false),
47
49
  _useState2 = _slicedToArray(_useState, 2),
48
50
  frontEndLoadedState = _useState2[0],
49
51
  setFrontEndLoadedState = _useState2[1];
50
52
  var _useState3 = (0, _react.useState)(false),
51
53
  _useState4 = _slicedToArray(_useState3, 2),
52
- isLoadingShow = _useState4[0],
53
- setIsLoadingShow = _useState4[1];
54
- var _useState5 = (0, _react.useState)(null),
54
+ concentState = _useState4[0],
55
+ setConcentState = _useState4[1];
56
+ var _useState5 = (0, _react.useState)(false),
55
57
  _useState6 = _slicedToArray(_useState5, 2),
56
- signedInUserState = _useState6[0],
57
- setSignedInUserState = _useState6[1];
58
+ isLoadingShow = _useState6[0],
59
+ setIsLoadingShow = _useState6[1];
60
+ var _useState7 = (0, _react.useState)(null),
61
+ _useState8 = _slicedToArray(_useState7, 2),
62
+ signedInUserState = _useState8[0],
63
+ setSignedInUserState = _useState8[1];
58
64
  var loadingAuth = (0, _react.useRef)(false);
59
65
  var frontEndLoaded = (0, _react.useRef)(false);
60
66
  var signedInUser = (0, _react.useRef)(null);
@@ -64,20 +70,13 @@ function AuthScapeApp(_ref) {
64
70
  var queryRef = searchParams.get('ref');
65
71
  var queryCode = searchParams.get('code');
66
72
  var pathname = (0, _navigation.usePathname)();
67
- (0, _react.useEffect)(function () {
68
- var stored = localStorage.getItem("gdpr-consent");
69
- if (stored) {
70
- var prefs = JSON.parse(stored);
71
- console.log("User previously consented:", prefs);
72
- // optional: send to your backend
73
- }
74
- }, []);
75
73
  var handleConsentAccepted = function handleConsentAccepted(prefs) {
76
74
  console.log("Consent accepted:", prefs);
77
- // optional: send to backend
75
+ setConcentState(prefs);
78
76
  };
79
77
  var handleConsentRejected = function handleConsentRejected() {
80
78
  console.log("Consent rejected");
79
+ setConcentState(null);
81
80
  // disable analytics scripts, etc.
82
81
  };
83
82
  var signInValidator = /*#__PURE__*/function () {
@@ -274,7 +273,16 @@ function AuthScapeApp(_ref) {
274
273
  }
275
274
  };
276
275
  (0, _react.useEffect)(function () {
277
- if (frontEndLoadedState) {
276
+ var enableAnalytics = false;
277
+ var stored = localStorage.getItem("gdpr-consent");
278
+ if (stored) {
279
+ var prefs = JSON.parse(stored);
280
+ if (prefs.analytics) {
281
+ enableAnalytics = true;
282
+ }
283
+ }
284
+ if (frontEndLoadedState && !enableConsentDialog || frontEndLoadedState && enableConsentDialog && enableAnalytics) {
285
+ console.log("Analytics are working now!");
278
286
  if (pageProps.googleAnalytics4Code != null) {
279
287
  initGA(pageProps.googleAnalytics4Code);
280
288
  } else if (process.env.googleAnalytics4 != "") {
@@ -314,8 +322,10 @@ function AuthScapeApp(_ref) {
314
322
  script.id = "hs-script-loader";
315
323
  document.body.appendChild(script);
316
324
  }
325
+ } else {
326
+ console.log("No Analytics for you!");
317
327
  }
318
- }, [frontEndLoadedState]);
328
+ }, [frontEndLoadedState, concentState]);
319
329
  var validateUserSignedIn = /*#__PURE__*/function () {
320
330
  var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
321
331
  var usr;
@@ -463,22 +473,15 @@ function AuthScapeApp(_ref) {
463
473
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_head["default"], null, /*#__PURE__*/_react["default"].createElement("meta", {
464
474
  name: "viewport",
465
475
  content: "width=device-width, initial-scale=0.86, maximum-scale=5.0, minimum-scale=0.86"
466
- })), /*#__PURE__*/_react["default"].createElement(GDPRConsentDialog, {
476
+ })), enableConsentDialog && /*#__PURE__*/_react["default"].createElement(GDPRConsentDialog, {
467
477
  onAccept: handleConsentAccepted,
468
478
  onReject: handleConsentRejected,
469
479
  enableAnalytics: true,
470
- enableMarketing: true,
471
- additionalPrivacyFeatures: [{
472
- id: "danceParty",
473
- title: "Dance Party",
474
- description: "Hello world this is about the feature",
475
- checked: true
476
- }, {
477
- id: "frog",
478
- title: "Able to see Frogs",
479
- description: "Frogs will appear on your screen",
480
- checked: true
481
- }]
480
+ enableMarketing: false
481
+ // additionalPrivacyFeatures={[
482
+ // {id: "danceParty", title: "Dance Party", description: "Hello world this is about the feature", checked: true },
483
+ // {id: "frog", title: "Able to see Frogs", description: "Frogs will appear on your screen", checked: true }
484
+ // ]}
482
485
  }), /*#__PURE__*/_react["default"].createElement(_styles.ThemeProvider, {
483
486
  theme: muiTheme
484
487
  }, frontEndLoadedState != null && frontEndLoadedState && pathname != "/signin-oidc" && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, layout != null && layout({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "authscape",
3
- "version": "1.0.704",
3
+ "version": "1.0.708",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -11,9 +11,10 @@ import { create } from 'zustand'
11
11
  import { clarity } from 'react-microsoft-clarity';
12
12
  import { authService } from 'authscape';
13
13
 
14
- export function AuthScapeApp ({Component, layout, loadingLayout, pageProps, muiTheme = {}, store={}, enforceLoggedIn = false, enableAuth = true}) {
14
+ export function AuthScapeApp ({Component, layout, loadingLayout, pageProps, muiTheme = {}, store={}, enforceLoggedIn = false, enableAuth = true, enableConsentDialog = false}) {
15
15
 
16
16
  const [frontEndLoadedState, setFrontEndLoadedState] = useState(false);
17
+ const [concentState, setConcentState] = useState(false);
17
18
 
18
19
  const [isLoadingShow, setIsLoadingShow] = useState(false);
19
20
 
@@ -32,23 +33,14 @@ export function AuthScapeApp ({Component, layout, loadingLayout, pageProps, muiT
32
33
 
33
34
  const pathname = usePathname();
34
35
 
35
-
36
- useEffect(() => {
37
- const stored = localStorage.getItem("gdpr-consent");
38
- if (stored) {
39
- const prefs = JSON.parse(stored);
40
- console.log("User previously consented:", prefs);
41
- // optional: send to your backend
42
- }
43
- }, []);
44
-
45
36
  const handleConsentAccepted = (prefs) => {
46
37
  console.log("Consent accepted:", prefs);
47
- // optional: send to backend
38
+ setConcentState(prefs);
48
39
  };
49
40
 
50
41
  const handleConsentRejected = () => {
51
42
  console.log("Consent rejected");
43
+ setConcentState(null);
52
44
  // disable analytics scripts, etc.
53
45
  };
54
46
 
@@ -234,8 +226,21 @@ export function AuthScapeApp ({Component, layout, loadingLayout, pageProps, muiT
234
226
 
235
227
  useEffect(() => {
236
228
 
237
- if (frontEndLoadedState)
229
+ let enableAnalytics = false;
230
+ const stored = localStorage.getItem("gdpr-consent");
231
+ if (stored) {
232
+ const prefs = JSON.parse(stored);
233
+ if (prefs.analytics)
234
+ {
235
+ enableAnalytics = true;
236
+ }
237
+ }
238
+
239
+ if ((frontEndLoadedState && !enableConsentDialog) || (frontEndLoadedState && enableConsentDialog && enableAnalytics))
238
240
  {
241
+
242
+ console.log("Analytics are working now!");
243
+
239
244
  if (pageProps.googleAnalytics4Code != null)
240
245
  {
241
246
  initGA(pageProps.googleAnalytics4Code);
@@ -289,8 +294,12 @@ export function AuthScapeApp ({Component, layout, loadingLayout, pageProps, muiT
289
294
  document.body.appendChild(script);
290
295
  }
291
296
  }
297
+ else
298
+ {
299
+ console.log("No Analytics for you!");
300
+ }
292
301
 
293
- }, [frontEndLoadedState]);
302
+ }, [frontEndLoadedState, concentState]);
294
303
 
295
304
  const validateUserSignedIn = async () => {
296
305
 
@@ -492,16 +501,18 @@ export function AuthScapeApp ({Component, layout, loadingLayout, pageProps, muiT
492
501
 
493
502
  </Head>
494
503
 
495
- <GDPRConsentDialog
496
- onAccept={handleConsentAccepted}
497
- onReject={handleConsentRejected}
498
- enableAnalytics={true}
499
- enableMarketing={true}
500
- additionalPrivacyFeatures={[
501
- {id: "danceParty", title: "Dance Party", description: "Hello world this is about the feature", checked: true },
502
- {id: "frog", title: "Able to see Frogs", description: "Frogs will appear on your screen", checked: true }
503
- ]}
504
- />
504
+ {enableConsentDialog &&
505
+ <GDPRConsentDialog
506
+ onAccept={handleConsentAccepted}
507
+ onReject={handleConsentRejected}
508
+ enableAnalytics={true}
509
+ enableMarketing={false}
510
+ // additionalPrivacyFeatures={[
511
+ // {id: "danceParty", title: "Dance Party", description: "Hello world this is about the feature", checked: true },
512
+ // {id: "frog", title: "Able to see Frogs", description: "Frogs will appear on your screen", checked: true }
513
+ // ]}
514
+ />
515
+ }
505
516
 
506
517
  <ThemeProvider theme={muiTheme}>
507
518
  {frontEndLoadedState != null && frontEndLoadedState && pathname != "/signin-oidc" &&