authscape 1.0.758 → 1.0.762

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
@@ -76,6 +76,7 @@ function AuthScapeApp(_ref) {
76
76
  var Component = _ref.Component,
77
77
  layout = _ref.layout,
78
78
  loadingLayout = _ref.loadingLayout,
79
+ signInLoadingComponent = _ref.signInLoadingComponent,
79
80
  pageProps = _ref.pageProps,
80
81
  _ref$muiTheme = _ref.muiTheme,
81
82
  muiTheme = _ref$muiTheme === void 0 ? {} : _ref$muiTheme,
@@ -97,6 +98,10 @@ function AuthScapeApp(_ref) {
97
98
  _useState6 = _slicedToArray(_useState5, 2),
98
99
  signedInUserState = _useState6[0],
99
100
  setSignedInUserState = _useState6[1];
101
+ var _useState7 = (0, _react.useState)(false),
102
+ _useState8 = _slicedToArray(_useState7, 2),
103
+ isSigningIn = _useState8[0],
104
+ setIsSigningIn = _useState8[1];
100
105
  var loadingAuth = (0, _react.useRef)(false);
101
106
  var signedInUser = (0, _react.useRef)(null);
102
107
  var queryCodeUsed = (0, _react.useRef)(null);
@@ -125,13 +130,17 @@ function AuthScapeApp(_ref) {
125
130
  }
126
131
  return _context.abrupt("return");
127
132
  case 5:
133
+ setIsSigningIn(true);
128
134
  codeVerifier = window.localStorage.getItem("verifier");
129
135
  if (!(!codeFromQuery || !codeVerifier)) {
130
- _context.next = 8;
136
+ _context.next = 11;
131
137
  break;
132
138
  }
139
+ // No code or verifier - redirect to login
140
+ window.localStorage.clear();
141
+ module.exports.authService().login();
133
142
  return _context.abrupt("return");
134
- case 8:
143
+ case 11:
135
144
  headers = {
136
145
  "Content-Type": "application/x-www-form-urlencoded"
137
146
  };
@@ -143,55 +152,62 @@ function AuthScapeApp(_ref) {
143
152
  client_secret: process.env.client_secret,
144
153
  code_verifier: codeVerifier
145
154
  });
146
- _context.prev = 10;
147
- _context.next = 13;
155
+ _context.prev = 13;
156
+ _context.next = 16;
148
157
  return _axios["default"].post(process.env.authorityUri + "/connect/token", body, {
149
158
  headers: headers
150
159
  });
151
- case 13:
160
+ case 16:
152
161
  response = _context.sent;
153
162
  domainHost = window.location.hostname.split(".").slice(-2).join(".");
154
163
  window.localStorage.removeItem("verifier");
155
164
 
156
165
  // NOTE: replace setCookie below with your implementation if different
157
- _context.next = 18;
166
+ _context.next = 21;
158
167
  return setCookie("access_token", response.data.access_token, {
159
168
  maxAge: 60 * 60 * 24 * 365,
160
169
  path: "/",
161
170
  domain: domainHost,
162
171
  secure: true
163
172
  });
164
- case 18:
165
- _context.next = 20;
173
+ case 21:
174
+ _context.next = 23;
166
175
  return setCookie("expires_in", response.data.expires_in, {
167
176
  maxAge: 60 * 60 * 24 * 365,
168
177
  path: "/",
169
178
  domain: domainHost,
170
179
  secure: true
171
180
  });
172
- case 20:
173
- _context.next = 22;
181
+ case 23:
182
+ _context.next = 25;
174
183
  return setCookie("refresh_token", response.data.refresh_token, {
175
184
  maxAge: 60 * 60 * 24 * 365,
176
185
  path: "/",
177
186
  domain: domainHost,
178
187
  secure: true
179
188
  });
180
- case 22:
181
- redirectUri = window.localStorage.getItem("redirectUri");
189
+ case 25:
190
+ redirectUri = window.localStorage.getItem("redirectUri") || "/";
182
191
  window.localStorage.clear();
183
- window.location.href = redirectUri || "/";
184
- _context.next = 30;
192
+
193
+ // Navigate to the redirect URI - use window.location for a clean page load
194
+ // This ensures all state is properly initialized on the target page
195
+ window.location.href = redirectUri;
196
+ _context.next = 36;
185
197
  break;
186
- case 27:
187
- _context.prev = 27;
188
- _context.t0 = _context["catch"](10);
189
- console.error("PKCE sign-in failed", _context.t0);
190
198
  case 30:
199
+ _context.prev = 30;
200
+ _context.t0 = _context["catch"](13);
201
+ console.error("PKCE sign-in failed", _context.t0);
202
+ // Invalid code - clear storage and redirect to login
203
+ window.localStorage.clear();
204
+ setIsSigningIn(false);
205
+ module.exports.authService().login();
206
+ case 36:
191
207
  case "end":
192
208
  return _context.stop();
193
209
  }
194
- }, _callee, null, [[10, 27]]);
210
+ }, _callee, null, [[13, 30]]);
195
211
  }));
196
212
  return function signInValidator(_x) {
197
213
  return _ref2.apply(this, arguments);
@@ -321,6 +337,43 @@ function AuthScapeApp(_ref) {
321
337
  });
322
338
 
323
339
  // ----- Render (SSR-safe; always output page so <title> is visible) -----
