-
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
Showing
9 changed files
with
217 additions
and
276 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import React, { useState } from 'react'; | ||
import './auth.css'; | ||
import Login from './Login'; | ||
import Register from './Register'; | ||
|
||
const FlipCard = () => { | ||
const [isFlipped, setIsFlipped] = useState(false); | ||
|
||
const handleFlip = () => { | ||
setIsFlipped(!isFlipped); | ||
}; | ||
|
||
return ( | ||
<div className="flip-card-container"> | ||
<div className={`flip-card ${isFlipped ? 'flipped' : ''}`}> | ||
<div className="flip-card-front"> | ||
<h2>Login</h2> | ||
<Login /> | ||
<p className="toggle-link" onClick={handleFlip}> | ||
Don't have an account? Register here | ||
</p> | ||
</div> | ||
<div className="flip-card-back"> | ||
<h2>Register</h2> | ||
<Register /> | ||
<p className="toggle-link" onClick={handleFlip}> | ||
Already have an account? Login here | ||
</p> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default FlipCard; |
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,44 +1,46 @@ | ||
import React, { useState } from 'react'; | ||
import axios from 'axios'; | ||
import { useAuth } from './AuthContext'; | ||
|
||
const Login = ({ onClose }) => { | ||
const Login = () => { | ||
const [username, setUsername] = useState(''); | ||
const [password, setPassword] = useState(''); | ||
const { login } = useAuth(); | ||
|
||
const handleSubmit = async (e) => { | ||
e.preventDefault(); | ||
try { | ||
const response = await axios.post('/auth/login', { username, password }); | ||
localStorage.setItem('token', response.data.token); | ||
login({ username }); | ||
onClose(); | ||
// handle login success | ||
} catch (error) { | ||
console.error('Login Error:', error.response ? error.response.data : error.message); | ||
} | ||
}; | ||
|
||
return (<div> | ||
<form onSubmit={handleSubmit}> | ||
<input | ||
type="text" | ||
placeholder="Username" | ||
value={username} | ||
onChange={(e) => setUsername(e.target.value)} | ||
required | ||
/> | ||
<input | ||
type="password" | ||
placeholder="Password" | ||
value={password} | ||
onChange={(e) => setPassword(e.target.value)} | ||
required | ||
/> | ||
<button type="submit">Login</button> | ||
return ( | ||
<form className="auth-form" onSubmit={handleSubmit} > | ||
<div className="input-container"> | ||
<input | ||
type="text" | ||
value={username} | ||
onChange={(e) => setUsername(e.target.value)} | ||
required | ||
className="input-field" | ||
/> | ||
<label className="form-label">Username</label> | ||
</div> | ||
<div className="input-container"> | ||
<input | ||
type="password" | ||
value={password} | ||
onChange={(e) => setPassword(e.target.value)} | ||
required | ||
className="input-field" | ||
/> | ||
<label className="form-label">Password</label> | ||
</div> | ||
<button type="submit" className="submit-button">Login</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
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.