Skip to content

📚 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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export async function createSessionClient() {
.setEndpoint(process.env.NEXT_PUBLIC_APPWRITE_ENDPOINT)
.setProject(process.env.NEXT_PUBLIC_APPWRITE_PROJECT);

const session = await cookies().get("my-custom-session");
const session = (await cookies()).get("my-custom-session");
if (!session || !session.value) {
throw new Error("No session");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ async function signUpWithEmail(formData) {
await account.create(ID.unique(), email, password, name);
const session = await account.createEmailPasswordSession(email, password);

cookies().set("my-custom-session", session.secret, {
(await cookies()).set("my-custom-session", session.secret, {
path: "/",
httpOnly: true,
sameSite: "strict",
Expand All @@ -85,4 +85,4 @@ async function signUpWithEmail(formData) {
// the SignUpPage component ...
```

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 set the session secret in a cookie and redirect the user to the account page.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async function signOut() {

const { account } = await createSessionClient();

cookies().delete("my-custom-session");
(await cookies()).delete("my-custom-session");
await account.deleteSession("current");

redirect("/signup");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { OAuthProvider } from "node-appwrite";
export async function signUpWithGithub() {
const { account } = await createAdminClient();

const origin = headers().get("origin");
const origin = (await headers()).get("origin");

const redirectUrl = await account.createOAuth2Token(
OAuthProvider.Github,
Expand Down Expand Up @@ -85,7 +85,7 @@ export async function GET(request) {
const { account } = await createAdminClient();
const session = await account.createSession(userId, secret);

cookies().set("my-custom-session", session.secret, {
(await cookies()).set("my-custom-session", session.secret, {
path: "/",
httpOnly: true,
sameSite: "strict",
Expand All @@ -94,4 +94,4 @@ export async function GET(request) {

return NextResponse.redirect(`${request.nextUrl.origin}/account`);
}
```
```
Loading