cloudflare-next-intl 0.6.20 → 0.6.22

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.
@@ -1,6 +1,20 @@
1
1
  'use client';
2
2
  import config from '@intl-config';
3
3
  import requireFirebaseAuthConfig from '../require_config';
4
+ async function initializeFirebaseAppCheck(app, appCheckConfig) {
5
+ const { initializeAppCheck, ReCaptchaV3Provider, ReCaptchaEnterpriseProvider } = await import('firebase/app-check');
6
+ if (appCheckConfig.debugToken) {
7
+ globalThis.FIREBASE_APPCHECK_DEBUG_TOKEN =
8
+ appCheckConfig.debugToken;
9
+ }
10
+ const provider = appCheckConfig.recaptchaEnterpriseSiteKey
11
+ ? new ReCaptchaEnterpriseProvider(appCheckConfig.recaptchaEnterpriseSiteKey)
12
+ : new ReCaptchaV3Provider(appCheckConfig.recaptchaV3SiteKey);
13
+ initializeAppCheck(app, {
14
+ provider,
15
+ isTokenAutoRefreshEnabled: appCheckConfig.isTokenAutoRefreshEnabled ?? true,
16
+ });
17
+ }
4
18
  let cached;
5
19
  let cachedPromise;
6
20
  /**
@@ -16,7 +30,7 @@ export async function getFirebaseAuthClient() {
16
30
  return cached;
17
31
  if (!cachedPromise) {
18
32
  const fa = config.firebaseAuth;
19
- cachedPromise = Promise.all([import('firebase/app'), import('firebase/auth')]).then(([{ getApp, getApps, initializeApp }, { getAuth }]) => {
33
+ cachedPromise = Promise.all([import('firebase/app'), import('firebase/auth')]).then(async ([{ getApp, getApps, initializeApp }, { getAuth }]) => {
20
34
  const firebaseConfig = {
21
35
  apiKey: fa.apiKey,
22
36
  authDomain: fa.authDomain,
@@ -27,6 +41,9 @@ export async function getFirebaseAuthClient() {
27
41
  measurementId: fa.measurementId,
28
42
  };
29
43
  const app = getApps().length ? getApp() : initializeApp(firebaseConfig);
44
+ if (fa.appCheck) {
45
+ await initializeFirebaseAppCheck(app, fa.appCheck);
46
+ }
30
47
  const auth = getAuth(app);
31
48
  cached = { app, auth };
32
49
  return cached;
@@ -440,6 +440,13 @@ export interface FirebaseAuthRoutingConfig {
440
440
  appId: string;
441
441
  /** Firebase Analytics measurement ID. */
442
442
  measurementId?: string;
443
+ /**
444
+ * Enables Firebase App Check on the client. Omit to leave App Check
445
+ * uninitialized — required if App Check enforcement is turned on for
446
+ * Auth/Firestore/etc. in the Firebase console, or every request gets
447
+ * rejected with 401.
448
+ */
449
+ appCheck?: FirebaseAppCheckConfig;
443
450
  /** Path to redirect signed-out users to, e.g. "/login". Must start with "/" — `setIntlConfig` auto-corrects a missing leading slash with a warning. */
444
451
  redirectAuthPath: string;
445
452
  /** Path to redirect signed-in users away from auth pages to, e.g. "/". Must start with "/" — `setIntlConfig` auto-corrects a missing leading slash with a warning. */
@@ -531,6 +538,24 @@ export interface FirebaseAuthRoutingConfig {
531
538
  */
532
539
  onSignOut?: () => void | Promise<void>;
533
540
  }
541
+ export interface FirebaseAppCheckConfig {
542
+ /** reCAPTCHA v3 site key. Mutually exclusive with `recaptchaEnterpriseSiteKey`. */
543
+ recaptchaV3SiteKey?: string;
544
+ /** reCAPTCHA Enterprise site key. Mutually exclusive with `recaptchaV3SiteKey`. */
545
+ recaptchaEnterpriseSiteKey?: string;
546
+ /**
547
+ * Enables App Check's debug token on this client. Pass `true` to have
548
+ * the Firebase SDK generate a new random token each run (logged to the
549
+ * console — register it in the Firebase console every time it changes).
550
+ * Pass a fixed UUID string instead to reuse the same token across
551
+ * restarts/builds — set `self.FIREBASE_APPCHECK_DEBUG_TOKEN` to it
552
+ * before init, register that one UUID once, and it never changes.
553
+ * Use only for local development — never set this in production.
554
+ */
555
+ debugToken?: boolean | string;
556
+ /** Forwarded to `initializeAppCheck`'s `isTokenAutoRefreshEnabled`. Defaults to `true`. */
557
+ isTokenAutoRefreshEnabled?: boolean;
558
+ }
534
559
  export interface CookieAttributes {
535
560
  /**
536
561
  * Specifies the value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.3|Domain Set-Cookie attribute}. By default, no
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cloudflare-next-intl",
3
- "version": "0.6.20",
3
+ "version": "0.6.22",
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",