authscape 1.0.275 → 1.0.277

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
@@ -52,7 +52,11 @@ function AuthScapeApp(_ref) {
52
52
  loadingLogin = _useState8[0],
53
53
  setLoadingLogin = _useState8[1];
54
54
  var router = (0, _router.useRouter)();
55
+ (0, _react.useEffect)(function () {}, [loadedUser]);
55
56
  (0, _react.useEffect)(function () {
57
+ if (!router.isReady) return;
58
+
59
+ // analytics
56
60
  if (loadedUser) {
57
61
  if (process.env.googleAnalytics4 != null) {
58
62
  init(process.env.googleAnalytics4);
@@ -60,17 +64,16 @@ function AuthScapeApp(_ref) {
60
64
  if (router.query.r != null) {
61
65
  localStorage.setItem("ref", router.query.r);
62
66
  }
67
+ }
63
68
 
64
- // if (enforceLoggedIn)
65
- // {
66
- // if (currentUser == null ) {
67
- // window.location.href = "/login";
68
- // }
69
- // }
69
+ // ensure login is hit
70
+ if (loadedUser && router.isReady && enforceLoggedIn) {
71
+ if (currentUser == null && router.pathname.indexOf("/login") == -1 && router.pathname.indexOf("404") == -1 && router.pathname.indexOf("/logout") == -1 && router.pathname.indexOf("/signin-oidc") == -1 && router.pathname.indexOf("/signout-oidc") == -1) {
72
+ window.location.href = "/login";
73
+ }
70
74
  }
71
- }, [loadedUser]);
72
- (0, _react.useEffect)(function () {
73
- if (!router.isReady) return;
75
+
76
+ // sign in validation
74
77
  if (router.query.code != null) {
75
78
  setLoadingLogin(true);
76
79
  signInValidator(router.query.code);
@@ -78,7 +81,7 @@ function AuthScapeApp(_ref) {
78
81
  setLoadingLogin(true);
79
82
  authService().login();
80
83
  }
81
- }, [router.isReady]);
84
+ }, [loadedUser, router.isReady]);
82
85
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_styles.ThemeProvider, {
83
86
  theme: muiTheme
84
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, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "authscape",
3
- "version": "1.0.275",
3
+ "version": "1.0.277",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -15,6 +15,15 @@ export function AuthScapeApp({Component, pageProps, muiTheme = {}, enforceLogged
15
15
  const router = useRouter();
16
16
 
17
17
  useEffect(() => {
18
+
19
+ }, [loadedUser]);
20
+
21
+
22
+ useEffect(() => {
23
+
24
+ if(!router.isReady) return;
25
+
26
+ // analytics
18
27
  if (loadedUser)
19
28
  {
20
29
  if (process.env.googleAnalytics4 != null)
@@ -26,20 +35,19 @@ export function AuthScapeApp({Component, pageProps, muiTheme = {}, enforceLogged
26
35
  {
27
36
  localStorage.setItem("ref", router.query.r);
28
37
  }
38
+ }
29
39
 
30
- // if (enforceLoggedIn)
31
- // {
32
- // if (currentUser == null ) {
33
- // window.location.href = "/login";
34
- // }
35
- // }
36
40
 
41
+ // ensure login is hit
42
+ if (loadedUser && router.isReady && enforceLoggedIn)
43
+ {
44
+ if (currentUser == null && router.pathname.indexOf("/login") == -1 && router.pathname.indexOf("404") == -1 && router.pathname.indexOf("/logout") == -1 && router.pathname.indexOf("/signin-oidc") == -1 && router.pathname.indexOf("/signout-oidc") == -1)
45
+ {
46
+ window.location.href = "/login";
47
+ }
37
48
  }
38
- }, [loadedUser]);
39
-
40
- useEffect(() => {
41
- if(!router.isReady) return;
42
49
 
50
+ // sign in validation
43
51
  if (router.query.code != null)
44
52
  {
45
53
  setLoadingLogin(true);
@@ -51,7 +59,9 @@ export function AuthScapeApp({Component, pageProps, muiTheme = {}, enforceLogged
51
59
  authService().login();
52
60
  }
53
61
 
54
- }, [router.isReady]);
62
+
63
+ }, [loadedUser, router.isReady])
64
+
55
65
 
56
66
  return (
57
67
  <>