diff options
author | Biswakalyan Bhuyan <biswa@surgot.in> | 2024-07-18 14:56:39 +0530 |
---|---|---|
committer | Biswakalyan Bhuyan <biswa@surgot.in> | 2024-07-18 14:56:39 +0530 |
commit | 2f613682b733f8f03634df08270469830cad1800 (patch) | |
tree | bab1e0c7b19aa9538bbcb099d7e5b36c1f264528 /src/components | |
parent | 05faaf231620ce8d4ee67585bd86f1e97fd32eeb (diff) | |
download | admin-panel-2f613682b733f8f03634df08270469830cad1800.tar.gz admin-panel-2f613682b733f8f03634df08270469830cad1800.tar.bz2 admin-panel-2f613682b733f8f03634df08270469830cad1800.zip |
added the config and setup the basic auth
Diffstat (limited to 'src/components')
-rw-r--r-- | src/components/Login.js | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/components/Login.js b/src/components/Login.js new file mode 100644 index 0000000..9a67051 --- /dev/null +++ b/src/components/Login.js @@ -0,0 +1,34 @@ +import React, { useState } from 'react'; +import axios from 'axios'; + +const Login = ({ setAuth }) => { + const [formData, setFormData] = useState({ + username: '', + password: '', + }); + + const { username, password } = formData; + + const onChange = (e) => setFormData({ ...formData, [e.target.name]: e.target.value }); + + const onSubmit = async (e) => { + e.preventDefault(); + try { + const res = await axios.post('/api/auth/login', formData); + localStorage.setItem('token', res.data.token); + setAuth(true); + } catch (err) { + console.error(err.response.data); + } + }; + + return ( + <form onSubmit={onSubmit}> + <input type="text" name="username" value={username} onChange={onChange} required /> + <input type="password" name="password" value={password} onChange={onChange} required /> + <button type="submit">Login</button> + </form> + ); +}; + +export default Login; |