1
0
Fork 0
mirror of https://github.com/codex-team/codex.docs.git synced 2025-08-08 06:55:26 +02:00

Fix middleware + add note about password in readme

This commit is contained in:
georgyb 2019-03-06 13:19:44 +03:00
parent 97d7f357ea
commit 4c669c5a74
5 changed files with 25 additions and 17 deletions

View file

@ -42,3 +42,9 @@ $ yarn lint
```
$ yarn test
```
### Authentication
To manage pages you need to authorize (available on `/auth`).
To generate password use `yarn generatePassword [password]` command.

View file

@ -55,7 +55,7 @@ function createMenuTree(parentPageId, pages, pagesOrder, level = 1, currentLevel
* @param res
* @param next
*/
module.exports = asyncMiddleware(async function (req, res, next) {
module.exports = asyncMiddleware(async (req, res, next) => {
/**
* Pages without parent
* @type {string}

View file

@ -13,10 +13,13 @@ module.exports = async function verifyToken(req, res, next) {
let token = req.cookies.authToken;
const userDoc = await Users.get();
if (userDoc) {
if (!userDoc) {
res.locals.isAuthorized = false;
next()
}
jwt.verify(token, userDoc.passHash + config.secret, (err, decodedToken) => {
res.locals.isAuthorized = !(err || !decodedToken);
next();
});
}
};

View file

@ -2,15 +2,15 @@
<a href="/" class="docs-header__logo">
{{ config.title }}
</a>
<ul class="docs-header__menu-add">
<li>
<ul class="docs-header__menu">
{% if isAuthorized == true %}
<li class="docs-header__menu-add">
<a class="docs-header__button" href="/page/new">
{{ svg('plus') }}
Add Page
</a>
{% endif %}
</li>
{% endif %}
{% for option in config.menu %}
<li>
<a

View file

@ -6,13 +6,12 @@ const { expect } = chai;
chai.use(chaiHTTP);
describe('Express app', () => {
it('App is available', async (done) => {
it('App is available', async () => {
let agent = chai.request.agent(app);
const result = await agent
.get('/');
expect(result).to.have.status(200);
done();
});
});