Created
August 17, 2020 10:49
-
-
Save bibhuticoder/1928a16f9306cd0effdc060212ce4829 to your computer and use it in GitHub Desktop.
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
const jwt = require('jsonwebtoken'); | |
// extract token from header | |
let authHeader = request.header.Authorization; | |
let token = authHeader.split(" ")[1]; | |
// decode token and get user's 'role' | |
let decodedVal = jwt.verify(token, process.env.JWT_KEY); | |
let role = decodedVal.role; | |
// get resource name(based on your web framework) | |
// eg: | |
// GET /products/1 => 'products' | |
// PUT /users/3 => 'users' | |
// POST /orders => 'orders' | |
let resourceName = request.url.split("/")[1]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment