authscape 1.0.710 → 1.0.712

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
@@ -60,7 +60,7 @@ function AuthScapeApp(_ref) {
60
60
  var queryCodeUsed = (0, _react.useRef)(null);
61
61
  var ga4React = (0, _react.useRef)(null);
62
62
  var searchParams = (0, _navigation.useSearchParams)();
63
- var queryCode = searchParams.get('code');
63
+ var queryCode = searchParams.get("code");
64
64
  var pathname = (0, _navigation.usePathname)();
65
65
 
66
66
  // ---------- PKCE Sign-in ----------
@@ -77,15 +77,21 @@ function AuthScapeApp(_ref) {
77
77
  return _context.abrupt("return");
78
78
  case 2:
79
79
  queryCodeUsed.current = queryCode;
80
+ if (!(typeof window === "undefined")) {
81
+ _context.next = 5;
82
+ break;
83
+ }
84
+ return _context.abrupt("return");
85
+ case 5:
80
86
  codeVerifier = window.localStorage.getItem("verifier");
81
87
  if (!(!queryCode || !codeVerifier)) {
82
- _context.next = 6;
88
+ _context.next = 8;
83
89
  break;
84
90
  }
85
91
  return _context.abrupt("return");
86
- case 6:
92
+ case 8:
87
93
  headers = {
88
- 'Content-Type': 'application/x-www-form-urlencoded'
94
+ "Content-Type": "application/x-www-form-urlencoded"
89
95
  };
90
96
  queryString = _queryString["default"].stringify({
91
97
  code: queryCode,
@@ -95,53 +101,53 @@ function AuthScapeApp(_ref) {
95
101
  client_secret: process.env.client_secret,
96
102
  code_verifier: codeVerifier
97
103
  });
98
- _context.prev = 8;
99
- _context.next = 11;
100
- return _axios["default"].post(process.env.authorityUri + '/connect/token', queryString, {
104
+ _context.prev = 10;
105
+ _context.next = 13;
106
+ return _axios["default"].post(process.env.authorityUri + "/connect/token", queryString, {
101
107
  headers: headers
102
108
  });
103
- case 11:
109
+ case 13:
104
110
  response = _context.sent;
105
- domainHost = window.location.hostname.split('.').slice(-2).join('.');
111
+ domainHost = window.location.hostname.split(".").slice(-2).join(".");
106
112
  window.localStorage.removeItem("verifier");
107
- _context.next = 16;
108
- return setCookie('access_token', response.data.access_token, {
109
- maxAge: 60 * 60 * 24 * 365,
110
- path: '/',
111
- domain: domainHost,
112
- secure: true
113
- });
114
- case 16:
115
113
  _context.next = 18;
116
- return setCookie('expires_in', response.data.expires_in, {
114
+ return setCookie("access_token", response.data.access_token, {
117
115
  maxAge: 60 * 60 * 24 * 365,
118
- path: '/',
116
+ path: "/",
119
117
  domain: domainHost,
120
118
  secure: true
121
119
  });
122
120
  case 18:
123
121
  _context.next = 20;
124
- return setCookie('refresh_token', response.data.refresh_token, {
122
+ return setCookie("expires_in", response.data.expires_in, {
125
123
  maxAge: 60 * 60 * 24 * 365,
126
- path: '/',
124
+ path: "/",
127
125
  domain: domainHost,
128
126
  secure: true
129
127
  });
130
128
  case 20:
129
+ _context.next = 22;
130
+ return setCookie("refresh_token", response.data.refresh_token, {
131
+ maxAge: 60 * 60 * 24 * 365,
132
+ path: "/",
133
+ domain: domainHost,
134
+ secure: true
135
+ });
136
+ case 22:
131
137
  redirectUri = localStorage.getItem("redirectUri");
132
138
  localStorage.clear();
133
139
  window.location.href = redirectUri || "/";
134
- _context.next = 28;
140
+ _context.next = 30;
135
141
  break;
136
- case 25:
137
- _context.prev = 25;
138
- _context.t0 = _context["catch"](8);
142
+ case 27:
143
+ _context.prev = 27;
144
+ _context.t0 = _context["catch"](10);
139
145
  console.error("PKCE sign-in failed", _context.t0);
140
- case 28:
146
+ case 30:
141
147
  case "end":
142
148
  return _context.stop();
143
149
  }
144
- }, _callee, null, [[8, 25]]);
150
+ }, _callee, null, [[10, 27]]);
145
151
  }));
146
152
  return function signInValidator(_x) {
147
153
  return _ref2.apply(this, arguments);
@@ -157,7 +163,7 @@ function AuthScapeApp(_ref) {
157
163
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
158
164
  while (1) switch (_context2.prev = _context2.next) {
159
165
  case 0:
160
- if (!(!_ga4React["default"].isInitialized() && G && typeof window !== "undefined")) {
166
+ if (!(typeof window !== "undefined" && !_ga4React["default"].isInitialized() && G)) {
161
167
  _context2.next = 10;
162
168
  break;
163
169
  }
@@ -190,6 +196,7 @@ function AuthScapeApp(_ref) {
190
196
  var databaseDrivenPageView = function databaseDrivenPageView(pathName) {
191
197
  var _signedInUser$current, _signedInUser$current2, _signedInUser$current3;
192
198
  if (process.env.enableDatabaseAnalytics !== "true") return;
199
+ if (typeof window === "undefined") return;
193
200
  if (pathName === "/signin-oidc") return;
194
201
  var host = window.location.protocol + "//" + window.location.host;
195
202
  apiService().post("/Analytics/PageView", {
@@ -201,7 +208,7 @@ function AuthScapeApp(_ref) {
201
208
  });
202
209
  };
203
210
 
204
- // ---------- Auth + Tracking Init ----------
211
+ // ---------- Auth Init ----------
205
212
  (0, _react.useEffect)(function () {
206
213
  if (queryCode) {
207
214
  signInValidator(queryCode);
@@ -221,7 +228,7 @@ function AuthScapeApp(_ref) {
221
228
 
222
229
  // ---------- Analytics Init ----------
223
230
  (0, _react.useEffect)(function () {
224
- if (!frontEndLoadedState) return;
231
+ if (!frontEndLoadedState || typeof window === "undefined") return;
225
232
  if (pageProps.googleAnalytics4Code) {
226
233
  initGA(pageProps.googleAnalytics4Code);
227
234
  } else if (process.env.googleAnalytics4) {
@@ -233,7 +240,7 @@ function AuthScapeApp(_ref) {
233
240
  _reactMicrosoftClarity.clarity.init(process.env.microsoftClarityTrackingCode);
234
241
  }
235
242
  databaseDrivenPageView(window.location.pathname);
236
- _router["default"].events.on('routeChangeComplete', function (url) {
243
+ _router["default"].events.on("routeChangeComplete", function (url) {
237
244
  var _ga4React$current;
238
245
  (_ga4React$current = ga4React.current) === null || _ga4React$current === void 0 || _ga4React$current.pageview(url);
239
246
  databaseDrivenPageView(url);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "authscape",
3
- "version": "1.0.710",
3
+ "version": "1.0.712",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,15 +1,15 @@
1
- import React, { useState, useRef, useEffect } from 'react';
2
- import { ToastContainer, toast } from 'react-toastify';
3
- import { ThemeProvider } from '@mui/material/styles';
1
+ import React, { useState, useRef, useEffect } from "react";
2
+ import { ToastContainer, toast } from "react-toastify";
3
+ import { ThemeProvider } from "@mui/material/styles";
4
4
  import Head from "next/head";
5
- import { useSearchParams, usePathname } from 'next/navigation';
6
- import axios from 'axios';
5
+ import { useSearchParams, usePathname } from "next/navigation";
6
+ import axios from "axios";
7
7
  import querystring from "query-string";
8
- import Router from 'next/router';
9
- import GA4React from 'ga-4-react';
10
- import { create } from 'zustand';
11
- import { clarity } from 'react-microsoft-clarity';
12
- import { authService } from 'authscape';
8
+ import Router from "next/router";
9
+ import GA4React from "ga-4-react";
10
+ import { create } from "zustand";
11
+ import { clarity } from "react-microsoft-clarity";
12
+ import { authService } from "authscape";
13
13
 
14
14
  export function AuthScapeApp({
15
15
  Component,
@@ -19,7 +19,7 @@ export function AuthScapeApp({
19
19
  muiTheme = {},
20
20
  store = {},
21
21
  enforceLoggedIn = false,
22
- enableAuth = true
22
+ enableAuth = true,
23
23
  }) {
24
24
  const [frontEndLoadedState, setFrontEndLoadedState] = useState(false);
25
25
  const [isLoadingShow, setIsLoadingShow] = useState(false);
@@ -31,7 +31,7 @@ export function AuthScapeApp({
31
31
  const ga4React = useRef(null);
32
32
 
33
33
  const searchParams = useSearchParams();
34
- const queryCode = searchParams.get('code');
34
+ const queryCode = searchParams.get("code");
35
35
  const pathname = usePathname();
36
36
 
37
37
  // ---------- PKCE Sign-in ----------
@@ -39,10 +39,12 @@ export function AuthScapeApp({
39
39
  if (queryCodeUsed.current === queryCode) return;
40
40
  queryCodeUsed.current = queryCode;
41
41
 
42
+ if (typeof window === "undefined") return;
43
+
42
44
  const codeVerifier = window.localStorage.getItem("verifier");
43
45
  if (!queryCode || !codeVerifier) return;
44
46
 
45
- const headers = { 'Content-Type': 'application/x-www-form-urlencoded' };
47
+ const headers = { "Content-Type": "application/x-www-form-urlencoded" };
46
48
 
47
49
  const queryString = querystring.stringify({
48
50
  code: queryCode,
@@ -50,32 +52,40 @@ export function AuthScapeApp({
50
52
  redirect_uri: window.location.origin + "/signin-oidc",
51
53
  client_id: process.env.client_id,
52
54
  client_secret: process.env.client_secret,
53
- code_verifier: codeVerifier
55
+ code_verifier: codeVerifier,
54
56
  });
55
57
 
56
58
  try {
57
- const response = await axios.post(process.env.authorityUri + '/connect/token', queryString, { headers });
58
- const domainHost = window.location.hostname.split('.').slice(-2).join('.');
59
+ const response = await axios.post(
60
+ process.env.authorityUri + "/connect/token",
61
+ queryString,
62
+ { headers }
63
+ );
64
+
65
+ const domainHost = window.location.hostname
66
+ .split(".")
67
+ .slice(-2)
68
+ .join(".");
59
69
 
60
70
  window.localStorage.removeItem("verifier");
61
71
 
62
- await setCookie('access_token', response.data.access_token, {
72
+ await setCookie("access_token", response.data.access_token, {
63
73
  maxAge: 60 * 60 * 24 * 365,
64
- path: '/',
74
+ path: "/",
65
75
  domain: domainHost,
66
- secure: true
76
+ secure: true,
67
77
  });
68
- await setCookie('expires_in', response.data.expires_in, {
78
+ await setCookie("expires_in", response.data.expires_in, {
69
79
  maxAge: 60 * 60 * 24 * 365,
70
- path: '/',
80
+ path: "/",
71
81
  domain: domainHost,
72
- secure: true
82
+ secure: true,
73
83
  });
74
- await setCookie('refresh_token', response.data.refresh_token, {
84
+ await setCookie("refresh_token", response.data.refresh_token, {
75
85
  maxAge: 60 * 60 * 24 * 365,
76
- path: '/',
86
+ path: "/",
77
87
  domain: domainHost,
78
- secure: true
88
+ secure: true,
79
89
  });
80
90
 
81
91
  const redirectUri = localStorage.getItem("redirectUri");
@@ -88,8 +98,14 @@ export function AuthScapeApp({
88
98
 
89
99
  // ---------- GA + Clarity ----------
90
100
  async function initGA(G) {
91
- if (!GA4React.isInitialized() && G && typeof window !== "undefined") {
92
- ga4React.current = new GA4React(G, { debug_mode: !process.env.production });
101
+ if (
102
+ typeof window !== "undefined" &&
103
+ !GA4React.isInitialized() &&
104
+ G
105
+ ) {
106
+ ga4React.current = new GA4React(G, {
107
+ debug_mode: !process.env.production,
108
+ });
93
109
  try {
94
110
  await ga4React.current.initialize();
95
111
  } catch (error) {
@@ -106,6 +122,7 @@ export function AuthScapeApp({
106
122
 
107
123
  const databaseDrivenPageView = (pathName) => {
108
124
  if (process.env.enableDatabaseAnalytics !== "true") return;
125
+ if (typeof window === "undefined") return;
109
126
  if (pathName === "/signin-oidc") return;
110
127
 
111
128
  const host = window.location.protocol + "//" + window.location.host;
@@ -115,11 +132,11 @@ export function AuthScapeApp({
115
132
  locationId: signedInUser.current?.locationId,
116
133
  companyId: signedInUser.current?.companyId,
117
134
  uri: pathName,
118
- host
135
+ host,
119
136
  });
120
137
  };
121
138
 
122
- // ---------- Auth + Tracking Init ----------
139
+ // ---------- Auth Init ----------
123
140
  useEffect(() => {
124
141
  if (queryCode) {
125
142
  signInValidator(queryCode);
@@ -139,7 +156,7 @@ export function AuthScapeApp({
139
156
 
140
157
  // ---------- Analytics Init ----------
141
158
  useEffect(() => {
142
- if (!frontEndLoadedState) return;
159
+ if (!frontEndLoadedState || typeof window === "undefined") return;
143
160
 
144
161
  if (pageProps.googleAnalytics4Code) {
145
162
  initGA(pageProps.googleAnalytics4Code);
@@ -155,7 +172,7 @@ export function AuthScapeApp({
155
172
 
156
173
  databaseDrivenPageView(window.location.pathname);
157
174
 
158
- Router.events.on('routeChangeComplete', (url) => {
175
+ Router.events.on("routeChangeComplete", (url) => {
159
176
  ga4React.current?.pageview(url);
160
177
  databaseDrivenPageView(url);
161
178
  });
@@ -163,32 +180,59 @@ export function AuthScapeApp({
163
180
 
164
181
  // ---------- Enforce Login ----------
165
182
  useEffect(() => {
166
- if (enforceLoggedIn && pathname !== "/signin-oidc" && frontEndLoadedState && !signedInUserState) {
183
+ if (
184
+ enforceLoggedIn &&
185
+ pathname !== "/signin-oidc" &&
186
+ frontEndLoadedState &&
187
+ !signedInUserState
188
+ ) {
167
189
  authService().login();
168
190
  }
169
191
  }, [signedInUserState, enforceLoggedIn, frontEndLoadedState, pathname]);
170
192
 
171
193
  const GetSignedInUser = () => signedInUser.current;
172
-
173
- const useStore = create((set) => (store));
194
+ const useStore = create((set) => store);
174
195
 
175
196
  // ---------- Render ----------
176
197
  const pageContent = layout
177
198
  ? layout({
178
- children: <Component {...pageProps} currentUser={GetSignedInUser()} loadedUser={frontEndLoadedState} setIsLoading={setIsLoadingShow} logEvent={logEvent} store={useStore} toast={toast} />,
199
+ children: (
200
+ <Component
201
+ {...pageProps}
202
+ currentUser={GetSignedInUser()}
203
+ loadedUser={frontEndLoadedState}
204
+ setIsLoading={setIsLoadingShow}
205
+ logEvent={logEvent}
206
+ store={useStore}
207
+ toast={toast}
208
+ />
209
+ ),
179
210
  currentUser: GetSignedInUser(),
180
211
  setIsLoading: setIsLoadingShow,
181
212
  logEvent,
182
213
  toast,
183
214
  store: useStore,
184
- pageProps
215
+ pageProps,
185
216
  })
186
- : <Component {...pageProps} currentUser={GetSignedInUser()} loadedUser={frontEndLoadedState} setIsLoading={setIsLoadingShow} logEvent={logEvent} store={useStore} toast={toast} />;
217
+ : (
218
+ <Component
219
+ {...pageProps}
220
+ currentUser={GetSignedInUser()}
221
+ loadedUser={frontEndLoadedState}
222
+ setIsLoading={setIsLoadingShow}
223
+ logEvent={logEvent}
224
+ store={useStore}
225
+ toast={toast}
226
+ />
227
+ );
187
228
 
188
229
  return (
189
230
  <>
190
231
  <Head>
191
- <meta name="viewport" content="width=device-width, initial-scale=0.86, maximum-scale=5.0, minimum-scale=0.86" />
232
+ <meta
233
+ name="viewport"
234
+ content="width=device-width, initial-scale=0.86, maximum-scale=5.0, minimum-scale=0.86"
235
+ />
192
236
  </Head>
193
237
 
194
238
  <ThemeProvider theme={muiTheme}>