cloudflare-next-intl 0.6.19 → 0.6.20

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.
@@ -9,6 +9,7 @@ import { getFirebaseAuthClient, getFirebaseAuthModule } from './firebase_client'
9
9
  import { setAuthUserCache } from './auth_user_cache';
10
10
  import { defaultEmailVerifiedHintCookieName, defaultRefreshTokenCookieName, defaultSessionCookieName } from '../middleware/update_session';
11
11
  import decodeJwtPayload from '../decode_jwt_payload';
12
+ import isWhitelisted from '../is_whitelisted';
12
13
  import setCookie from '../../client/functions/set_cookie';
13
14
  import getCookie from '../../client/functions/get_cookie';
14
15
  import clearSessionAction from '../server/clear_session_action';
@@ -87,7 +88,7 @@ export default function AuthUserProvider({ initialUser = null, children }) {
87
88
  const router = useRouter();
88
89
  const pathname = usePathname();
89
90
  const isAuthPage = fa.isAuthPath(pathname);
90
- const isWhiteListed = fa.whiteListPaths?.includes(pathname) ?? false;
91
+ const isWhiteListed = isWhitelisted(pathname, fa.whiteListPaths);
91
92
  const maxAge = fa.sessionCookieMaxAge ?? 60 * 60 * 24 * 5;
92
93
  const sessionCookieName = fa.sessionCookieName ?? defaultSessionCookieName;
93
94
  const refreshTokenMaxAge = fa.refreshTokenCookieMaxAge ?? 60 * 60 * 24 * 365;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Whether `path` is exempt from auth redirects under `whiteListPaths`.
3
+ * Matches an entry exactly, OR as a path-segment prefix (`/bonds` also
4
+ * covers `/bonds/some-slug`, but NOT `/bonds-extra`) — a plain
5
+ * `startsWith` would let a differently-named sibling route slip through
6
+ * whenever one route's name happens to prefix another's.
7
+ */
8
+ export default function isWhitelisted(path: string, whiteListPaths: readonly string[] | undefined): boolean;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Whether `path` is exempt from auth redirects under `whiteListPaths`.
3
+ * Matches an entry exactly, OR as a path-segment prefix (`/bonds` also
4
+ * covers `/bonds/some-slug`, but NOT `/bonds-extra`) — a plain
5
+ * `startsWith` would let a differently-named sibling route slip through
6
+ * whenever one route's name happens to prefix another's.
7
+ */
8
+ export default function isWhitelisted(path, whiteListPaths) {
9
+ if (!whiteListPaths)
10
+ return false;
11
+ return whiteListPaths.some((entry) => path === entry || path.startsWith(`${entry}/`));
12
+ }
@@ -1,6 +1,7 @@
1
1
  import { NextResponse } from 'next/server';
2
2
  import config from '@intl-config';
3
3
  import decodeJwtPayload from '../decode_jwt_payload';
4
+ import isWhitelisted from '../is_whitelisted';
4
5
  export const defaultSessionCookieName = '__fa_session__';
5
6
  export const defaultRefreshTokenCookieName = '__fa_refresh_token__';
6
7
  // Non-httpOnly: written by AuthUserProvider (client) every time it observes
@@ -219,7 +220,7 @@ export default async function updateSession(request, baseResponse, locale) {
219
220
  }
220
221
  }
221
222
  }
222
- const isWhiteListed = fa.whiteListPaths?.includes(path) ?? false;
223
+ const isWhiteListed = isWhitelisted(path, fa.whiteListPaths);
223
224
  if (isWhiteListed)
224
225
  return baseResponse;
225
226
  const isAuthPage = fa.isAuthPath(path);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cloudflare-next-intl",
3
- "version": "0.6.19",
3
+ "version": "0.6.20",
4
4
  "description": "Optimized Next Intl Package Special for App Router and Cloudflare",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",