Skip to content

Commit

Permalink
Merge branch 'master'
Browse files Browse the repository at this point in the history
Merging changes from the master branch into the main branch

Incorporating updates and new features from the master branch into the main branch to unify the project history.
  • Loading branch information
Reayan-Iqbal committed Jan 30, 2024
2 parents 0ffa584 + df8f333 commit bd182f0
Show file tree
Hide file tree
Showing 34 changed files with 7,069 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Ignore node_modules directory
node_modules/

# Ignore .env files containing sensitive information
.env

# Ignore npm's debug log file
npm-debug.log*

# Ignore yarn's debug log file
yarn-debug.log*

# Ignore yarn error log file
yarn-error.log*

# Ignore IDE and editor-specific files
.vscode/
.idea/
*.sublime-workspace
*.sublime-project
.DS_Store

# Ignore compiled binary files
*.pyc
*.class
*.jar

# Ignore dependencies installed via pip
pip-wheel-metadata/
2 changes: 2 additions & 0 deletions backend/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const JWT_SECRET = "someSecret";
module.exports = JWT_SECRET;
54 changes: 54 additions & 0 deletions backend/db.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const mongoose = require("mongoose");
const { string } = require("zod");

mongoose.connect("Your_Connection_String");

const userSchema = new mongoose.Schema({
username: {
type: String,
required: true,
unique: true,
trim: true,
lowercase: true,
minLength: 3,
maxLength: 30,
},
password: {
type: String,
required: true,
minLength: 6,
},
firstName: {
type: String,
required: true,
trim: true,
maxLength: 50,
},
lastName: {
type: String,
required: true,
trim: true,
maxLength: 50,
},
});

const User = mongoose.model("User", userSchema);

const accountSchema = new mongoose.Schema({
userId: {
type: mongoose.Schema.Types.ObjectId,
ref: "User",
required: true,
},
balance: {
type: Number,
required: true,
},
});

const Account = mongoose.model("Account", accountSchema);

module.exports = {
User,
Account,
};
10 changes: 10 additions & 0 deletions backend/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const express = require("express");
const rootRouter = require("./routes/index");
const app = express();
const cors = require("cors");
app.use(express.json());
app.use(cors());
app.use("/api/v1", rootRouter);
app.listen(3000, () => {
console.log("Listening on Port 3000");
});
22 changes: 22 additions & 0 deletions backend/middleware.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const jwt = require("jsonwebtoken");
const JWT_SECRET = require("./config");
const authMiddleware = (req, res, next) => {
const authHeader = req.headers.authorization;
if (!authHeader || !authHeader.startsWith("Bearer ")) {
return res.status(403).json({
message: "Authorization Token Error",
});
} else {
const token = authHeader.split(" ")[1];
try {
const userId = jwt.verify(token, JWT_SECRET).userId;
req.userId = userId;
} catch (error) {
res.status(403).json({
message: "Unauthorized User",
});
}
}
next();
};
module.exports = { authMiddleware };
Loading

0 comments on commit bd182f0

Please sign in to comment.