From b4afb1baf5076125052dcb15bf4d657371f1f4e2 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Fri, 2 May 2025 16:05:17 +0200 Subject: [PATCH] docs(cloudflare): remove outdated NextAuth howto --- pages/cloudflare/howtos/NextAuth.mdx | 57 ---------------------------- pages/cloudflare/howtos/_meta.json | 1 - 2 files changed, 58 deletions(-) delete mode 100644 pages/cloudflare/howtos/NextAuth.mdx diff --git a/pages/cloudflare/howtos/NextAuth.mdx b/pages/cloudflare/howtos/NextAuth.mdx deleted file mode 100644 index 3882eb5..0000000 --- a/pages/cloudflare/howtos/NextAuth.mdx +++ /dev/null @@ -1,57 +0,0 @@ -import { Callout } from "nextra/components"; - -## [NextAuth.js](https://next-auth.js.org/) - - - Starting from wrangler 4.4.0, the implementation of `createCipheriv` is available and NextAuth.js should - work out of the box. - - -NextAuth.js is an open-source authentication solution for Next.js applications. - -### Solving a broken build - - - This section offers a solution for NextAuth.js v4. Use of v5 is currently blocked by the lack of - `createCipheriv` implementation. - - -NextAuth.js relies on [`createCipheriv`](https://nodejs.org/docs/v22.13.1/api/crypto.html#cryptocreatecipherivalgorithm-key-iv-options) from [`node:crypto`](https://nodejs.org/docs/v22.13.1/api/crypto.html). - -`createCipheriv` is not currently implemented by the workerd runtime so apps using NextAuth.js with the default configuration break at build time. - -However you can configure NextAuth.js to use custom implementations of the `encode` and `decode` functions that do not use the unimplemented Node APIs. Implementations built on top of [`SubtleCrypto`](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto) can run on workerd. - -The NextAuth.js configuration file should look like: - -```js -import { encode, decode } from "@/lib/webcrypto"; - -export const NEXT_AUTH_CONFIG = { - // ... - jwt: { - encode, - decode, - }, -}; -``` - -Kudos to Arnav Gupta ([`@arnavgupta00`](https://github.com/arnavgupta00)) for coming up with the solution. -You can find an example of this on his [example repository](https://github.com/arnavgupta00/deployment-cf-workers-prisma-nextauth). - -Related issues: [`workers-sdk#206`](https://github.com/opennextjs/opennextjs-cloudflare/issues/206) and [`workerd#3277`](https://github.com/cloudflare/workerd/issues/3277). - -### Solving issues in local dev - -When trying to access Cloudflare bindings depending on your implementation, you might run into: - -`ERROR: getCloudflareContext has been called without having called initOpenNextCloudflareForDev from the Next.js config file.` - -You can resolve this issue, by calling `getCloudflareContext` in your `NextAuth` callback, for example like so: - -```js -export const { handlers, auth, signIn, signOut } = NextAuth(async _ => { - let { env } = await getCloudflareContext({async: true}) - .. -} -``` diff --git a/pages/cloudflare/howtos/_meta.json b/pages/cloudflare/howtos/_meta.json index 2c781b5..401af5b 100644 --- a/pages/cloudflare/howtos/_meta.json +++ b/pages/cloudflare/howtos/_meta.json @@ -1,5 +1,4 @@ { - "NextAuth": "NextAuth", "stripeAPI": "Stripe API", "dev-deploy": "Develop and Deploy", "env-vars": "Environment Variables",