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
Update fullstack authentication tutorial for Next.js and Cloudflare D1
- Clarified instructions for modifying `tsconfig.json` and `cloudflare-env.d.ts`.
- Added note about wrangler creating the worker if not deployed.
- Improved error handling in the GET function.
- Updated file references for clarity and consistency.
Copy file name to clipboardExpand all lines: src/content/docs/developer-spotlight/tutorials/fullstack-authentication-with-next-js-and-cloudflare-d1.mdx
+17-13Lines changed: 17 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -60,7 +60,7 @@ From within the repository or directory where you want to create your project ru
60
60
61
61
This will create a new Next.js project using [OpenNext](https://opennext.js.org/cloudflare) that will run in a Worker using [Workers Static Assets](/workers/frameworks/framework-guides/nextjs/#static-assets).
62
62
63
-
Before we get started, open your project's `tsconfig.json` file and add the following to the `compilerOptions` object to allow for top level await needed to let our application get the Cloudflare context:
63
+
Before we get started, open your project's `tsconfig.json` file and modify the following to the `compilerOptions` object to allow for top level await needed to let our application get the Cloudflare context:
64
64
65
65
```json title="tsconfig.json"
66
66
{
@@ -101,6 +101,8 @@ Now, deviating from the standard Auth.js setup, locate your generated secret (li
101
101
npx wrangler secret put AUTH_SECRET
102
102
```
103
103
104
+
If you have not deployed yet that's fine. Allow wrangler to create the worker for you.
105
+
104
106
After adding the secret, update your `.dev.vars` file to include an `AUTH_SECRET` value (this secret should be different from the one you generated earlier for security purposes):
105
107
106
108
```sh title=".dev.vars"
@@ -109,9 +111,9 @@ AUTH_SECRET = "<replace-me>"
109
111
# ...
110
112
```
111
113
112
-
Next, go into the newly generated `env.d.ts` file and add the following to the <Typetext="CloudflareEnv" /> interface:
114
+
Next, go into `cloudflare-env.d.ts` file and add the following to the <Typetext="CloudflareEnv" /> interface:
Now, within the `src/` directory, create a `middleware.ts` file to persist session data containing the following:
239
+
Now, within the `src/` directory, create a `middleware.ts` file. If you do not have a `src/` directory, create a `middleware.ts` file in the root of your project. This will persist session data.
238
240
239
241
<TypeScriptExamplefilename="src/middleware.ts">
240
242
```ts
@@ -248,15 +250,17 @@ The D1 adapter requires that tables be created within your database. It [recomme
0 commit comments