generated from CS3219-AY2324S1/course-assessment-template
-
Notifications
You must be signed in to change notification settings - Fork 5
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 #73 from kohkaixun/master
Rectify admin view
- Loading branch information
Showing
4 changed files
with
29 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const axios = require('axios') | ||
const { verifyJsonWebToken } = require('./tokenUtils') | ||
const USER_HOST = process.env.USER_HOST ? process.env.USER_HOST : "http://localhost:4000/api/users" | ||
|
||
|
||
async function validateAdmin (request, response, next) { | ||
const token = request.headers.authorization | ||
console.log(token) | ||
try { | ||
const is_admin = verifyJsonWebToken(token).user_data.is_admin | ||
if (!is_admin) { | ||
return response.status(401).json({ error: 'Unauthorised access. User not admin.' }) | ||
} | ||
} catch (error) { | ||
console.log("error") | ||
console.log(error.message) | ||
return response.status(401).json({ error: 'Unauthorised' }) | ||
} | ||
|
||
next() | ||
} | ||
|
||
module.exports = { | ||
validateAdmin | ||
} |
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