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:
parent
97d7f357ea
commit
4c669c5a74
5 changed files with 25 additions and 17 deletions
|
@ -42,3 +42,9 @@ $ yarn lint
|
||||||
```
|
```
|
||||||
$ yarn test
|
$ yarn test
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Authentication
|
||||||
|
|
||||||
|
To manage pages you need to authorize (available on `/auth`).
|
||||||
|
|
||||||
|
To generate password use `yarn generatePassword [password]` command.
|
||||||
|
|
|
@ -55,7 +55,7 @@ function createMenuTree(parentPageId, pages, pagesOrder, level = 1, currentLevel
|
||||||
* @param res
|
* @param res
|
||||||
* @param next
|
* @param next
|
||||||
*/
|
*/
|
||||||
module.exports = asyncMiddleware(async function (req, res, next) {
|
module.exports = asyncMiddleware(async (req, res, next) => {
|
||||||
/**
|
/**
|
||||||
* Pages without parent
|
* Pages without parent
|
||||||
* @type {string}
|
* @type {string}
|
||||||
|
|
|
@ -13,10 +13,13 @@ module.exports = async function verifyToken(req, res, next) {
|
||||||
let token = req.cookies.authToken;
|
let token = req.cookies.authToken;
|
||||||
const userDoc = await Users.get();
|
const userDoc = await Users.get();
|
||||||
|
|
||||||
if (userDoc) {
|
if (!userDoc) {
|
||||||
jwt.verify(token, userDoc.passHash + config.secret, (err, decodedToken) => {
|
res.locals.isAuthorized = false;
|
||||||
res.locals.isAuthorized = !(err || !decodedToken);
|
next()
|
||||||
next();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jwt.verify(token, userDoc.passHash + config.secret, (err, decodedToken) => {
|
||||||
|
res.locals.isAuthorized = !(err || !decodedToken);
|
||||||
|
next();
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,15 +2,15 @@
|
||||||
<a href="/" class="docs-header__logo">
|
<a href="/" class="docs-header__logo">
|
||||||
{{ config.title }}
|
{{ config.title }}
|
||||||
</a>
|
</a>
|
||||||
<ul class="docs-header__menu-add">
|
<ul class="docs-header__menu">
|
||||||
<li>
|
{% if isAuthorized == true %}
|
||||||
{% if isAuthorized == true %}
|
<li class="docs-header__menu-add">
|
||||||
<a class="docs-header__button" href="/page/new">
|
<a class="docs-header__button" href="/page/new">
|
||||||
{{ svg('plus') }}
|
{{ svg('plus') }}
|
||||||
Add Page
|
Add Page
|
||||||
</a>
|
</a>
|
||||||
{% endif %}
|
</li>
|
||||||
</li>
|
{% endif %}
|
||||||
{% for option in config.menu %}
|
{% for option in config.menu %}
|
||||||
<li>
|
<li>
|
||||||
<a
|
<a
|
||||||
|
|
|
@ -6,13 +6,12 @@ const { expect } = chai;
|
||||||
chai.use(chaiHTTP);
|
chai.use(chaiHTTP);
|
||||||
|
|
||||||
describe('Express app', () => {
|
describe('Express app', () => {
|
||||||
it('App is available', async (done) => {
|
it('App is available', async () => {
|
||||||
let agent = chai.request.agent(app);
|
let agent = chai.request.agent(app);
|
||||||
|
|
||||||
const result = await agent
|
const result = await agent
|
||||||
.get('/');
|
.get('/');
|
||||||
|
|
||||||
expect(result).to.have.status(200);
|
expect(result).to.have.status(200);
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue