-
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
254dc0c
commit 2984dde
Showing
8 changed files
with
99 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React from 'react' | ||
import axios from 'axios'; | ||
|
||
export const logout = () => { | ||
axios.defaults.withCredentials = true | ||
console.log("clciked") | ||
// Add logout functionality here | ||
axios.post("http://localhost:5000/api/auth/logout") | ||
.then((res)=>{ | ||
window.location.reload(true); | ||
window.location.href = "/"; | ||
}).catch((err)=>console.log(err)) | ||
}; | ||
|
||
|
||
|
||
|
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,4 +1,4 @@ | ||
import React from "react"; | ||
import React, { useState } from "react"; | ||
import FloatingLabel from 'react-bootstrap/FloatingLabel'; | ||
import Form from 'react-bootstrap/Form'; | ||
import '../assets/CSS/signUp.css' | ||
|
@@ -11,21 +11,43 @@ import jwt_decode from 'jwt-decode' | |
|
||
export default function Login() { | ||
const navigate = useNavigate() | ||
const {setAuth,auth} = useAuthContext() | ||
|
||
const [email,setEmail] = useState("") | ||
const [password,setPassword] = useState("") | ||
|
||
|
||
|
||
|
||
const handleSubmit = ()=>{ | ||
|
||
const handleSubmit = (e)=>{ | ||
e.preventDefault() | ||
|
||
axios.defaults.withCredentials = true | ||
axios.post('http://localhost:5000/api/auth/login', {email:"[email protected]", password:"pwd123"}) | ||
axios.post('http://localhost:5000/api/auth/login', {email:email, password:password}) | ||
.then(response => { | ||
// Handle the successful response here | ||
|
||
console.log(jwt_decode(getSessionCookie("token"))) | ||
console.log('Registration successful:', response.data); | ||
setAuth(true) | ||
|
||
if(jwt_decode(getSessionCookie("token")).isVerified){ | ||
navigate("/dashboard",{replace:true}) | ||
} | ||
else{ | ||
navigate("/dashboard",{replace:true}) | ||
} | ||
|
||
|
||
|
||
|
||
}) | ||
.catch(error => { | ||
// Handle any errors that occur during the request | ||
console.error('Registration failed:', error.response.data); | ||
}); | ||
console.log('Login failed!') | ||
}).finally(()=>{ | ||
setEmail("") | ||
setPassword("") | ||
}) | ||
|
||
|
||
// if(auth.isVerified){ | ||
|
@@ -40,15 +62,15 @@ export default function Login() { | |
<div className="container-fluid" style={{ display: 'flex', justifyContent: 'center', alignItems: 'center', height: '100vh' }}> | ||
<div className="blurEffect" style={{ width: '500px' }}> | ||
<h1 className="mb-4" style={{textAlign:'center'}}>LOGIN</h1> | ||
<Form> | ||
<Form onSubmit={handleSubmit}> | ||
|
||
<FloatingLabel | ||
controlId="floatingInput" | ||
label="Email address" | ||
className="mb-3" | ||
style={{ fontSize: 'small' }} | ||
> | ||
<Form.Control type="email" size="sm" placeholder="[email protected]" /> | ||
<Form.Control onChange={(e)=>setEmail(e.target.value)} value={email} type="email" size="sm" placeholder="[email protected]" /> | ||
</FloatingLabel> | ||
|
||
<FloatingLabel | ||
|
@@ -57,7 +79,7 @@ export default function Login() { | |
// className="mb-3" | ||
style={{ fontSize: 'small' }} | ||
> | ||
<Form.Control type="password" placeholder="Password" /> | ||
<Form.Control onChange={(e)=>setPassword(e.target.value)} value={password} type="password" placeholder="Password" /> | ||
</FloatingLabel> | ||
|
||
|
||
|
@@ -68,7 +90,7 @@ export default function Login() { | |
</div> | ||
|
||
<div style={{ display: 'flex', flexDirection: 'column',marginTop: '50px'}}> | ||
<Button onClick={handleSubmit} className="mb-3 task-button">Login</Button> | ||
<Button type="submit" className="mb-3 task-button">Login</Button> | ||
{/* <hr className="hr-lines"/> | ||
<p>OR</p> */} | ||
<p className="hr-line"><span>OR</span></p> | ||
|
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