30 lines
702 B
TypeScript
30 lines
702 B
TypeScript
import { Handlers, PageProps } from "$fresh/server.ts";
|
|
import { getCookies } from "$std/http/cookie.ts";
|
|
import { sessions } from "../api/auth.middleware.ts";
|
|
|
|
export const handler: Handlers = {
|
|
async GET(req, ctx) {
|
|
const cookies = getCookies(req.headers);
|
|
const sessionId = cookies.session;
|
|
|
|
// Check if session exists and is valid
|
|
if (!sessionId || !sessions.has(sessionId)) {
|
|
return new Response("", {
|
|
status: 307,
|
|
headers: { Location: "/login" },
|
|
});
|
|
}
|
|
|
|
return ctx.render();
|
|
},
|
|
};
|
|
|
|
export default function Home() {
|
|
return (
|
|
<div id="mcrates">
|
|
<h1>Welcome to crates</h1>
|
|
<p>You are logged in!</p>
|
|
</div>
|
|
);
|
|
}
|