Skip to content

Commit

Permalink
update file names for sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
pilinux committed Aug 31, 2023
1 parent 65ed793 commit 1506d31
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions app/routes/_index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ export default function Index() {
</a>
</li>
<li>
<Link to="cookie-set">Example: Set Cookie</Link>
<Link to="session-set">Example: Set Session</Link>
</li>
<li>
<Link to="cookie-delete">Example: Delete Cookie</Link>
<Link to="session-delete">Example: Delete Session</Link>
</li>
<li>
<Link to="status">Remote API Status [GET]</Link>
Expand Down
12 changes: 6 additions & 6 deletions app/routes/cookie-delete.jsx → app/routes/session-delete.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// example: how to delete cookie
// example: how to delete session
import { Form, Link } from "@remix-run/react";
import { redirect } from "@remix-run/node";

import { getSession, destroySession } from "~/sessions";
import { getSession, destroySession } from "~/sessions.server";

export const action = async ({ request }) => {
const session = await getSession(request.headers.get("Cookie"));
Expand All @@ -17,24 +17,24 @@ export const action = async ({ request }) => {
console.log(message2);
console.log(message3);

return redirect("/cookie-set", {
return redirect("/session-set", {
headers: {
"Set-Cookie": await destroySession(session),
},
});
};

export default function CookieDeleteRoute() {
export default function SessionDeleteRoute() {
return (
<>
<div className="container-sm">
<div className="row">
<div className="col-sm-4">
<h3>Delete demo cookie?</h3>
<h3>Delete demo session?</h3>
<Form method="post">
<div className="mb-2">
<button type="submit" className="btn btn-danger">
Delete Cookie
Delete Session
</button>
</div>
</Form>
Expand Down
12 changes: 6 additions & 6 deletions app/routes/cookie-set.jsx → app/routes/session-set.jsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// example: how to set cookie
// example: how to set session
import { Form, Link } from "@remix-run/react";
import { redirect } from "@remix-run/node";

import { getSession, commitSession } from "~/sessions";
import { getSession, commitSession } from "~/sessions.server";

export const action = async ({ request }) => {
const session = await getSession(request.headers.get("Cookie"));
session.set("customKey1", "customValue1");
session.set("customKey2", "customValue2");
session.set("customKey3", "customValue3");

return redirect("/cookie-delete", {
return redirect("/session-delete", {
headers: {
"Set-Cookie": await commitSession(session, {
maxAge: 300,
Expand All @@ -19,17 +19,17 @@ export const action = async ({ request }) => {
});
};

export default function CookieSetRoute() {
export default function SessionSetRoute() {
return (
<>
<div className="container-sm">
<div className="row">
<div className="col-sm-4"></div>
<h3>Set demo cookie?</h3>
<h3>Set demo session?</h3>
<Form method="post">
<div className="mb-2">
<button type="submit" className="btn btn-success">
Set Cookie
Set Session
</button>
</div>
</Form>
Expand Down
File renamed without changes.

0 comments on commit 1506d31

Please sign in to comment.