Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃 [Question]: can't se my cookie in the browser #2961

Closed
3 tasks done
kronborg6 opened this issue Apr 11, 2024 · 1 comment
Closed
3 tasks done

馃 [Question]: can't se my cookie in the browser #2961

kronborg6 opened this issue Apr 11, 2024 · 1 comment

Comments

@kronborg6
Copy link

kronborg6 commented Apr 11, 2024

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.
Copy link

welcome bot commented Apr 11, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant