-
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.
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
Showing
34 changed files
with
7,069 additions
and
0 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 |
---|---|---|
@@ -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/ |
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,2 @@ | ||
const JWT_SECRET = "someSecret"; | ||
module.exports = JWT_SECRET; |
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,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, | ||
}; |
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,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"); | ||
}); |
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,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 }; |
Oops, something went wrong.