-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from JonasSchweigler/feature/auth-pages
Feature/auth pages
- Loading branch information
Showing
12 changed files
with
326 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import { useState } from "react"; | ||
import apiClient from "../../libs/api.client"; | ||
import { toast } from "react-toastify"; | ||
import { Link } from "react-router-dom"; | ||
|
||
export const LoginCard = () => { | ||
const [email, setEmail] = useState(""); | ||
const [password, setPassword] = useState(""); | ||
|
||
let token = localStorage.getItem("token"); | ||
|
||
const handleSubmit = (event) => { | ||
event.preventDefault(); | ||
|
||
apiClient | ||
.post( | ||
"/user/login", | ||
{ | ||
email, | ||
password, | ||
}, | ||
{ | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
} | ||
) | ||
.then((response) => { | ||
if (response.data.message === "Login successful") { | ||
token = response.data.token; | ||
localStorage.setItem("token", token); | ||
toast.success("Login Successful!", { | ||
position: "bottom-right", | ||
autoClose: 3000, | ||
hideProgressBar: true, | ||
closeOnClick: true, | ||
draggable: true, | ||
}); | ||
setTimeout(() => { | ||
window.location.href = "/app"; | ||
}, 3000); | ||
} else { | ||
toast.error("Login Failed!", { | ||
position: "bottom-right", | ||
autoClose: 3000, | ||
hideProgressBar: true, | ||
closeOnClick: true, | ||
draggable: true, | ||
}); | ||
} | ||
}) | ||
.catch(() => { | ||
toast.error("Login Failed!", { | ||
position: "bottom-right", | ||
autoClose: 3000, | ||
hideProgressBar: true, | ||
closeOnClick: true, | ||
draggable: true, | ||
}); | ||
}); | ||
}; | ||
return ( | ||
<div> | ||
<div className='login-card'> | ||
<h2>Sign In</h2> | ||
<form onSubmit={handleSubmit}> | ||
<div className='form-control'> | ||
<div className='form-el-container'> | ||
<label htmlFor='email'>Email</label> | ||
</div> | ||
<div className='form-el-container'> | ||
<input | ||
className='forminput' | ||
type='text' | ||
id='email' | ||
value={email} | ||
onChange={(event) => setEmail(event.target.value)} | ||
placeholder='Enter your email' | ||
/> | ||
</div> | ||
</div> | ||
<div className='form-control'> | ||
<div className='form-el-container'> | ||
<label htmlFor='password'>Password</label> | ||
</div> | ||
<div className='form-el-container'> | ||
<input | ||
className='forminput' | ||
type='password' | ||
id='password' | ||
value={password} | ||
onChange={(event) => setPassword(event.target.value)} | ||
placeholder='Enter your password' | ||
/> | ||
</div> | ||
</div> | ||
<button className='btn' type='submit'> | ||
Sign In | ||
</button> | ||
</form> | ||
</div> | ||
<p className='read-the-docs'> | ||
Don't have a account, register from{" "} | ||
<Link to='/register'>here</Link>. | ||
</p> | ||
</div> | ||
); | ||
}; |
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,140 @@ | ||
import { useState } from "react"; | ||
import { ToastContainer, toast } from "react-toastify"; | ||
import { Link } from "react-router-dom"; | ||
|
||
import "react-toastify/dist/ReactToastify.css"; | ||
import apiClient from "../../libs/api.client"; | ||
|
||
export const RegisterCard = () => { | ||
const [email, setEmail] = useState(""); | ||
const [password, setPassword] = useState(""); | ||
const [firstName, setFirstName] = useState(""); | ||
const [lastName, setLastName] = useState(""); | ||
|
||
const handleSubmit = (event) => { | ||
event.preventDefault(); | ||
|
||
apiClient | ||
.post( | ||
"/user/register", | ||
{ | ||
email, | ||
password, | ||
firstName, | ||
lastName, | ||
}, | ||
{ | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
} | ||
) | ||
.then((response) => { | ||
if (response.data.email === email) { | ||
toast.success("Register Successful!", { | ||
position: "bottom-right", | ||
autoClose: 3000, | ||
hideProgressBar: true, | ||
closeOnClick: true, | ||
draggable: true, | ||
}); | ||
setTimeout(() => { | ||
window.location.href = "/verify"; | ||
}, 3000); | ||
} else { | ||
toast.error("Register Failed!", { | ||
position: "bottom-right", | ||
autoClose: 3000, | ||
hideProgressBar: true, | ||
closeOnClick: true, | ||
draggable: true, | ||
}); | ||
} | ||
}) | ||
.catch(() => { | ||
toast.error("Register Failed!", { | ||
position: "bottom-right", | ||
autoClose: 3000, | ||
hideProgressBar: true, | ||
closeOnClick: true, | ||
draggable: true, | ||
}); | ||
}); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<div className='login-card'> | ||
<h2>Sign In</h2> | ||
<form onSubmit={handleSubmit}> | ||
<div className='form-control'> | ||
<div className='form-el-container'> | ||
<label htmlFor='email'>Email</label> | ||
</div> | ||
<div className='form-el-container'> | ||
<input | ||
className='forminput' | ||
type='text' | ||
id='email' | ||
value={email} | ||
onChange={(event) => setEmail(event.target.value)} | ||
placeholder='Enter your email' | ||
/> | ||
</div> | ||
</div> | ||
<div className='form-control'> | ||
<div className='form-el-container'> | ||
<label htmlFor='password'>Password</label> | ||
</div> | ||
<div className='form-el-container'> | ||
<input | ||
className='forminput' | ||
type='password' | ||
id='password' | ||
value={password} | ||
onChange={(event) => setPassword(event.target.value)} | ||
placeholder='Enter your password' | ||
/> | ||
</div> | ||
</div> | ||
<div className='form-control'> | ||
<div className='form-el-container'> | ||
<label htmlFor='firstName'>First Name</label> | ||
</div> | ||
<div className='form-el-container'> | ||
<input | ||
className='forminput' | ||
type='firstName' | ||
id='firstName' | ||
value={firstName} | ||
onChange={(event) => setFirstName(event.target.value)} | ||
placeholder='Enter your firstName' | ||
/> | ||
</div> | ||
</div> | ||
<div className='form-control'> | ||
<div className='form-el-container'> | ||
<label htmlFor='lastName'>Last Name</label> | ||
</div> | ||
<div className='form-el-container'> | ||
<input | ||
className='forminput' | ||
type='lastName' | ||
id='lastName' | ||
value={lastName} | ||
onChange={(event) => setLastName(event.target.value)} | ||
placeholder='Enter your lastName' | ||
/> | ||
</div> | ||
</div> | ||
<button className='btn' type='submit'> | ||
Sign Up | ||
</button> | ||
</form> | ||
</div> | ||
<p className='read-the-docs'> | ||
Already have a account? Login from <Link to='/login'>here</Link>. | ||
</p> | ||
</div> | ||
); | ||
}; |
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
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
Oops, something went wrong.