Next.js Discord

Discord Forum

Home page dont know about cookie after redirect and cookies().set functio, even i refreshing website

Unanswered
Selkirk Rex posted this in #help-forum
Open in Discord
Selkirk RexOP
Hi,
export async function GET(request: NextRequest) {
  const userId = request.nextUrl.searchParams.get("userId");
  const secret = request.nextUrl.searchParams.get("secret");

  if (!userId || !secret) {
    return NextResponse.json({ error: "Invalid request" }, { status: 400 });
  }

  const { account } = await createAdminClient();
  const session = await account.createSession(userId, secret);

  cookies().set("my-custom-session", session.secret, {
    path: "/",
    httpOnly: true,
    sameSite: "strict",
    secure: true,
  });

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

I am setting cookie and user redirected to home page.
In devlopment tools cookies is added successfuly, but on main page i am checking if i have my-custom-session(using appwrite actually) and then because main page doesnt know this cookie that it got when user redirected to home page, this main page redirect user to sign up page, but also sign up page doesnt know about this cookie. Dunno
when i reassgine "lax" insteaf of strict its working, but dont know if that secure way or anything else.
Otherwise(strict mode) cookie is in sync to home page if i enter url from address bar in browser and press enter.
I dont know if that expected behaviour, i never had problems with this, currently i will keep "lax", if u have any opinion, pls help me

6 Replies

Selkirk RexOP
&752637460550385834
Asian black bear
Don't ping mods for support - we're only here for moderation purposes.
Selkirk RexOP
Then who should i ping
Asian black bear
Nobody.
@Asian black bear Nobody.
Selkirk RexOP
Are u in nextjs team
Oh, u are not, thanks