feat: initial commit.
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
import Header from "../components/Header.tsx";
|
||||
import { define } from "../utils.ts";
|
||||
|
||||
export default define.page(function App({ Component }) {
|
||||
return (
|
||||
<html data-theme="light">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Deno Fresh Dummy</title>
|
||||
</head>
|
||||
<body>
|
||||
<Header />
|
||||
<Component />
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,10 @@
|
||||
import { define } from "../../utils.ts";
|
||||
|
||||
export const handler = define.handlers({
|
||||
GET(ctx) {
|
||||
const name = ctx.params.name;
|
||||
return new Response(
|
||||
`Hello, ${name.charAt(0).toUpperCase() + name.slice(1)}!`,
|
||||
);
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,5 @@
|
||||
import { define } from "../utils.ts";
|
||||
|
||||
export default define.page(function Dashboard(ctx) {
|
||||
return <h1>Dashboard</h1>;
|
||||
});
|
||||
@@ -0,0 +1,33 @@
|
||||
import { useSignal } from "@preact/signals";
|
||||
import { Head } from "fresh/runtime";
|
||||
import Counter from "../islands/Counter.tsx";
|
||||
import { define } from "../utils.ts";
|
||||
|
||||
export default define.page(function Home(ctx) {
|
||||
const count = useSignal(3);
|
||||
|
||||
console.log("Shared value " + ctx.state.shared);
|
||||
|
||||
return (
|
||||
<div class="px-4 py-8 mx-auto fresh-gradient">
|
||||
<Head>
|
||||
<title>Fresh counter</title>
|
||||
</Head>
|
||||
<div class="max-w-3xl mx-auto flex flex-col items-center justify-center">
|
||||
<img
|
||||
class="my-6"
|
||||
src="/logo.svg"
|
||||
width="128"
|
||||
height="128"
|
||||
alt="the Fresh logo: a sliced lemon dripping with juice"
|
||||
/>
|
||||
<h1 class="text-4xl font-bold">Welcome to Fresh</h1>
|
||||
<p class="my-4">
|
||||
Try updating this message in the
|
||||
<code class="mx-2">./routes/index.tsx</code> file, and refresh.
|
||||
</p>
|
||||
<Counter count={count} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,85 @@
|
||||
import { getCookies, setCookie } from "@std/http/cookie";
|
||||
import { z } from "zod";
|
||||
import { backendSignIn } from "../backend/sign-in.ts";
|
||||
import { SignInForm } from "../components/SignInForm.tsx";
|
||||
import { define } from "../utils.ts";
|
||||
|
||||
const loginSchema = z.object({
|
||||
email: z.string(),
|
||||
password: z.string().min(8),
|
||||
});
|
||||
|
||||
export const handler = define.handlers({
|
||||
GET(ctx) {
|
||||
const cookies = getCookies(ctx.req.headers);
|
||||
const authCookie = cookies["auth"];
|
||||
if (authCookie === "ok") {
|
||||
const url = new URL(ctx.req.url);
|
||||
url.pathname = "/dashboard";
|
||||
return Response.redirect(url, 303);
|
||||
}
|
||||
return {
|
||||
data: {
|
||||
email: "",
|
||||
error: undefined,
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
async POST(ctx) {
|
||||
const formData = await ctx.req.formData();
|
||||
const request = loginSchema.safeParse({
|
||||
email: formData.get("email"),
|
||||
password: formData.get("password"),
|
||||
});
|
||||
|
||||
if (!request.success) {
|
||||
return {
|
||||
data: {
|
||||
email: formData.get("email") as string,
|
||||
error: request.error.issues[0].message,
|
||||
},
|
||||
};
|
||||
}
|
||||
const { email, password } = request.data;
|
||||
|
||||
// Super secure authorization method
|
||||
if (!await backendSignIn(email, password)) {
|
||||
return {
|
||||
data: {
|
||||
email,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const url = new URL(ctx.req.url);
|
||||
const headers = new Headers();
|
||||
setCookie(headers, {
|
||||
name: "auth",
|
||||
value: "ok",
|
||||
maxAge: 120,
|
||||
sameSite: "Lax",
|
||||
domain: url.hostname,
|
||||
path: "/",
|
||||
secure: true,
|
||||
});
|
||||
url.pathname = "/dashboard";
|
||||
headers.set("location", url.toString());
|
||||
return new Response(null, {
|
||||
status: 303,
|
||||
headers,
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
export default define.page<typeof handler>(function SignInPage(ctx) {
|
||||
const email = ctx.data.email || "";
|
||||
const error = ctx.data.error;
|
||||
|
||||
return (
|
||||
<div class="container mx-auto p-4 flex flex-col gap-4">
|
||||
<h1>Sign in</h1>
|
||||
<SignInForm email={email} error={error} />
|
||||
</div>
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,5 @@
|
||||
import { define } from "../utils.ts";
|
||||
|
||||
export default define.page(function SignUpPage(ctx) {
|
||||
return <div></div>;
|
||||
});
|
||||
Reference in New Issue
Block a user