authscape 1.0.776 → 1.0.780

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,9 +42,10 @@ exports.useNotifications = useNotifications;
42
42
  var _react = _interopRequireWildcard(require("react"));
43
43
  var _reactToastify = require("react-toastify");
44
44
  var _head = _interopRequireDefault(require("next/head"));
45
- var _router = _interopRequireWildcard(require("next/router"));
45
+ var _navigation = require("next/navigation");
46
46
  var _axios = _interopRequireDefault(require("axios"));
47
47
  var _queryString = _interopRequireDefault(require("query-string"));
48
+ var _router = _interopRequireDefault(require("next/router"));
48
49
  var _ga4React = _interopRequireDefault(require("ga-4-react"));
49
50
  var _zustand = require("zustand");
50
51
  var _reactMicrosoftClarity = require("react-microsoft-clarity");
@@ -726,6 +727,7 @@ function ensureUserHelpers(u) {
726
727
  // AuthScapeApp Component
727
728
  // ============================================================================
728
729
  function AuthScapeApp(_ref0) {
730
+ var _searchParams$get;
729
731
  var Component = _ref0.Component,
730
732
  layout = _ref0.layout,
731
733
  loadingLayout = _ref0.loadingLayout,
@@ -769,32 +771,9 @@ function AuthScapeApp(_ref0) {
769
771
  var ga4React = (0, _react.useRef)(null);
770
772
  var errorTrackingInitializedRef = (0, _react.useRef)(false);
771
773
  var loginRedirectPending = (0, _react.useRef)(false);
772
-
773
- // Use Pages Router's `useRouter` instead of `useSearchParams`/`usePathname`
774
- // from `next/navigation`. The `next/navigation` hooks don't hydrate query
775
- // params reliably on the 404 page in Webkit/Safari — when the IDP redirects
776
- // back to /signin-oidc (a URL with no Next.js page in the consumer project),
777
- // useSearchParams() returns null and the PKCE code is never picked up.
778
- // The Pages Router router parses query from `asPath` and works on 404 too.
779
- //
780
- // SSR safety: accessing `router.isReady`, `router.query`, `router.asPath`
781
- // throws "NextRouter was not mounted" on server-side renders where the
782
- // router singleton hasn't been initialized (Static Generation, _error
783
- // pages, some edge-runtime paths). We only do the work on the client.
784
- var router = (0, _router.useRouter)();
785
- var queryCode = null;
786
- var pathname = "";
787
- if (typeof window !== "undefined") {
788
- try {
789
- if (router && router.isReady) {
790
- var raw = router.query && router.query.code;
791
- queryCode = typeof raw === "string" ? raw : Array.isArray(raw) ? raw[0] : null;
792
- }
793
- pathname = (router && router.asPath || "").split("?")[0].split("#")[0];
794
- } catch (_) {
795
- // router not mounted (SSR / static render) — leave defaults
796
- }
797
- }
774
+ var searchParams = (0, _navigation.useSearchParams)();
775
+ var queryCode = (_searchParams$get = searchParams === null || searchParams === void 0 ? void 0 : searchParams.get("code")) !== null && _searchParams$get !== void 0 ? _searchParams$get : null;
776
+ var pathname = (0, _navigation.usePathname)();
798
777
  var signInValidator = /*#__PURE__*/function () {
799
778
  var _ref1 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(codeFromQuery) {
800
779
  var codeVerifier, headers, body, response, domainHost, redirectUri, usr, enrichedUser;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "authscape",
3
- "version": "1.0.776",
3
+ "version": "1.0.780",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -4,7 +4,7 @@ import Head from "next/head";
4
4
 
5
5
  // Re-export toast and transitions so pages can import from authscape
6
6
  export { toast, Bounce, Slide, Zoom, Flip };
7
- import { useRouter } from "next/router";
7
+ import { useSearchParams, usePathname } from "next/navigation";
8
8
  import axios from "axios";
9
9
  import querystring from "query-string";
10
10
  import Router from "next/router";
@@ -501,33 +501,9 @@ export function AuthScapeApp({
501
501
  const errorTrackingInitializedRef = useRef(false);
502
502
  const loginRedirectPending = useRef(false);
503
503
 
504
- // Use Pages Router's `useRouter` instead of `useSearchParams`/`usePathname`
505
- // from `next/navigation`. The `next/navigation` hooks don't hydrate query
506
- // params reliably on the 404 page in Webkit/Safari — when the IDP redirects
507
- // back to /signin-oidc (a URL with no Next.js page in the consumer project),
508
- // useSearchParams() returns null and the PKCE code is never picked up.
509
- // The Pages Router router parses query from `asPath` and works on 404 too.
510
- //
511
- // SSR safety: accessing `router.isReady`, `router.query`, `router.asPath`
512
- // throws "NextRouter was not mounted" on server-side renders where the
513
- // router singleton hasn't been initialized (Static Generation, _error
514
- // pages, some edge-runtime paths). We only do the work on the client.
515
- const router = useRouter();
516
- let queryCode = null;
517
- let pathname = "";
518
- if (typeof window !== "undefined") {
519
- try {
520
- if (router && router.isReady) {
521
- const raw = router.query && router.query.code;
522
- queryCode = typeof raw === "string"
523
- ? raw
524
- : (Array.isArray(raw) ? raw[0] : null);
525
- }
526
- pathname = ((router && router.asPath) || "").split("?")[0].split("#")[0];
527
- } catch (_) {
528
- // router not mounted (SSR / static render) — leave defaults
529
- }
530
- }
504
+ const searchParams = useSearchParams();
505
+ const queryCode = searchParams?.get("code") ?? null;
506
+ const pathname = usePathname();
531
507
 
532
508
  const signInValidator = async (codeFromQuery) => {
533
509
  if (queryCodeUsed.current === codeFromQuery) return;
@@ -41,6 +41,64 @@ import { createSitemapRoute } from 'authscape/src/lib/sitemap-route';
41
41
  export const GET = createSitemapRoute(process.env.apiUri);
42
42
  `;
43
43
 
44
+ // ---------------------------------------------------------------------------
45
+ // /signin-oidc page templates
46
+ // ---------------------------------------------------------------------------
47
+ // AuthScapeApp reads the PKCE `code` query param from `useSearchParams()`
48
+ // (next/navigation). If the consumer doesn't have a `/signin-oidc` page, the
49
+ // IDP's redirect back lands on Next.js's 404 page — and Webkit/Safari
50
+ // doesn't reliably hydrate `useSearchParams()` on the 404 page. The code is
51
+ // never read, the user is stuck.
52
+ //
53
+ // Making /signin-oidc a real Next.js page (200 status) fixes this in every
54
+ // browser. The page itself is a placeholder; AuthScapeApp's signInValidator
55
+ // does the actual token exchange.
56
+
57
+ const SIGNIN_OIDC_PAGES_ROUTER_TEMPLATE = `// Auto-generated by AuthScape - Do not edit manually.
58
+ // Exists so /signin-oidc returns HTTP 200 (not the Next.js 404 page).
59
+ // Required for Webkit/Safari: useSearchParams() doesn't hydrate on the 404
60
+ // page in Webkit, so the PKCE 'code' query param is never read and sign-in
61
+ // silently stalls. With this real page in place, AuthScapeApp's
62
+ // signInValidator picks up the code and completes the exchange normally.
63
+ export default function SignInOidc() {
64
+ return (
65
+ <div
66
+ style={{
67
+ display: "flex",
68
+ alignItems: "center",
69
+ justifyContent: "center",
70
+ minHeight: "60vh",
71
+ fontFamily: "system-ui, -apple-system, Segoe UI, sans-serif",
72
+ color: "#666",
73
+ }}
74
+ >
75
+ Signing you in…
76
+ </div>
77
+ );
78
+ }
79
+ `;
80
+
81
+ const SIGNIN_OIDC_APP_ROUTER_TEMPLATE = `// Auto-generated by AuthScape - Do not edit manually.
82
+ // Exists so /signin-oidc returns HTTP 200 (not the Next.js 404 page).
83
+ // Required for Webkit/Safari to pick up the PKCE 'code' query param.
84
+ export default function SignInOidc() {
85
+ return (
86
+ <div
87
+ style={{
88
+ display: "flex",
89
+ alignItems: "center",
90
+ justifyContent: "center",
91
+ minHeight: "60vh",
92
+ fontFamily: "system-ui, -apple-system, Segoe UI, sans-serif",
93
+ color: "#666",
94
+ }}
95
+ >
96
+ Signing you in…
97
+ </div>
98
+ );
99
+ }
100
+ `;
101
+
44
102
  function detectProjectStructure() {
45
103
  // Get the parent directory where the user ran npm install
46
104
  // This goes up from node_modules/authscape to the project root
@@ -118,9 +176,42 @@ function setupSitemap() {
118
176
  }
119
177
  }
120
178
 
179
+ function setupSigninOidc() {
180
+ const structure = detectProjectStructure();
181
+ if (!structure) return;
182
+
183
+ const targetFile =
184
+ structure.type === 'app'
185
+ ? path.join(structure.baseDir, 'signin-oidc', 'page.js')
186
+ : path.join(structure.baseDir, 'signin-oidc.js');
187
+
188
+ if (fs.existsSync(targetFile)) {
189
+ // File exists, don't overwrite — consumer may have their own handler
190
+ return;
191
+ }
192
+
193
+ try {
194
+ fs.mkdirSync(path.dirname(targetFile), { recursive: true });
195
+ fs.writeFileSync(
196
+ targetFile,
197
+ structure.type === 'app' ? SIGNIN_OIDC_APP_ROUTER_TEMPLATE : SIGNIN_OIDC_PAGES_ROUTER_TEMPLATE,
198
+ 'utf8'
199
+ );
200
+ console.log(
201
+ '✅ AuthScape signin-oidc page configured at /signin-oidc (' +
202
+ (structure.type === 'app' ? 'App Router' : 'Pages Router') +
203
+ ')'
204
+ );
205
+ } catch (error) {
206
+ console.log('⚠️ Could not auto-configure /signin-oidc:', error.message);
207
+ console.log(' Without this page, Safari users will fail to sign in.');
208
+ }
209
+ }
210
+
121
211
  // Run the setup
122
212
  try {
123
213
  setupSitemap();
214
+ setupSigninOidc();
124
215
  } catch (error) {
125
216
  // Completely silent failure to avoid breaking npm install
126
217
  // Only log if there's an unexpected error