diff options
Diffstat (limited to 'src/api/routes/user/apiKey.js')
| -rw-r--r-- | src/api/routes/user/apiKey.js | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/src/api/routes/user/apiKey.js b/src/api/routes/user/apiKey.js index 7de6cb8..f80d563 100644 --- a/src/api/routes/user/apiKey.js +++ b/src/api/routes/user/apiKey.js @@ -2,10 +2,11 @@ const Route = require('../../structures/Route'); const randomstring = require('randomstring'); const moment = require('moment'); const bcrypt = require('bcrypt'); +const { dump } = require('dumper.js'); class apiKeyPOST extends Route { constructor() { - super('/user/apikey/change', 'post'); + super('/user/apikey/change', 'post', { noApiKey: true }); } async run(req, res, db, user) { @@ -14,24 +15,21 @@ class apiKeyPOST extends Route { try { const hash = await bcrypt.hash(apiKey, 10); - await db.table('users') .where({ id: user.id }) .update({ apiKey: hash, apiKeyEditedAt: now }); - - return res.json({ - message: 'Successfully created new api key', - apiKey - }); - } catch (error) { - return super.error(res, error); + dump(error); + return res.status(401).json({ message: 'There was a problem processing your account' }); } - + return res.json({ + message: 'Successfully created new api key', + apiKey + }); } } |