{"size": 1157, "ext": "js", "max_stars_repo_path": "src/auth/extra-routes.js", "max_stars_repo_name": "David-Palagashvili-JS-401d36/auth-server", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/auth/extra-routes.js", "max_issues_repo_name": "David-Palagashvili-JS-401d36/auth-server", "max_issues_repo_issues_event_min_datetime": "2021-09-02T13:15:43.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-02T13:15:43.000Z", "max_forks_repo_path": "src/auth/extra-routes.js", "max_forks_repo_name": "David-Palagashvili-JS-401d36/auth-server", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 29.6666666667, "max_line_length": 133, "alphanum_fraction": 0.680207433}
'use strict';

// express middleware
const express = require('express');
const router = express.Router();

// bearer auth middleware
const bearer = require('./middleware/bearer-auth.js');

// Permissions for RBAC
const permissions = require('./middleware/authorize.js');

// instantiate user model
const UserModel = require('./models/user-model.js');
const User = new UserModel();

router.get('/secret', bearer, (req, res) => {
    res.send(req.user);
});

// The following routes are basically a means of ensuring that our authorization system works well:

router.get('/read', bearer, permissions('read'), (req, res) => { // // Read the value of the Bearer Token in the authorization header
    res.send('Route /read worked'); // permissions attached inline to all of your routes as described
});

router.post('/add', bearer, permissions('create'), (req, res) => {
    res.send('Route /add worked');
});

router.put('/change', bearer, permissions('update'), (req, res) => {
    res.send('Route /change worked');
});

router.delete('/remove', bearer, permissions('delete'), (req, res) => {
    res.send('Route /remove worked');
});

module.exports = router;