-
Notifications
You must be signed in to change notification settings - Fork 296
📚 Documentation: Adding await to cookies() and headers() to align with Next.js 15 async API changes in Server-side authentication with Next.js tutorial
#1858
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
… 15 async API changes
Refactor: Add `await` to `cookies()` in step-5 to comply with Next.js 15 async API changes
Refactor: add 'await' to 'cookies()' call
Refactor: add 'await' to 'cookies()' call
Refactor: add 'await' to 'cookies()' and `headers()` call
|
The preview deployment failed. 🔴 Last updated at: 2025-07-02 19:37:01 CET |
appwrite.ioProject ID: Tip You can use Avatars API to generate QR code for any text or URLs. |
6e3c6b4 to
83e3ebc
Compare
WalkthroughThis pull request updates tutorial examples for Next.js SSR authentication by changing direct calls to Next.js runtime APIs into awaited invocations: replacing Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/routes/docs/tutorials/nextjs-ssr-auth/step-5/+page.markdoc (1)
96-96: Consider adding explicit mention of awaiting cookies().The description accurately summarizes the function but could optionally mention that
cookies()must be awaited in Next.js 15. This would provide additional clarity for developers following the tutorial.Example enhancement:
-The `signUpWithEmail` function is an async function that takes the form data as an argument. It uses the `createAdminClient` function to create an admin Appwrite client and then calls the `createEmailPasswordSession` method on the `account` object. This method takes the email and password as arguments and returns a session object. We then set the session secret in a cookie and redirect the user to the account page. +The `signUpWithEmail` function is an async function that takes the form data as an argument. It uses the `createAdminClient` function to create an admin Appwrite client and then calls the `createEmailPasswordSession` method on the `account` object. This method takes the email and password as arguments and returns a session object. We then await the `cookies()` function (required in Next.js 15) to set the session secret in a secure cookie and redirect the user to the account page.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
src/routes/docs/tutorials/nextjs-ssr-auth/step-3/+page.markdoc(1 hunks)src/routes/docs/tutorials/nextjs-ssr-auth/step-5/+page.markdoc(2 hunks)src/routes/docs/tutorials/nextjs-ssr-auth/step-6/+page.markdoc(1 hunks)src/routes/docs/tutorials/nextjs-ssr-auth/step-7/+page.markdoc(3 hunks)
🧰 Additional context used
🧠 Learnings (3)
📚 Learning: 2025-09-25T05:24:12.551Z
Learnt from: BretRen
Repo: appwrite/website PR: 2442
File: src/routes/docs/products/auth/email-password/+page.markdoc:50-56
Timestamp: 2025-09-25T05:24:12.551Z
Learning: Appwrite v17+ uses object parameters consistently across Account methods. Both account.create({ userId, email, password }) and account.createEmailPasswordSession({ email, password }) use object parameters instead of positional arguments.
Applied to files:
src/routes/docs/tutorials/nextjs-ssr-auth/step-3/+page.markdoc
📚 Learning: 2025-09-25T05:24:12.551Z
Learnt from: BretRen
Repo: appwrite/website PR: 2442
File: src/routes/docs/products/auth/email-password/+page.markdoc:50-56
Timestamp: 2025-09-25T05:24:12.551Z
Learning: Appwrite v17+ uses object parameters for Account methods including createEmailPasswordSession({ email, password }) instead of positional arguments. This is consistent across the Account API methods like account.create({ userId, email, password }).
Applied to files:
src/routes/docs/tutorials/nextjs-ssr-auth/step-3/+page.markdoc
📚 Learning: 2025-09-25T05:24:12.551Z
Learnt from: BretRen
Repo: appwrite/website PR: 2442
File: src/routes/docs/products/auth/email-password/+page.markdoc:50-56
Timestamp: 2025-09-25T05:24:12.551Z
Learning: The Appwrite `createEmailPasswordSession` method uses object parameters `{ email, password }` instead of positional arguments. This is consistent with other Account methods in Appwrite that also use object parameters.
Applied to files:
src/routes/docs/tutorials/nextjs-ssr-auth/step-5/+page.markdoc
🔇 Additional comments (6)
src/routes/docs/tutorials/nextjs-ssr-auth/step-3/+page.markdoc (1)
23-23: LGTM! Correctly aligns with Next.js 15 async API.The change properly awaits
cookies()before calling.get(), which is necessary because Next.js 15 made these helper functions asynchronous. The parentheses ensure the Promise is resolved before accessing the cookie store methods.src/routes/docs/tutorials/nextjs-ssr-auth/step-6/+page.markdoc (1)
25-27: LGTM! Correct implementation of Next.js 15 async cookies() API.The change properly demonstrates awaiting the
cookies()function before calling methods on the cookie store, which aligns with Next.js 15's async API requirements.src/routes/docs/tutorials/nextjs-ssr-auth/step-5/+page.markdoc (1)
83-88: LGTM! Async cookies() correctly implemented with bonus security improvement.The
awaitsyntax forcookies()correctly aligns with Next.js 15's async API changes. The parentheses aroundawait cookies()are necessary to resolve the promise before calling.set().Additionally, the addition of
secure: trueon line 87 is a valuable security enhancement ensuring cookies are only transmitted over HTTPS. Note that this security improvement goes beyond the stated PR objectives and may warrant mention in the PR description.src/routes/docs/tutorials/nextjs-ssr-auth/step-7/+page.markdoc (3)
30-30: LGTM! Correct async usage for Next.js 15.The
awaitforheaders()is correctly applied, and the syntax(await headers()).get("origin")properly reflects Next.js 15's async API changes.
91-96: LGTM! Correct async usage for Next.js 15.The
awaitforcookies()is properly applied with correct syntax(await cookies()).set(...). The cookie configuration also appropriately includessecure: true,httpOnly: true, andsameSite: "strict"for security best practices.
1-100: Code is consistent across all tutorial steps - no changes needed.Verification confirms that
cookies()andheaders()calls are consistently awaited throughout the entirenextjs-ssr-authtutorial series (steps 3, 5, 6, and 7). All instances follow the proper async pattern, so users following the tutorial sequentially will see uniform patterns with no confusion.
Updated the explanation of the `signUpWithEmail` function to include the use of the `cookies()` function in Next.js 15 for setting the session secret.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/routes/docs/tutorials/nextjs-ssr-auth/step-5/+page.markdoc (1)
83-88: Consider documenting secure cookie behavior for different development environments.The async/await pattern
(await cookies()).set(...)is correct for Next.js 15. Thesecure: trueflag is a standard cookie option and appropriate for production security. However, setting it unconditionally can prevent cookies from working in development environments that aren't localhost (e.g., network IPs, custom domains). The tutorial text already mentions "secure cookie" but doesn't explain this caveat.Consider clarifying that developers should either:
- Use conditional logic:
secure: process.env.NODE_ENV === 'production'- Run development over HTTPS (mkcert or similar)
- Note that localhost correctly handles Secure cookies during development
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/routes/docs/tutorials/nextjs-ssr-auth/step-5/+page.markdoc
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-09-25T05:24:12.551Z
Learnt from: BretRen
Repo: appwrite/website PR: 2442
File: src/routes/docs/products/auth/email-password/+page.markdoc:50-56
Timestamp: 2025-09-25T05:24:12.551Z
Learning: The Appwrite `createEmailPasswordSession` method uses object parameters `{ email, password }` instead of positional arguments. This is consistent with other Account methods in Appwrite that also use object parameters.
Applied to files:
src/routes/docs/tutorials/nextjs-ssr-auth/step-5/+page.markdoc
📚 Learning: 2025-09-25T05:24:12.551Z
Learnt from: BretRen
Repo: appwrite/website PR: 2442
File: src/routes/docs/products/auth/email-password/+page.markdoc:50-56
Timestamp: 2025-09-25T05:24:12.551Z
Learning: Appwrite v17+ uses object parameters for Account methods including createEmailPasswordSession({ email, password }) instead of positional arguments. This is consistent across the Account API methods like account.create({ userId, email, password }).
Applied to files:
src/routes/docs/tutorials/nextjs-ssr-auth/step-5/+page.markdoc
🔇 Additional comments (1)
src/routes/docs/tutorials/nextjs-ssr-auth/step-5/+page.markdoc (1)
96-96: LGTM! Clear documentation of the Next.js 15 requirement.The updated explanation clearly states that awaiting
cookies()is required in Next.js 15 and mentions the secure cookie setting, which helps developers understand the changes.

What does this PR do?
Updates code examples in documentation to reflect Next.js 15 changes, specifically adding
awaittocookies()andheaders()calls. Since these functions are now asynchronous in Next.js 15, the examples have been updated to provide updated and accurate guidance to developers.Test Plan
.markdocdocumentation files in this tutorial.Related PRs and Issues
Have you read the Contributing Guidelines on issues?
Yes
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.