authscape 1.0.774 → 1.0.776

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
@@ -776,14 +776,25 @@ function AuthScapeApp(_ref0) {
776
776
  // back to /signin-oidc (a URL with no Next.js page in the consumer project),
777
777
  // useSearchParams() returns null and the PKCE code is never picked up.
778
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.
779
784
  var router = (0, _router.useRouter)();
780
- var rawQueryCode = router.isReady ? router.query.code : null;
781
- // router.query values can be string | string[] — coerce to a single string.
782
- var queryCode = typeof rawQueryCode === "string" ? rawQueryCode : Array.isArray(rawQueryCode) ? rawQueryCode[0] : null;
783
- // Pages Router's `router.pathname` returns the route file path (e.g. "/_error"
784
- // for the 404 page). The auth-redirect guard below compares against
785
- // "/signin-oidc", so we derive the actual URL path from `asPath` instead.
786
- var pathname = (router.asPath || "").split("?")[0].split("#")[0];
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
+ }
787
798
  var signInValidator = /*#__PURE__*/function () {
788
799
  var _ref1 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(codeFromQuery) {
789
800
  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.774",
3
+ "version": "1.0.776",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -507,16 +507,27 @@ export function AuthScapeApp({
507
507
  // back to /signin-oidc (a URL with no Next.js page in the consumer project),
508
508
  // useSearchParams() returns null and the PKCE code is never picked up.
509
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.
510
515
  const router = useRouter();
511
- const rawQueryCode = router.isReady ? router.query.code : null;
512
- // router.query values can be string | string[] — coerce to a single string.
513
- const queryCode = typeof rawQueryCode === "string"
514
- ? rawQueryCode
515
- : (Array.isArray(rawQueryCode) ? rawQueryCode[0] : null);
516
- // Pages Router's `router.pathname` returns the route file path (e.g. "/_error"
517
- // for the 404 page). The auth-redirect guard below compares against
518
- // "/signin-oidc", so we derive the actual URL path from `asPath` instead.
519
- const pathname = (router.asPath || "").split("?")[0].split("#")[0];
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
+ }
520
531
 
521
532
  const signInValidator = async (codeFromQuery) => {
522
533
  if (queryCodeUsed.current === codeFromQuery) return;