Last active
June 14, 2023 21:28
-
-
Save NerdPraise/2ef32aef4e34cdcdab642cefa463b046 to your computer and use it in GitHub Desktop.
Login/Login.js form, pretty minimal, no styles, just raw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useNavigate } from 'react-router-dom' | |
import { API } from '../../api' | |
export const Login = () => { | |
const navigate = useNavigate() | |
const onSubmit = (e) => { | |
e.preventDefault() | |
const formData = new FormData(e.target) | |
API.post('auth/login', formData).then((response) => { | |
localStorage.setItem('token', response.data.token) | |
localStorage.setItem('userID', response.data.id) | |
setTimeout(navigate('/private'), 500) | |
}) | |
} | |
return ( | |
<div style={{ padding: '20px' }}> | |
<form onSubmit={onSubmit}> | |
<label htmlFor="username">Username</label> | |
<input type="text" name="username" /> | |
<br /> | |
<label htmlFor="password">Password</label> | |
<input type="password" name="password" /> | |
<br /> | |
<button>Submit </button> | |
</form> | |
</div> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment