ls-deno/routes/logout.tsx

37 lines
928 B
TypeScript
Raw Normal View History

2022-10-08 02:01:48 -05:00
import { Handlers } from "$fresh/server.ts";
2022-10-12 03:31:26 -05:00
import { deleteCookie, getCookies } from "$std/http/cookie.ts";
import { deleteToken } from "@/db/mod.ts";
2022-10-08 02:01:48 -05:00
export const handler: Handlers<unknown> = {
2022-10-12 03:31:26 -05:00
async GET(request: Request, context) {
const { lsauth } = getCookies(request.headers);
if (lsauth) {
console.log("deleteToken:", await deleteToken(lsauth));
}
const newUrl = new URL(request.url);
newUrl.pathname = "/login";
2022-10-08 02:01:48 -05:00
const response = await context.render();
const headers = new Headers(response.headers);
deleteCookie(headers, "lsauth");
headers.set("location", newUrl.toString());
const actualResponse = new Response(response.body, {
...response,
headers: headers,
status: 302,
});
return actualResponse;
2022-10-08 02:01:48 -05:00
},
};
export default function LoggedOut() {
return (
2022-10-11 23:49:36 -05:00
<p>
If you were logged in before, we've logged you out.
</p>
2022-10-08 02:01:48 -05:00
);
}