-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1688797
commit 5a0cca9
Showing
8 changed files
with
94 additions
and
63 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,68 @@ | ||
import React, { useState } from 'react'; | ||
import React, {useState} from 'react'; | ||
import axios from 'axios'; | ||
|
||
function Login() { | ||
const [username, setUsername] = useState(''); | ||
const [password, setPassword] = useState(''); | ||
const [username, setUsername] = useState(''); | ||
const [password, setPassword] = useState(''); | ||
|
||
const handleLogin = async (e) => { | ||
e.preventDefault(); | ||
const res = await axios.post('http://localhost:3001/login', { username, password }); | ||
console.log(res.data); | ||
}; | ||
const handleLogin = async (e) => { | ||
e.preventDefault(); | ||
const res = await axios.post('http://localhost:3001/login', { | ||
username, | ||
password, | ||
}); | ||
console.log(res.data); | ||
}; | ||
|
||
const handleRegister = async (e) => { | ||
e.preventDefault(); | ||
const res = await axios.post('http://localhost:3001/register', { username, password }); | ||
console.log(res.data); | ||
}; | ||
const handleRegister = async (e) => { | ||
e.preventDefault(); | ||
const res = await axios.post('http://localhost:3001/register', { | ||
username, | ||
password, | ||
}); | ||
console.log(res.data); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<form onSubmit={handleLogin}> | ||
<h1>Login</h1> | ||
<input type="text" value={username} onChange={e => setUsername(e.target.value)} placeholder="Username" required /> | ||
<input type="password" value={password} onChange={e => setPassword(e.target.value)} placeholder="Password" required /> | ||
<button type="submit">Login</button> | ||
</form> | ||
<form onSubmit={handleRegister}> | ||
<h1>Register</h1> | ||
<input type="text" value={username} onChange={e => setUsername(e.target.value)} placeholder="Username" required /> | ||
<input type="password" value={password} onChange={e => setPassword(e.target.value)} placeholder="Password" required /> | ||
<button type="submit">Register</button> | ||
</form> | ||
</div> | ||
); | ||
return ( | ||
<div> | ||
<form onSubmit={handleLogin}> | ||
<h1>Login</h1> | ||
<input | ||
type='text' | ||
value={username} | ||
onChange={(e) => setUsername(e.target.value)} | ||
placeholder='Username' | ||
required | ||
/> | ||
<input | ||
type='password' | ||
value={password} | ||
onChange={(e) => setPassword(e.target.value)} | ||
placeholder='Password' | ||
required | ||
/> | ||
<button type='submit'>Login</button> | ||
</form> | ||
<form onSubmit={handleRegister}> | ||
<h1>Register</h1> | ||
<input | ||
type='text' | ||
value={username} | ||
onChange={(e) => setUsername(e.target.value)} | ||
placeholder='Username' | ||
required | ||
/> | ||
<input | ||
type='password' | ||
value={password} | ||
onChange={(e) => setPassword(e.target.value)} | ||
placeholder='Password' | ||
required | ||
/> | ||
<button type='submit'>Register</button> | ||
</form> | ||
</div> | ||
); | ||
} | ||
|
||
export default Login; | ||
export default Login; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
import React from "react"; | ||
import ReactDOM from "react-dom/client"; | ||
import "./index.css"; | ||
import App from "./App"; | ||
import reportWebVitals from "./reportWebVitals"; | ||
import Login from "./Login"; | ||
import { BrowserRouter as Router, Routes, Route } from "react-router-dom"; | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom/client'; | ||
import './index.css'; | ||
import App from './App'; | ||
import reportWebVitals from './reportWebVitals'; | ||
import Login from './Login'; | ||
import {BrowserRouter as Router, Routes, Route} from 'react-router-dom'; | ||
|
||
const root = ReactDOM.createRoot(document.getElementById("root")); | ||
const root = ReactDOM.createRoot(document.getElementById('root')); | ||
root.render( | ||
<React.StrictMode> | ||
<Router> | ||
<Routes> | ||
<Route path="/" element={<App />} /> | ||
<Route path="/login" element={<Login />} /> | ||
<Route path='/' element={<App />} /> | ||
<Route path='/login' element={<Login />} /> | ||
</Routes> | ||
</Router> | ||
</React.StrictMode> | ||
</React.StrictMode>, | ||
); | ||
|
||
// If you want to start measuring performance in your app, pass a function | ||
// to log results (for example: reportWebVitals(console.log)) | ||
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals | ||
reportWebVitals(); | ||
reportWebVitals(); |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ const router = express.Router(); | |
router.use('/users', require('./users')); | ||
|
||
module.exports = router; | ||
// |