Skip to content

Commit

Permalink
Merge pull request #124 from Abhishek-TG18/main
Browse files Browse the repository at this point in the history
Connected frontEnd with BackEnd
  • Loading branch information
AnitSarkar123 authored Oct 6, 2024
2 parents 6cb828b + b970e2a commit 363d603
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 5 deletions.
45 changes: 45 additions & 0 deletions SignUp/signup.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,50 @@ <h1>Create Your Account</h1>
<a href="../login/login.html">Already have an account? Login</a>
</div>
</div>

<script>
const signup = document.querySelector(".signup-button");

signup.addEventListener("click",(e)=>{
e.preventDefault();

const name = document.querySelector("#username").value;
const email = document.querySelector("#email").value;
const password = document.querySelector("#password").value;
const confirmPassword = document.querySelector("#confirm-password").value;

if(!name || !email || !password || !confirmPassword){
alert("every feild is required");
return;
}
const userdata = {
name,
email,
password,
confirmPassword
}
registeruser(userdata);

} )


const registeruser = async(user)=>{

try{
const res = await fetch("http://localhost:5000/auth/signup",{
method:"POST",
headers:{"content-type" : "application/json"},
body:JSON.stringify(user)
})

const data = await res.json();
console.log(data);
window.location.href="http://127.0.0.1:5500/Collect-your-GamingTools/login/login.html"

}catch(err){
console.log(err.message)
}
}
</script>
</body>
</html>
4 changes: 2 additions & 2 deletions backend/controller/authController.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const emailValidator = require("email-validator");

const signUp = async (req, res, next) => {
const { name, email, password, confirmPassword } = req.body;

console.log(name , email,password,confirmPassword)
/// every field is required
if (!name || !email || !password || !confirmPassword) {
return res.status(400).json({
Expand Down Expand Up @@ -137,7 +137,7 @@ const signIn = async (req, res, next) => {
const logout = async (req, res, next) => {
try {
const cookieOption = {
expires: new Date(), // current expiry date
expires: new Date(Date.now()), // current expiry date
httpOnly: true // not able to modify the cookie in client side
};

Expand Down
2 changes: 1 addition & 1 deletion backend/middleware/jwtAuth.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const JWT = require("jsonwebtoken");

// router level middleware function
const jwtAuth = (req, res, next) => {
console.log(req.cookies?.token);

// get cookie token(jwt token generated using json.sign()) form the request
const token = ( req.cookies?.token) || null;

Expand Down
42 changes: 40 additions & 2 deletions login/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<h1>Login to Your Account</h1>
<form action="#" method="post">
<div class="input-group">
<label for="username">Username</label>
<input type="text" id="username" name="username" required>
<label for="username">Gmail</label>
<input type="text" id="gmail" name="username" required>
</div>
<div class="input-group">
<label for="password">Password</label>
Expand All @@ -31,4 +31,42 @@ <h1>Login to Your Account</h1>
</div>
</div>
</body>

<script>
const login = document.querySelector(".button");

login.addEventListener("click",(e)=>{
e.preventDefault();

const email = document.querySelector("#gmail").value;
const password = document.querySelector("#password").value;
const userData = {
email,
password
}
console.log(userData)
loginUser(userData)
})

const loginUser = async (user)=>{
try{
const res = await fetch("http://localhost:5000/auth/signin",{
method:"POST",
credentials:"include",
redirect:"follow",
headers:{"content-type":"application/json"},
body:JSON.stringify(user)
})
if (!res.ok) {
throw new Error(`HTTP error! status: ${res.status}`);
}
const data = await res.json();


window.location.href="http://127.0.0.1:5500/Collect-your-GamingTools/index.html"
}catch(e){
console.log(e.message);
}
}
</script>
</html>

0 comments on commit 363d603

Please sign in to comment.