Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

commit #41

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions backend/auth/auhtorization.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const usertoken= require("../config");
const jwt= require("jsonwebtoken");

const AuhtorizeUser=(req, res,next)=>{
const auth= req.headers["authorization"];
if(!auth){
return res.json({
msg:"no header is there in yout headers ",
})
}
const token = auth.split(" ")[1];
jwt.verify(token, usertoken , (err, decoded)=>{
if(err){
return res.json({
msg:"the user cannot be verified",
})
}
req.user= decoded;
next();

})

}
module.exports= AuhtorizeUser;
3 changes: 3 additions & 0 deletions backend/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const usertoken= "hardikyadav1182005";

module.exports= usertoken;
14 changes: 14 additions & 0 deletions backend/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
const express = require("express");
const router = require("./routes/index");
const bodyParser= require("body-parser")
const cors = require("cors");
const Port= 3000;

const app= express();
app.use(express.json());
app.use(bodyParser.urlencoded({extended:true}));

app.use("/api/v1", router);


app.listen(Port, ()=>{
console.log("the server has stared ");
})

24 changes: 24 additions & 0 deletions backend/models/User.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const {Schema ,type , model} = require("mongoose");
const mongoose= require("mongoose");

mongoose.connect("mongodb://localhost:27017/BankUser").then(()=>{console.log("the db has started ")})
const userSchema = new Schema({
Fullname:{
type:String,
required:true,

},
Email:{
type:String,
required:true,
unique:true,

},
Password:{
type:String,
required:true
}
},{timestamps:true}
)
const User= model("userschema",userSchema);
module.exports= User;
Loading