Next.js Discord

Discord Forum

Next js does not include session cookies (or any cookies for that matter) no matter what :(

Unanswered
Filipino Venus posted this in #help-forum
Open in Discord
Filipino VenusOP
I set cookies from my flask backend and the cookies are being set perfectly. However nonn of the cookkies are being passed to the backend on subsequent fetch requests. I tried:
1. Adding use client .
2.Tried adding credentials inclue.
3.Changing the headers in prefetch and others.

Please help its urgent!!
 "use client";
import { create_basic_resource } from "@/APITypes/call";
export const CreateResourcesAPI = {
  async CreateBasicResource(ResourceData: create_basic_resource): Promise<any> {
    const resourceTagsString = ResourceData.resourceTags.join(",");
    const response = await fetch(process.env.NEXT_PUBLIC_CREATERESOURCES_URL!, {
      method: "POST",
      headers: { "Content-Type": "application/json", credentials: "include" },
      body: JSON.stringify({
        resourceName: ResourceData.resourceName,
        resourceDescription: ResourceData.resourceDescription,
        resourceTags: resourceTagsString,
        visibility: ResourceData.visibility,
        helpEmail: ResourceData.helpEmail,
      }),
    });
    console.log(response.status);
    return response;
  },
};


@app.after_request
def after_request(response):
    allowed_origins = config.ALLOWED_ORIGINS
    origin = flask.request.headers.get("Origin")
    
    if origin in allowed_origins:
        response.headers["Access-Control-Allow-Origin"] = origin
        response.headers["Access-Control-Allow-Credentials"] = "true"
        response.headers["Access-Control-Allow-Methods"] = "POST, GET, OPTIONS, PUT, DELETE"
        response.headers["Access-Control-Allow-Headers"] = "Accept,credentials, Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, Cookie"
        response.headers["Access-Control-Expose-Headers"] = "Set-Cookie"
    
    return response

Please not my main issues is that the cookies are not being sent 😦

0 Replies