cloudflare-next-intl 0.10.14 → 0.10.16
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/README.md +1 -0
- package/dist/src/firebase_auth/client/auth_user_provider.js +3 -1
- package/dist/src/vite/index.d.ts +1 -0
- package/dist/src/vite/index.js +1 -0
- package/dist/src/vite/optional_firebase_stub.d.ts +9 -0
- package/dist/src/vite/optional_firebase_stub.js +50 -0
- package/dist/src/vite/plugin.d.ts +1 -0
- package/dist/src/vite/plugin.js +4 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -510,6 +510,7 @@ bundled — for apps that never set `firebaseAuth`.
|
|
|
510
510
|
|
|
511
511
|
Features include:
|
|
512
512
|
- `whiteListPaths`: Array of paths exempt from auth redirects (matches exact path or path-segment prefix, e.g. `/bonds` matches `/bonds/some-slug`).
|
|
513
|
+
- `protectedPaths`: `(path) => boolean` gate that inverts `whiteListPaths` — when set, every path passes through unless `protectedPaths` (or `isAuthPath`) returns true, so unrecognised URLs reach the app's own routing instead of being redirected to `redirectAuthPath`. Preferred over `whiteListPaths` for apps where most pages are public: both the middleware and `AuthUserProvider` (client) derive their whitelist from it directly, so you don't maintain two separate path lists that can drift out of sync. `whiteListPaths` is only consulted when `protectedPaths` isn't set.
|
|
513
514
|
- `actionLinkPath`: Pinned route for handling Firebase action links (e.g. `/auth/action`), prioritized during cross-origin action link redirects.
|
|
514
515
|
- `createForgotPasswordAction(locale, actionCodeSettings?)`: Accepts optional Firebase `AuthActionCodeSettings` (e.g. `url` redirect link).
|
|
515
516
|
- `sendVerificationEmail(actionCodeSettings?)` on `useAuthUser()`: Custom action email settings when resending email verification.
|
|
@@ -76,7 +76,9 @@ export default function AuthUserProvider({ initialUser = null, children }) {
|
|
|
76
76
|
const router = useRouter();
|
|
77
77
|
const pathname = usePathname();
|
|
78
78
|
const isAuthPage = fa.isAuthPath(pathname);
|
|
79
|
-
const isWhiteListed =
|
|
79
|
+
const isWhiteListed = fa.protectedPaths
|
|
80
|
+
? !fa.protectedPaths(pathname) && !isAuthPage
|
|
81
|
+
: isWhitelisted(pathname, fa.whiteListPaths);
|
|
80
82
|
const maxAge = fa.sessionCookieMaxAge ?? 60 * 60 * 24 * 5;
|
|
81
83
|
const sessionCookieName = fa.sessionCookieName ?? defaultSessionCookieName;
|
|
82
84
|
const refreshTokenMaxAge = fa.refreshTokenCookieMaxAge ?? 60 * 60 * 24 * 365;
|
package/dist/src/vite/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export { buildIdAsset } from "./build_id_asset.js";
|
|
|
6
6
|
export { userAgentStubPlugin, USER_AGENT_STUB_ID, USER_AGENT_STUB_CODE } from "./user_agent_stub.js";
|
|
7
7
|
export { cfWorkersClientStubPlugin, CF_WORKERS_CLIENT_STUB_ID, CF_WORKERS_CLIENT_STUB_CODE } from "./cf_workers_client_stub.js";
|
|
8
8
|
export { bufferStubPlugin, BUFFER_STUB_ID } from "./buffer_stub.js";
|
|
9
|
+
export { optionalFirebaseStubPlugin, optionalFirebaseStubId, optionalFirebaseStubCode, isModuleInstalled, OPTIONAL_FIREBASE_MODULES, OPTIONAL_FIREBASE_STUB_PREFIX, } from "./optional_firebase_stub.js";
|
|
9
10
|
export { reactEvalStubPlugin, reactEvalEsbuildPlugin, transformReactEval, EVAL_WARNING_RE, EVAL_POLYFILL_SNIPPET, } from "./react_eval_stub.js";
|
|
10
11
|
export { vinextRouteWiringFixPlugin, patchAppPageRouteWiring, isAppPageRouteWiringFile, isAppPageRouteWiringAlreadyFixed, isVinextAppPageRouteWiringSafeOnDisk, patchAppPageProbe, isAppPageProbeFile, isAppPageProbeAlreadyFixed, isVinextAppPageProbeSafeOnDisk, type VinextRouteWiringFixPluginOptions, } from "./vinext_route_wiring_fix.js";
|
|
11
12
|
export { localeFilePlugin, resolveDefaultIntlConfigPath, type LocaleFilePluginOptions } from "./locale_file_plugin.js";
|
package/dist/src/vite/index.js
CHANGED
|
@@ -6,6 +6,7 @@ export { buildIdAsset } from "./build_id_asset.js";
|
|
|
6
6
|
export { userAgentStubPlugin, USER_AGENT_STUB_ID, USER_AGENT_STUB_CODE } from "./user_agent_stub.js";
|
|
7
7
|
export { cfWorkersClientStubPlugin, CF_WORKERS_CLIENT_STUB_ID, CF_WORKERS_CLIENT_STUB_CODE } from "./cf_workers_client_stub.js";
|
|
8
8
|
export { bufferStubPlugin, BUFFER_STUB_ID } from "./buffer_stub.js";
|
|
9
|
+
export { optionalFirebaseStubPlugin, optionalFirebaseStubId, optionalFirebaseStubCode, isModuleInstalled, OPTIONAL_FIREBASE_MODULES, OPTIONAL_FIREBASE_STUB_PREFIX, } from "./optional_firebase_stub.js";
|
|
9
10
|
export { reactEvalStubPlugin, reactEvalEsbuildPlugin, transformReactEval, EVAL_WARNING_RE, EVAL_POLYFILL_SNIPPET, } from "./react_eval_stub.js";
|
|
10
11
|
export { vinextRouteWiringFixPlugin, patchAppPageRouteWiring, isAppPageRouteWiringFile, isAppPageRouteWiringAlreadyFixed, isVinextAppPageRouteWiringSafeOnDisk, patchAppPageProbe, isAppPageProbeFile, isAppPageProbeAlreadyFixed, isVinextAppPageProbeSafeOnDisk, } from "./vinext_route_wiring_fix.js";
|
|
11
12
|
export { localeFilePlugin, resolveDefaultIntlConfigPath } from "./locale_file_plugin.js";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Plugin } from "vite";
|
|
2
|
+
export declare const OPTIONAL_FIREBASE_MODULES: readonly ["@firebase/app", "@firebase/auth", "@firebase/app-check", "@firebase/performance"];
|
|
3
|
+
export declare const OPTIONAL_FIREBASE_STUB_PREFIX = "\0cfni:optional-firebase-stub:";
|
|
4
|
+
export declare const optionalFirebaseStubId: (id: string) => string;
|
|
5
|
+
export declare function optionalFirebaseStubCode(id: string): string;
|
|
6
|
+
export declare function isModuleInstalled(id: string, root: string): boolean;
|
|
7
|
+
export declare function optionalFirebaseStubPlugin(options?: {
|
|
8
|
+
root?: string;
|
|
9
|
+
}): Plugin;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { pathToFileURL } from "node:url";
|
|
3
|
+
import { resolve } from "node:path";
|
|
4
|
+
export const OPTIONAL_FIREBASE_MODULES = [
|
|
5
|
+
"@firebase/app",
|
|
6
|
+
"@firebase/auth",
|
|
7
|
+
"@firebase/app-check",
|
|
8
|
+
"@firebase/performance",
|
|
9
|
+
];
|
|
10
|
+
export const OPTIONAL_FIREBASE_STUB_PREFIX = "\0cfni:optional-firebase-stub:";
|
|
11
|
+
export const optionalFirebaseStubId = (id) => `${OPTIONAL_FIREBASE_STUB_PREFIX}${id}`;
|
|
12
|
+
export function optionalFirebaseStubCode(id) {
|
|
13
|
+
const message = `cloudflare-next-intl: "${id}" is not installed. Add \`firebase\` (or ${id}) to your dependencies to use firebaseAuth features.`;
|
|
14
|
+
return `throw new Error(${JSON.stringify(message)});\n`;
|
|
15
|
+
}
|
|
16
|
+
export function isModuleInstalled(id, root) {
|
|
17
|
+
try {
|
|
18
|
+
createRequire(pathToFileURL(resolve(root, "package.json"))).resolve(id);
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export function optionalFirebaseStubPlugin(options = {}) {
|
|
26
|
+
const missing = new Set();
|
|
27
|
+
return {
|
|
28
|
+
name: "cfni:optional-firebase-stub",
|
|
29
|
+
enforce: "pre",
|
|
30
|
+
config(config) {
|
|
31
|
+
const root = options.root ?? config.root ?? process.cwd();
|
|
32
|
+
for (const id of OPTIONAL_FIREBASE_MODULES) {
|
|
33
|
+
if (!isModuleInstalled(id, root))
|
|
34
|
+
missing.add(id);
|
|
35
|
+
}
|
|
36
|
+
if (missing.size === 0)
|
|
37
|
+
return;
|
|
38
|
+
return { optimizeDeps: { exclude: [...missing] } };
|
|
39
|
+
},
|
|
40
|
+
resolveId(id) {
|
|
41
|
+
if (missing.has(id))
|
|
42
|
+
return optionalFirebaseStubId(id);
|
|
43
|
+
},
|
|
44
|
+
load(id) {
|
|
45
|
+
if (!id.startsWith(OPTIONAL_FIREBASE_STUB_PREFIX))
|
|
46
|
+
return;
|
|
47
|
+
return optionalFirebaseStubCode(id.slice(OPTIONAL_FIREBASE_STUB_PREFIX.length));
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
}
|
|
@@ -16,6 +16,7 @@ export interface CloudflareNextIntlOptions extends LocaleFilePluginOptions {
|
|
|
16
16
|
cfWorkersClientStub?: boolean;
|
|
17
17
|
bufferStub?: boolean;
|
|
18
18
|
reactEvalStub?: boolean;
|
|
19
|
+
optionalFirebaseStub?: boolean;
|
|
19
20
|
imageOptimizer?: boolean | ImageOptimizerPluginOptions;
|
|
20
21
|
vinextRouteWiringFix?: boolean | VinextRouteWiringFixPluginOptions;
|
|
21
22
|
autoLocaleParams?: boolean | AutoLocaleParamsPluginOptions;
|
package/dist/src/vite/plugin.js
CHANGED
|
@@ -3,6 +3,7 @@ import { userAgentStubPlugin } from "./user_agent_stub.js";
|
|
|
3
3
|
import { cfWorkersClientStubPlugin } from "./cf_workers_client_stub.js";
|
|
4
4
|
import { bufferStubPlugin } from "./buffer_stub.js";
|
|
5
5
|
import { reactEvalStubPlugin } from "./react_eval_stub.js";
|
|
6
|
+
import { optionalFirebaseStubPlugin } from "./optional_firebase_stub.js";
|
|
6
7
|
import { localeFilePlugin } from "./locale_file_plugin.js";
|
|
7
8
|
import { imageOptimizerPlugin } from "../image_optimizer/index.js";
|
|
8
9
|
import { autoDynamicPagesPlugin } from "./auto_dynamic_pages_plugin.js";
|
|
@@ -62,6 +63,9 @@ export function cloudflareNextIntl(options = {}) {
|
|
|
62
63
|
if (options.reactEvalStub !== false) {
|
|
63
64
|
plugins.push(reactEvalStubPlugin());
|
|
64
65
|
}
|
|
66
|
+
if (options.optionalFirebaseStub !== false) {
|
|
67
|
+
plugins.push(optionalFirebaseStubPlugin({ root: options.root }));
|
|
68
|
+
}
|
|
65
69
|
if (options.cfWorkersClientStub !== false) {
|
|
66
70
|
plugins.push(cfWorkersClientStubPlugin());
|
|
67
71
|
}
|