This repository has been archived by the owner on Mar 10, 2024. It is now read-only.
-
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.
fix temporary v1 compatibility issues
- Loading branch information
1 parent
c8998ee
commit ed3aaad
Showing
9 changed files
with
128 additions
and
106 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,23 @@ | ||
const express = require("express"); | ||
const router = express.Router(); | ||
const { | ||
getGames, | ||
createGame, | ||
updateGame, | ||
deleteGame, | ||
} = require("../../controllers/chargedUpController"); | ||
const fillTeamName = require("../../middleware/fillTeamName"); | ||
const { editHistory } = require("../../middleware/editHistory"); | ||
const protect = require("./protect.js"); | ||
|
||
router | ||
.route("/") | ||
.post(protect, fillTeamName, editHistory, createGame) | ||
.get(protect, getGames); | ||
router | ||
.route("/:id") | ||
.get(protect, getGames) | ||
.put(protect, editHistory, updateGame) | ||
.delete(protect, deleteGame); | ||
|
||
module.exports = router; |
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,32 @@ | ||
const jwt = require("jsonwebtoken"); | ||
const User = require("../../models/usersDb/userModel"); | ||
const asyncHandler = require("express-async-handler"); | ||
|
||
const protect = asyncHandler(async (req, res, next) => { | ||
let token; | ||
if ( | ||
req.headers.authorization && | ||
req.headers.authorization.startsWith("Bearer") | ||
) { | ||
try { | ||
token = req.headers.authorization.split(" ")[1]; | ||
const decoded = jwt.verify(token, process.env.JWT_SECRET); | ||
req.user = await User.findById(decoded.id).select("-password"); | ||
if (req.user.toObject().isAdmin || req.user.toObject().isVerified) { | ||
next(); | ||
} else { | ||
res.status(405).json({ | ||
message: "User is not compatible with the v1 API", | ||
}); | ||
} | ||
} catch (err) { | ||
console.log(err); | ||
res.status(401).json({ message: "Token failed" }); | ||
} | ||
} | ||
if (!token) { | ||
res.status(401).json({ message: "No token" }); | ||
} | ||
}); | ||
|
||
module.exports = protect; |
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,21 @@ | ||
const express = require("express"); | ||
const router = express.Router(); | ||
const { | ||
getGames, | ||
setGame, | ||
updateGame, | ||
deleteGame, | ||
} = require("../../controllers/rapidReactController"); | ||
const protect = require("./protect"); | ||
const { editHistory } = require("../../middleware/editHistory"); | ||
|
||
// all routes require user to be verified before making a request | ||
// authorization middleware checks for bearer token in header | ||
router.route("/").post(protect, editHistory, setGame).get(protect, getGames); | ||
router | ||
.route("/:id") | ||
.get(protect, getGames) | ||
.put(protect, editHistory, updateGame) | ||
.delete(protect, deleteGame); | ||
|
||
module.exports = router; |
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
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