-
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 #34 from brandonnorsworthy/updates
Updates
- Loading branch information
Showing
11 changed files
with
104 additions
and
59 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
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 was deleted.
Oops, something went wrong.
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 @@ | ||
import { Request, Response, NextFunction } from 'express'; | ||
import { AuthenticatedRequest } from './authenticate'; | ||
|
||
export const isModerator = (request: Request, response: Response, next: NextFunction) => { | ||
const { role } = (request as AuthenticatedRequest).tokenData; | ||
|
||
if (!role) { | ||
return response.status(401).json({ error: 'Access denied, \"role\" missing.' }); | ||
} | ||
|
||
if (role !== "admin" && role !== "moderator") { | ||
return response.status(403).json({ error: 'Access denied, Admins only.' }); | ||
} | ||
|
||
return next(); | ||
}; | ||
|
||
export const isAdmin = (request: Request, response: Response, next: NextFunction) => { | ||
const { role } = (request as AuthenticatedRequest).tokenData; | ||
|
||
if (!role) { | ||
return response.status(401).json({ error: 'Access denied, \"role\" missing.' }); | ||
} | ||
|
||
if (role !== "admin") { | ||
return response.status(403).json({ error: 'Access denied, Admins only.' }); | ||
} | ||
|
||
return next(); | ||
}; |
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
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