You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
+
exportconstNEXT_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).
0 commit comments