hackernews-remix-react icon indicating copy to clipboard operation
hackernews-remix-react copied to clipboard

Deleting Cookies

Open jguepjop opened this issue 3 years ago • 2 comments

Description

I am trying to rebuild the Hacker news web app, without using a database, and store user information (username) in cookies. Using a model similar to yours, I am currently able to add the username to the cookie header, but I am unable to delete. Here is the code for the login page, specifically the action that adds the cookie:

export async function action({ request }) {
  const session = await getSession(request.headers.get("Cookie"));
  const form = await request.formData();
  const username = form.get("name");
  const Password = form.get("password");

  // Login succeeded, send them to the home page.
  return redirect("http://localhost:3000/", {
    headers: {
      "Set-Cookie": username,
    },
  });
}

And here is the logout page:

import { ActionFunction, redirect } from "@remix-run/node";
import { getSession, destroySession } from "~/sessions";

export const loader: ActionFunction = async ({ request }) => {
  const session = await getSession(request.headers.get("Cookie"));
  //await destroySession(session);
  return redirect("/login", {
    headers: { "Set-Cookie": await destroySession(session) },
  });
};

Is there anything that I might be missing?

jguepjop avatar Jun 13 '22 01:06 jguepjop

When you say you can not delete it, have you checked the cookie contents? With mine it destroys the cookie content itself but still leaves the 'shell'

AnthoniG avatar Jun 14 '22 11:06 AnthoniG

For my application I only set the cookie headers, as shown in the code. I essentially want a way to remove it

jguepjop avatar Jun 14 '22 18:06 jguepjop