Skip to content

Commit a305d8d

Browse files
committed
Add HowTo NextAuth on cloudflare
1 parent 511a541 commit a305d8d

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

.github/workflows/check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ jobs:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- name: Checkout
13-
uses: actions/checkout@v3
13+
uses: actions/checkout@v4
1414
- uses: oven-sh/setup-bun@v2
1515
- uses: ./.github/actions/build-docs

pages/cloudflare/_meta.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"get-started": "",
44
"bindings": "",
55
"caching": "",
6+
"howtos": "How-Tos",
67
"examples": "",
78
"community": "Community projects",
89
"troubleshooting": "",
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
## [NextAuth.js](https://next-auth.js.org/)
3+
4+
NextAuth.js is an open-source authentication solution for Next.js applications.
5+
6+
### Solving a broken build
7+
8+
Authentication uses crypto algorithms and 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).
9+
10+
`createCipheriv` is not currently implemented by the workerd runtime so apps using NextAuth.js are broken out of the box.
11+
12+
However you can configure NextAuth.js to use custom implementations for the `encode` and `decode` functions. An implementation built on top of [`SubtleCrypto`](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto) can run on workerd.
13+
14+
The NextAuth.js configuration file should look like:
15+
16+
```js
17+
import { encode, decode } from "@/lib/webcrypto";
18+
19+
export const NEXT_AUTH_CONFIG = {
20+
// ...
21+
jwt: {
22+
encode,
23+
decode,
24+
},
25+
};
26+
```
27+
28+
Kudos to Arnav Gupta ([`@arnavgupta00`](https://github.com/arnavgupta00)) for coming up with the solution.
29+
You can find an example on his [example repository](https://github.com/arnavgupta00/deployment-cf-workers-prisma-nextauth).
30+
31+
Related issues: [`workers-sdk#206`](https://github.com/opennextjs/opennextjs-cloudflare/issues/206) and [`workerd#3277`](https://github.com/cloudflare/workerd/issues/3277).
32+
33+
34+
35+
36+
37+

0 commit comments

Comments
 (0)