Deploying an app with Cloudflare pages that use the @logto/node/edge client will fail because Buffer is not defined globally. Buffer is used primarily for Base64 encoding/decoding and could be replaced with a platform independent library.
Expected behavior
An alternative to Buffer that works across all edge runtimes would be used with the @logto/node/edge client.
How to reproduce?
Deploy a project using a @logto/node/edge such as @logto/next to Cloudflare pages.
Context
[ x] Logto Cloud
[ ] Self-hosted, Logto version =
[ ] Container (Docker image)
[ ] Raw Node.js
I'm actually using this with Astro instead of Next by adapting the @logto/next. (I can open a PR at some point to contribute an Astro client if that would be desired).
Buffer is used in both node/edge/index.ts and in @silverhand/essentialsurlSafeBase64 (it thinks isNode is true on Cloudflare).
There is a very simple workaround to polyfill Buffer in Cloudflare if node compatibility is enabled:
import {Buffer} from 'node:buffer';
globalThis.Buffer = Buffer;
Ideally, however, Cloudflare users wouldn't have to polyfill or even enable node compatibility.
Describe the bug
Deploying an app with Cloudflare pages that use the
@logto/node/edge
client will fail becauseBuffer
is not defined globally.Buffer
is used primarily forBase64
encoding/decoding and could be replaced with a platform independent library.Expected behavior
An alternative to
Buffer
that works across all edge runtimes would be used with the@logto/node/edge
client.How to reproduce?
Deploy a project using a
@logto/node/edge
such as@logto/next
to Cloudflare pages.Context
I'm actually using this with Astro instead of Next by adapting the @logto/next. (I can open a PR at some point to contribute an Astro client if that would be desired).
Buffer
is used in bothnode/edge/index.ts
and in@silverhand/essentials
urlSafeBase64
(it thinksisNode
is true on Cloudflare).There is a very simple workaround to polyfill
Buffer
in Cloudflare if node compatibility is enabled:Ideally, however, Cloudflare users wouldn't have to polyfill or even enable node compatibility.
Screenshots