-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathLogin.tsx
More file actions
41 lines (40 loc) · 1 KB
/
Login.tsx
File metadata and controls
41 lines (40 loc) · 1 KB
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
import React from 'react';
import { useForm } from '../hooks/useForm';
import { LoginCredentials, useAuth } from '../lib/auth';
export function Login() {
const { login } = useAuth();
const { values, onChange } = useForm<LoginCredentials>();
const [error, setError] = React.useState(null);
return (
<div>
Login
<form
onSubmit={async e => {
e.preventDefault();
try {
await login(values as LoginCredentials);
} catch (err) {
setError(err);
}
}}
>
<input
autoComplete="new-password"
placeholder="email"
name="email"
onChange={onChange}
/>
<input
type="password"
placeholder="password"
name="password"
onChange={onChange}
/>
<button type="submit">Submit</button>
</form>
{error && (
<div style={{ color: 'tomato' }}>{JSON.stringify(error, null, 2)}</div>
)}
</div>
);
}