jason
jason
Explore posts from servers
CDCloudflare Developers
Created by jason on 4/23/2025 in #pages-help
How to use wasm NPM package (pdfium)
I'm trying to use pdfium, but run into errors: 1. import { PDFiumLibrary } from "@hyzyla/pdfium/browser/base64"; Gets me built and deployed, but runtime error of (error) failed to asynchronously prepare wasm: CompileError: WebAssembly.instantiate(): Wasm code generation disallowed by embedder b/c Cloudflare disallows runtime fetching of wasm (even though the base64 is in my code itself). 2. I tried updating wrangler.jsonc, but this property is not supported in wrangler:
"wasm_modules": {
"pdfium": "node_modules/@hyzyla/pdfium/dist/pdfium.wasm"
},
"wasm_modules": {
"pdfium": "node_modules/@hyzyla/pdfium/dist/pdfium.wasm"
},
3. I've also tried storing the wasm in my public dir and fetching from /pdfium.wasm but that again runs into the same error as attempt 1. 4. Tried vite-plugin-wasm, but get this error:
(error) failed to asynchronously prepare wasm: ReferenceError: XMLHttpRequest is not defined
(error) warning: Loading from a file URI (file:///pdfium.wasm) is not supported in most browsers
(error) failed to asynchronously prepare wasm: ReferenceError: XMLHttpRequest is not defined
(error) warning: Loading from a file URI (file:///pdfium.wasm) is not supported in most browsers
Any ideas?
1 replies
CDCloudflare Developers
Created by jason on 4/8/2025 in #workers-help
Cloudflare Build fails due to `node:process`, but locally `npx wrangler deploy` works.
No description
1 replies
BABetter Auth
Created by jason on 4/2/2025 in #help
Best way to protect routes in TanStack Start?
What's the best way to protect all private routes like /dashboard*, so they redirect to /login if no session exists? I don't see this aspect in the example: https://github.com/better-auth/better-auth/tree/main/examples/tanstack-example Below is my attempt, but session is always null, even if the user is authenticated.
// /routes/(authenticated)/route.tsx -- a layout despite the weird name.
import { createFileRoute, Outlet, redirect } from "@tanstack/react-router";
import { authClient } from "@/lib/auth-client";

export const Route = createFileRoute("/(authenticated)")({
component: AuthenticatedLayout,
beforeLoad: async ({ location }) => {
const { data: session } = await authClient.getSession();

if (!session) {
throw redirect({
to: "/login",
search: {
redirect: location.pathname,
},
});
}

return { session };
},
});

function AuthenticatedLayout() {
return (
<div className="min-h-screen">
<Outlet />
</div>
);
}
// /routes/(authenticated)/route.tsx -- a layout despite the weird name.
import { createFileRoute, Outlet, redirect } from "@tanstack/react-router";
import { authClient } from "@/lib/auth-client";

export const Route = createFileRoute("/(authenticated)")({
component: AuthenticatedLayout,
beforeLoad: async ({ location }) => {
const { data: session } = await authClient.getSession();

if (!session) {
throw redirect({
to: "/login",
search: {
redirect: location.pathname,
},
});
}

return { session };
},
});

function AuthenticatedLayout() {
return (
<div className="min-h-screen">
<Outlet />
</div>
);
}
I'm using authClient.getSession() b/c I believe this needs to work for both SSR and in the client. CC @daveycodez Looking through the msg history, it appears you contributed the TanStack Start example, but I don't see this aspect in the example. Maybe you know?
26 replies
CDCloudflare Developers
Created by jason on 8/9/2024 in #pages-help
`Error: Dynamic require of node:path is not supported` causes runtime error - how to troubleshoot?
No description
8 replies
CDCloudflare Developers
Created by jason on 5/10/2024 in #workers-help
Using `R2 + image transformation API` vs the `Images` service
Are these effectively the same but with a lower storage cost for R2 storage? What are the advantages to using the Images API for storage vs the former?
15 replies
CDCloudflare Developers
Created by jason on 5/9/2024 in #general-help
Sending email via mailchannels on a preview domain
I'd like to send emails via mailchannels on my project's preview url (e.g. foo.pages.dev), to use my site's auth flow. Is this possible? I'm asking because usually Mailchannels requires TXT requires on the domain, which I can't set up on a preview domain. Or is it possible to use an API key with mailchannels instead?
9 replies
CDCloudflare Developers
Created by jason on 2/7/2024 in #pages-help
how to add durable object to Pages project?
No description
6 replies