summaryrefslogtreecommitdiff
path: root/src/pages/LogIn.tsx
blob: 7e83f989e8b368affe2c3aa49bddb3797267654e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { useContext } from 'preact/hooks';
import { useSignal } from '@preact/signals';
import { route } from 'preact-router';
import { Pb } from '../context.ts';
import { TextInput, ArrowButton, FormLabel, Content, Form } from '../components';

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 (
		<Content>
			<Form onSubmit={onSubmit}>
				<h1>Log In</h1>
				<p>
					Don't have an account? <a href="/signup">Sign up</a>
				</p>
				<hr />
				<FormLabel>
					Email
					<TextInput placeholder="Email" signal={email} />
				</FormLabel>
				<FormLabel>
					Password
					<TextInput type="password" placeholder="Email" signal={email} />
				</FormLabel>
				<ArrowButton>Continue</ArrowButton>
			</Form>
		</Content>
	);
};

export default LogIn;