import { useContext, useState } from 'react'; import { useNavigate } from 'react-router'; import { AuthContext } from '../../utils/auth_context'; import { Paper } from '../common/paper'; import { Input } from '../common/input'; import { Button } from '../common/button'; export const SignIn = () => { const [, setAuthToken] = useContext(AuthContext); const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const navigate = useNavigate(); const goToSignUp = () => { navigate('/signup'); }; const signIn = async () => { const res = await fetch('/sessions', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ email, password, }), }); if (res.status === 201) { const result = await res.json(); setAuthToken(result.token); navigate('/'); } else { console.error('An issue occurred when logging in.'); } }; return (