authscape 1.0.773 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "authscape",
3
- "version": "1.0.773",
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;