-
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.
Merge pull request #6 from fga-eps-mds/fixing_tests
redone e write permissions to routes
- Loading branch information
Showing
13 changed files
with
585 additions
and
311 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,10 @@ | ||
# CHANGE ALL VARIABLES ON DEPLOY | ||
|
||
NODE_ENV=development | ||
MONGO_URI=mongodb://root:password@financedb:27017/ | ||
MONGO_INITDB_ROOT_USERNAME=root | ||
MONGO_INITDB_ROOT_PASSWORD=password | ||
DB_HOST=financedb | ||
PORT=3002 | ||
BACK_USERS_URL=http://127.0.0.1:3001/ | ||
SECRET = S3T1N3L3L4 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const jwt = require("jsonwebtoken"); | ||
|
||
const checkPermissions = (permissionName) => { | ||
return async (req, res, next) => { | ||
try { | ||
const decoded = jwt.decode( | ||
req.headers.authorization?.split(" ")[1] | ||
); | ||
if (!decoded) { | ||
return res | ||
.status(401) | ||
.json({ mensagem: "Tokem não fornecido." }); | ||
} | ||
const permission = decoded.permissions.find( | ||
(perm) => perm === permissionName | ||
); | ||
|
||
if (!permission) { | ||
return res | ||
.status(400) | ||
.send("user has no permission to access resource"); | ||
} | ||
next(); | ||
} catch (error) { | ||
next(error); | ||
} | ||
}; | ||
}; | ||
|
||
module.exports = { checkPermissions }; |
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
Oops, something went wrong.