Skip to content

Commit

Permalink
Add displayName to access tokens. Closes #182 (#187)
Browse files Browse the repository at this point in the history
* Add displayName to access tokens. Closes #182

* Make display name optional
  • Loading branch information
brollb authored Feb 26, 2020
1 parent 42ca50b commit 492d764
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/server/middleware/access-tokens/TokenServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ function TokenServer(options) {
res.json(await self.tokens.list(userId));
});

router.post('/create', async function (req, res) {
router.post('/create/:name?', async function (req, res) {
const userId = self.getUserId(req);
const token = await self.tokens.create(userId);
const {name} = req.params;
const token = await self.tokens.create(userId, name);
res.json(token);
});

Expand Down Expand Up @@ -71,8 +72,10 @@ AccessTokens.prototype.list = async function (userId) {
return tokens;
};

AccessTokens.prototype.create = async function (userId) {
AccessTokens.prototype.create = async function (userId, name) {
name = name || `Created on ${new Date()}`;
const token = {
displayName: name,
userId: userId,
id: this.chance.guid(),
issuedAt: new Date(),
Expand Down

0 comments on commit 492d764

Please sign in to comment.