gofiber / fiber

⚡️ Express inspired web framework written in Go

Home Page:https://gofiber.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

🤗 [Question]: can't se my cookie in the browser

kronborg6 opened this issue · comments

Question Description

i have a gofiber v3 api and a nextjs app
api: localhost:8000 via docker
nextjs: localhost:3000 not via docker

it does work in postman and if i just go to the api url but not when i do a fetch in nextjs

Code Snippet (optional)

func (con *AuthController) Test(c fiber.Ctx) error {
	cookie := new(fiber.Cookie)
	cookie.Name = "kronborg"
	cookie.SameSite = "None"
	cookie.Value = "king"
	cookie.Secure = false
	cookie.Expires = time.Now().Add(5 * time.Minute)

	c.Cookie(cookie)
	return c.JSON(fiber.Map{
		"message": "cookie is set yes>?",
	})
}
	app.Use(cors.New(cors.Config{
		AllowOrigins:     "http://localhost:3000, http://localhost:8000",
		AllowCredentials: true,
	}))

and my nextjs fetch and response

async function testCookie(): Promise<any> {
  const res = await fetch("http://localhost:8000/auth", {
    credentials: "include", // Include cookies in the request
  });
  if (!res.ok) {
    console.log("gg");
    return null;
  }
  console.log(res);
  const data = await res.json();
  return data;
}
Response {
  [Symbol(realm)]: { settingsObject: {} },
  [Symbol(state)]: {
    aborted: false,
    rangeRequested: false,
    timingAllowPassed: false,
    requestIncludesCredentials: false,
    type: 'default',
    status: 200,
    timingInfo: null,
    cacheState: '',
    statusText: '',
    headersList: HeadersList {
      cookies: [Array],
      [Symbol(headers map)]: [Map],
      [Symbol(headers map sorted)]: null
    },
    urlList: [],
    body: { stream: undefined, source: [Uint8Array], length: 38 }
  },
  [Symbol(headers)]: HeadersList {
    cookies: [
      'kronborg=king; expires=Thu, 11 Apr 2024 22:04:23 GMT; path=/; secure; SameSite=None'
    ],
    [Symbol(headers map)]: Map(7) {
      'access-control-allow-credentials' => [Object],
      'access-control-allow-origin' => [Object],
      'content-length' => [Object],
      'content-type' => [Object],
      'date' => [Object],
      'set-cookie' => [Object],
      'vary' => [Object]
    },
    [Symbol(headers map sorted)]: null
  }
}
{ message: 'cookie is set yes>?' }

Checklist:

  • I agree to follow Fiber's Code of Conduct.
  • I have checked for existing issues that describe my questions prior to opening this one.
  • I understand that improperly formatted questions may be closed without explanation.

Thanks for opening your first issue here! 🎉 Be sure to follow the issue template! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord