clintonwoo / hackernews-remix-react

Hacker News clone written with universal TypeScript, using React and Remix.
https://remix.hnclone.win
MIT License
487 stars 36 forks source link

Deleting Cookies #6

Open jguepjop opened 2 years ago

jguepjop commented 2 years ago

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?

AnthoniG commented 2 years ago

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'

jguepjop commented 2 years ago

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