From 134c9904c0760d24e241400ef906ee8ea30a19db Mon Sep 17 00:00:00 2001 From: Dave Smith-Hayes Date: Sun, 3 Mar 2024 21:57:16 -0500 Subject: [PATCH] Start adding some handlers for routes. --- app/src/frontend/components/login-form.tsx | 2 +- app/src/frontend/pages/home.tsx | 9 ++++++ app/src/frontend/pages/login.tsx | 6 ++-- app/src/handlers/login.tsx | 28 +++++++++++++++++++ app/src/index.tsx | 32 +++++----------------- 5 files changed, 48 insertions(+), 29 deletions(-) create mode 100644 app/src/frontend/pages/home.tsx create mode 100644 app/src/handlers/login.tsx diff --git a/app/src/frontend/components/login-form.tsx b/app/src/frontend/components/login-form.tsx index e8dbed8..96f71ae 100644 --- a/app/src/frontend/components/login-form.tsx +++ b/app/src/frontend/components/login-form.tsx @@ -1,6 +1,6 @@ import { FC } from "hono/jsx" -const Error: FC = (props) => { +const Error = (props: { message: string }) => { return (
{props.message} diff --git a/app/src/frontend/pages/home.tsx b/app/src/frontend/pages/home.tsx new file mode 100644 index 0000000..4b07f04 --- /dev/null +++ b/app/src/frontend/pages/home.tsx @@ -0,0 +1,9 @@ +import { Layout } from "../layout"; + +export const HomePage = (props) => { + return ( + +
Welcome to Slovocast
+
+ ); +}; diff --git a/app/src/frontend/pages/login.tsx b/app/src/frontend/pages/login.tsx index d54b7f8..fe8c34f 100644 --- a/app/src/frontend/pages/login.tsx +++ b/app/src/frontend/pages/login.tsx @@ -1,11 +1,11 @@ import { Layout } from '../layout'; +import { LoginForm } from '../components/login-form'; -const LoginPage = (props: { error?: any }) => { +export const LoginPage = (props: { error?: any }) => { return ( - + ); }; -export default LoginPage; diff --git a/app/src/handlers/login.tsx b/app/src/handlers/login.tsx new file mode 100644 index 0000000..291179a --- /dev/null +++ b/app/src/handlers/login.tsx @@ -0,0 +1,28 @@ +import { Hono } from 'hono'; +import { Context } from 'hono'; +import { LoginPage } from '../frontend/pages/login'; + +const LoginHandler = new Hono(); + +LoginHandler.get('/login', async (c: Context) => { + return c.html(); +}); + +LoginHandler.post('/login', async (c: Context) => { + const form = await c.req.formData(); + + // validate form + if (form.has('login')) { + if (form.get('email') == 'me@davesmithhayes.com') { + if (form.get('password') == 'test') { + c.set('auth', true); + return c.redirect('/'); + } + } + } + + c.set('login-errors', {}); + return c.redirect('/login'); +}); + +export default LoginHandler; diff --git a/app/src/index.tsx b/app/src/index.tsx index 8186039..ea8f232 100644 --- a/app/src/index.tsx +++ b/app/src/index.tsx @@ -1,35 +1,17 @@ import { Hono } from 'hono'; -import Layout from './frontend/layout'; -import { SiteConfig, configMiddleware } from './middleware/config'; -import LoginForm from './frontend/user/login'; +import { configMiddleware } from './middleware/config'; +import { HomePage } from './frontend/pages/home'; +import { LoginPage } from './frontend/pages/login'; +import LoginHandler from './handlers/login'; const app = new Hono(); app.use(configMiddleware); app.get('/', async (c) => { - const siteData: SiteConfig = c.get('config'); - - const layout = ( - -
-

Welcome to Slovocast

-
-
- ); - - return c.html(layout); + return c.html(); }); -app.get('/login', async (c) => { - const config: SiteConfig = c.get('config'); - - return c.html( - -
- -
-
- ); -}); +// Handlers +app.route('/*', LoginHandler); export default app;