Skip to content

Commit

Permalink
feat: add jwt.secret option
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowgate15 committed Aug 23, 2021
1 parent d9a23d5 commit 603b930
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ The API will start automatically when the Bree constructor is called.

## Options

| Option | Type | Description |
|:------:|:------:|----------------------------------|
| port | Number | The port the API will listen on. |
| Option | Type | Description |
|:------:|:------:|----------------------------------------------------------------------------------------------|
| port | Number | The port the API will listen on. |
| jwt | Object | Configurations for JWT. Only option is `secret` which will be the secret used to verify JWT. |

## API

Expand Down
8 changes: 7 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,22 @@ const api = require('./api');
const apiConfig = require('./config/api');

const config = require('./config');
const jwt = require('koa-jwt');

function plugin(opts, Bree) {
opts = {
port: config.port,
jwt: config.jwt,
...opts
};

const api = new API({
...apiConfig,
port: opts.port
port: opts.port,
jwt: opts.jwt,
hookBeforeRoutes: (app) => {
app.use(jwt(opts.jwt));
}
});

const oldInit = Bree.prototype.init;
Expand Down
3 changes: 2 additions & 1 deletion test/plugin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ test('api does exist on bree instance', (t) => {
t.log(bree.api);
t.is(typeof bree.api, 'object');

// port is set correctly by default
// options is set correctly by default
t.is(bree.api.config.port, 4000);
t.is(bree.api.config.jwt.secret, 'secret');
});
4 changes: 3 additions & 1 deletion test/plugin/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ test('can modify options', (t) => {
t.not(plugin.$i, true);

Bree.extend(plugin, {
port: 3000
port: 3000,
jwt: { secret: 'thisisasecret' }
});

const bree = new Bree(baseConfig);

t.is(bree.api.config.port, 3000);
t.is(bree.api.config.jwt.secret, 'thisisasecret');
});

0 comments on commit 603b930

Please sign in to comment.