Skip to content

Commit 33229c5

Browse files
[cloudflare] Add nextauth infos (#88)
Co-authored-by: Dario Piotrowicz <dario.piotrowicz@gmail.com>
1 parent e68e874 commit 33229c5

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

pages/cloudflare/howtos/NextAuth.mdx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1+
import { Callout } from "nextra/components";
2+
13
## [NextAuth.js](https://next-auth.js.org/)
24

35
NextAuth.js is an open-source authentication solution for Next.js applications.
46

57
### Solving a broken build
68

9+
<Callout>
10+
This section offers a solution for NextAuth.js v4. Use of v5 is currently blocked by the lack of
11+
`createCipheriv` implementation.
12+
</Callout>
13+
714
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).
815

916
`createCipheriv` is not currently implemented by the workerd runtime so apps using NextAuth.js with the default configuration break at build time.
@@ -28,3 +35,18 @@ Kudos to Arnav Gupta ([`@arnavgupta00`](https://github.com/arnavgupta00)) for co
2835
You can find an example of this on his [example repository](https://github.com/arnavgupta00/deployment-cf-workers-prisma-nextauth).
2936

3037
Related issues: [`workers-sdk#206`](https://github.com/opennextjs/opennextjs-cloudflare/issues/206) and [`workerd#3277`](https://github.com/cloudflare/workerd/issues/3277).
38+
39+
### Solving issues in local dev
40+
41+
When trying to access Cloudflare bindings depending on your implementation, you might run into:
42+
43+
`ERROR: getCloudflareContext has been called without having called initOpenNextCloudflareForDev from the Next.js config file.`
44+
45+
You can resolve this issue, by calling `getCloudflareContext` in your `NextAuth` callback, for example like so:
46+
47+
```js
48+
export const { handlers, auth, signIn, signOut } = NextAuth(async _ => {
49+
let { env } = await getCloudflareContext({async: true})
50+
..
51+
}
52+
```

0 commit comments

Comments
 (0)