#Forward HTTP-Only cookie in server action

2 messages · Page 1 of 1 (latest)

jaunty ember
#

Hey there, upon login my server sends an http-only cookie with a jwt token. I'm trying to handle my login form submission with a server action. I can see the Set-Cookie header in the response, but it's not making it's way to the browser. Is there a way to forward the cookie from response?

"use server";

export async function authenticate(formData: FormData) {
  try {
    const res = await fetch("http://localhost:3000/signin", {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        email: formData.get("email"),
        password: formData.get("password"),
      }),
      credentials: "include",
    });

    console.log(res.headers);
  } catch (error) {
    console.error("Invalid credentials.", error);
  }
}

The only thing i see I can do is cookies().set() but that requires me to parse the header manually and reset all the settings, I'm not into it.

It works fine if i submit the form client side so I know the api is working good

sly hearthBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)