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

Deleting Cookies #6

Open
jguepjop opened this issue Jun 13, 2022 · 2 comments
Open

Deleting Cookies #6

jguepjop opened this issue Jun 13, 2022 · 2 comments

Comments

@jguepjop
Copy link

jguepjop commented Jun 13, 2022

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
Copy link

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants