From a9aa246f58dcb2664c4e7a1bd98e69c19e7d7000 Mon Sep 17 00:00:00 2001
From: Sam Nystrom <sam@samnystrom.dev>
Date: Tue, 12 Mar 2024 14:52:25 +0000
Subject: Add rudimentary backend and auth

---
 src/pages/LogIn.tsx | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
 create mode 100644 src/pages/LogIn.tsx

(limited to 'src/pages/LogIn.tsx')

diff --git a/src/pages/LogIn.tsx b/src/pages/LogIn.tsx
new file mode 100644
index 0000000..c787dce
--- /dev/null
+++ b/src/pages/LogIn.tsx
@@ -0,0 +1,33 @@
+import { useContext } from 'preact/hooks';
+import { useSignal } from '@preact/signals';
+import { route } from 'preact-router';
+import { Pb } from '../pb.ts';
+
+export const LogIn = () => {
+	const pb = useContext(Pb);
+
+	const email = useSignal('');
+	const password = useSignal('');
+
+	const onSubmit = async (event: SubmitEvent) => {
+		event.preventDefault();
+		const user = await pb.collection('users').authWithPassword(email.value, password.value);
+		if (pb.authStore.isValid) {
+			route('/' + user.username);
+		}
+	};
+
+	return (
+		<form onSubmit={onSubmit}>
+			<label>
+				Email:
+				<input type="text" value={email} onInput={e => email.value = e.target.value} />
+			</label>
+			<label>
+				Password:
+				<input type="password" value={password} onInput={e => password.value = e.target.value} />
+			</label>
+			<button>Log In</button>
+		</form>
+	);
+};
\ No newline at end of file
-- 
cgit v1.2.3

