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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set cookies #382

Open
1 task
MickL opened this issue Apr 8, 2024 · 8 comments
Open
1 task

Set cookies #382

MickL opened this issue Apr 8, 2024 · 8 comments

Comments

@MickL
Copy link

MickL commented Apr 8, 2024

Describe the feature

I have a login route that returns a session cookie but when sending subsequents requests the cookie is not set:

const loginResponse = await ofetch.raw('/login', {
      method: 'POST',
      body: {
        email: '[email protected]',
        password: 'test123',
      },
    });
expect(loginResponse.status).toBe(204);

const securedRouteResponse = await ofetch.raw('/admin/products');
expect(securedRouteResponse).toBe(200); // -> 403

Unfortunately the cookie is never set. I tried to set option credentials: 'include' on both requests with no success. Am I missing something?

Additional information

  • Would you be willing to help implement this feature?
@87xie
Copy link

87xie commented Apr 9, 2024

Checking the Set-Cookie attributes, such as Path, Domain, Expires, etc, in the server response headers of the /login endpoint to ensure the cookie is stored correctly

@MickL
Copy link
Author

MickL commented Apr 9, 2024

Yes it works fine in browser and in Postman

@duy-dev
Copy link

duy-dev commented Apr 23, 2024

I also have the same problem, the application runs fine locally but when deployed to Firebase it cannot get cookies 😥

@sonicjhon1
Copy link

Try with

const loginResponse = await ofetch.raw('/login', {
      method: 'POST',
      body: {
        email: '[email protected]',
        password: 'test123',
      },
      credentials: "include",
});

@MickL
Copy link
Author

MickL commented Apr 26, 2024

You mean credentials: include? Thats what I tried as I wrote in the initial issue

@sonicjhon1
Copy link

sonicjhon1 commented Apr 26, 2024

You mean credentials: include? Thats what I tried as I wrote in the initial issue

Yeah my bad, did you try it with access-control-allow-credentials header set to true in the server?

@MickL
Copy link
Author

MickL commented Apr 26, 2024

It works in the browser and with Postman, just not in the test or an empty node script with ofetch.

@pratik149
Copy link

pratik149 commented Jun 5, 2024

Facing the same issue, runs fine locally but not in production. Did anyone figure this out? :(

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

6 participants