NextJS is not including my HttpOnly Cookie provided by .NET Core Webapi

Viewed 244

I'm having a problem where my nextjs application is not passing trough the HttpOnly cookie created by my backend.

In my login mechanism I provide the cookie by the following code. (Backend)

Response.Cookies.Append("jwt", mytoken, new CookieOptions()
            {
                HttpOnly = true
            });

In my NextJS application i'm using redux-toolkit to handle my state. The following code is to login the user.

export const loginUser = createAsyncThunk(
  "auth/login",
  async (login: ILoginProps) => {
    const response = await fetch("https://localhost:5001/api/auth/login", {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
      },
      credentials: "include",
      body: JSON.stringify(login),
    });
    return (await response.json()) as IUser;
  }
);

I got a succesfull 200 and received the HttpOnly cookie.

cookie

But NextJS doesn't manage to "save" the cookie. When I go to the tab cookies in inspection tools none of the cookies are set.

no cookie?

When I do an authorized api in redux-toolkit with Credentials: "Include" the HttpOnly cookie is not sent with the fetch command.

export const getMatches = createAsyncThunk<
  IAuthCall[],
  void,
  { state: RootState }
>("auth/getAuthcall", async (_, thunkApi) => {
  const response = await fetch("https://localhost:5001/api/authcall", {
    method: "GET",
    credentials: "include",
    headers: {
      "Content-Type": "application/json",
    },
  });
  return (await response.json()) as IAuthCall[];
});

401

0 Answers
Related