-
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
909a18f
commit 777e7b3
Showing
9 changed files
with
289 additions
and
78 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 |
---|---|---|
@@ -1,37 +1,46 @@ | ||
import "./LoginRegister.css" | ||
import "./LoginRegister.css"; | ||
import React, { useState } from "react"; | ||
import axios from "axios"; | ||
import { useNavigate } from "react-router-dom"; | ||
|
||
function Login() { | ||
const [username, setUsername] = useState(""); | ||
const [password, setPassword] = useState(""); | ||
const [username, setUsername] = useState(""); | ||
const [password, setPassword] = useState(""); | ||
let history = useNavigate(); | ||
|
||
const login = () => { | ||
const data = { username: username, password: password }; | ||
axios.post("http://localhost:3001/auth/login", data).then((response) => { | ||
console.log(response.data); | ||
}); | ||
}; | ||
return ( | ||
<div className="loginContainer"> | ||
<label>Username:</label> | ||
<input | ||
type="text" | ||
onChange={(event) => { | ||
setUsername(event.target.value); | ||
}} | ||
/> | ||
<label>Password:</label> | ||
<input | ||
type="password" | ||
onChange={(event) => { | ||
setPassword(event.target.value); | ||
}} | ||
/> | ||
const login = () => { | ||
const data = { username: username, password: password }; | ||
axios | ||
.post("http://localhost:3001/auth/login", data) | ||
.then((response) => { | ||
if (response.data.error) { | ||
alert(response.data.error); | ||
} else { | ||
sessionStorage.setItem("accessToken", response.data); | ||
history.push("/"); | ||
} | ||
}); | ||
}; | ||
return ( | ||
<div className="loginContainer"> | ||
<label>Username:</label> | ||
<input | ||
type="text" | ||
onChange={(event) => { | ||
setUsername(event.target.value); | ||
}} | ||
/> | ||
<label>Password:</label> | ||
<input | ||
type="password" | ||
onChange={(event) => { | ||
setPassword(event.target.value); | ||
}} | ||
/> | ||
|
||
<button onClick={login}> Login </button> | ||
</div> | ||
); | ||
<button onClick={login}> Login </button> | ||
</div> | ||
); | ||
} | ||
|
||
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 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,19 @@ | ||
const { verify } = require("jsonwebtoken"); | ||
|
||
const validateToken = (req, res, next) => { | ||
const accessToken = req.header("accessToken"); | ||
|
||
if (!accessToken) return res.json({ error: "User not logged in!" }); | ||
|
||
try { | ||
const validToken = verify(accessToken, "importantsecret"); | ||
|
||
if (validToken) { | ||
return next(); | ||
} | ||
} catch (err) { | ||
return res.json({ error: err }); | ||
} | ||
}; | ||
|
||
module.exports = { validateToken }; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Oops, something went wrong.