340
+
341
+ // Default sign-in loading component if none provided
342
+ var defaultSignInLoading = /*#__PURE__*/_react["default"].createElement("div", {
343
+ style: {
344
+ display: 'flex',
345
+ flexDirection: 'column',
346
+ alignItems: 'center',
347
+ justifyContent: 'center',
348
+ height: '100vh',
349
+ width: '100%',
350
+ backgroundColor: '#f5f5f5'
351
+ }
352
+ }, /*#__PURE__*/_react["default"].createElement("div", {
353
+ style: {
354
+ width: '40px',
355
+ height: '40px',
356
+ border: '4px solid #e0e0e0',
357
+ borderTop: '4px solid #3498db',
358
+ borderRadius: '50%',
359
+ animation: 'spin 1s linear infinite'
360
+ }
361
+ }), /*#__PURE__*/_react["default"].createElement("p", {
362
+ style: {
363
+ marginTop: '16px',
364
+ color: '#666'
365
+ }
366
+ }, "Signing in..."), /*#__PURE__*/_react["default"].createElement("style", null, "\n @keyframes spin {\n 0% { transform: rotate(0deg); }\n 100% { transform: rotate(360deg); }\n }\n "));
367
+
368
+ // Show loading screen when signing in
369
+ if (isSigningIn) {
370
+ return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_head["default"], null, /*#__PURE__*/_react["default"].createElement("meta", {
371
+ name: "viewport",
372
+ content: "width=device-width, initial-scale=0.86, maximum-scale=5.0, minimum-scale=0.86"
373
+ })), /*#__PURE__*/_react["default"].createElement(_styles.ThemeProvider, {
374
+ theme: muiTheme
375
+ }, signInLoadingComponent || defaultSignInLoading));
376
+ }
324
377
  var pageContent = layout ? layout({
325
378
  children: /*#__PURE__*/_react["default"].createElement(Component, _extends({}, pageProps, {
326
379
  currentUser: currentUser,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "authscape",
3
- "version": "1.0.758",
3
+ "version": "1.0.762",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -60,6 +60,7 @@ export function AuthScapeApp({
60
60
  Component,
61
61
  layout,
62
62
  loadingLayout,
63
+ signInLoadingComponent,
63
64
  pageProps,
64
65
  muiTheme = {},
65
66
  store = {},
@@ -69,6 +70,7 @@ export function AuthScapeApp({
69
70
  const [frontEndLoadedState, setFrontEndLoadedState] = useState(false);
70
71
  const [isLoadingShow, setIsLoadingShow] = useState(false);
71
72
  const [signedInUserState, setSignedInUserState] = useState(null);
73
+ const [isSigningIn, setIsSigningIn] = useState(false);
72
74
 
73
75
  const loadingAuth = useRef(false);
74
76
  const signedInUser = useRef(null);
@@ -86,8 +88,15 @@ export function AuthScapeApp({
86
88
 
87
89
  if (typeof window === "undefined") return;
88
90
 
91
+ setIsSigningIn(true);
92
+
89
93
  const codeVerifier = window.localStorage.getItem("verifier");
90
- if (!codeFromQuery || !codeVerifier) return;
94
+ if (!codeFromQuery || !codeVerifier) {
95
+ // No code or verifier - redirect to login
96
+ window.localStorage.clear();
97
+ module.exports.authService().login();
98
+ return;
99
+ }
91
100
 
92
101
  const headers = { "Content-Type": "application/x-www-form-urlencoded" };
93
102
 
@@ -131,11 +140,18 @@ export function AuthScapeApp({
131
140
  secure: true,
132
141
  });
133
142
 
134
- const redirectUri = window.localStorage.getItem("redirectUri");
143
+ const redirectUri = window.localStorage.getItem("redirectUri") || "/";
135
144
  window.localStorage.clear();
136
- window.location.href = redirectUri || "/";
145
+
146
+ // Navigate to the redirect URI - use window.location for a clean page load
147
+ // This ensures all state is properly initialized on the target page
148
+ window.location.href = redirectUri;
137
149
  } catch (exp) {
138
150
  console.error("PKCE sign-in failed", exp);
151
+ // Invalid code - clear storage and redirect to login
152
+ window.localStorage.clear();
153
+ setIsSigningIn(false);
154
+ module.exports.authService().login();
139
155
  }
140
156
  };
141
157
 
@@ -246,6 +262,53 @@ export function AuthScapeApp({
246
262
  const useStore = create(() => store);
247
263
 
248
264
  // ----- Render (SSR-safe; always output page so <title> is visible) -----
265
+
266
+ // Default sign-in loading component if none provided
267
+ const defaultSignInLoading = (
268
+ <div style={{
269
+ display: 'flex',
270
+ flexDirection: 'column',
271
+ alignItems: 'center',
272
+ justifyContent: 'center',
273
+ height: '100vh',
274
+ width: '100%',
275
+ backgroundColor: '#f5f5f5'
276
+ }}>
277
+ <div style={{
278
+ width: '40px',
279
+ height: '40px',
280
+ border: '4px solid #e0e0e0',
281
+ borderTop: '4px solid #3498db',
282
+ borderRadius: '50%',
283
+ animation: 'spin 1s linear infinite'
284
+ }} />
285
+ <p style={{ marginTop: '16px', color: '#666' }}>Signing in...</p>
286
+ <style>{`
287
+ @keyframes spin {
288
+ 0% { transform: rotate(0deg); }
289
+ 100% { transform: rotate(360deg); }
290
+ }
291
+ `}</style>
292
+ </div>
293
+ );
294
+
295
+ // Show loading screen when signing in
296
+ if (isSigningIn) {
297
+ return (
298
+ <>
299
+ <Head>
300
+ <meta
301
+ name="viewport"
302
+ content="width=device-width, initial-scale=0.86, maximum-scale=5.0, minimum-scale=0.86"
303
+ />
304
+ </Head>
305
+ <ThemeProvider theme={muiTheme}>
306
+ {signInLoadingComponent || defaultSignInLoading}
307
+ </ThemeProvider>
308
+ </>
309
+ );
310
+ }
311
+
249
312
  const pageContent = layout
250
313
  ? layout({
251
314
  children: (