26 lines
556 B
TypeScript
26 lines
556 B
TypeScript
import type {
|
|
LoaderFunctionArgs,
|
|
} from "@remix-run/node";
|
|
import { redirect } from "@remix-run/node";
|
|
|
|
import { getSession, destroySession } from "~/auth/session";
|
|
|
|
export async function loader({
|
|
request,
|
|
}: LoaderFunctionArgs) {
|
|
const session = await getSession(
|
|
request.headers.get("Cookie")
|
|
);
|
|
|
|
if (session.has("user_id")) {
|
|
// Logout
|
|
return redirect("/login", {
|
|
headers: {
|
|
"Set-Cookie": await destroySession(session),
|
|
},
|
|
});
|
|
}
|
|
|
|
return redirect("/");
|
|
}
|
|
|