From 7aca73dea4fed4900e5ca8d9977f446ece9b1436 Mon Sep 17 00:00:00 2001 From: dmldc Date: Fri, 19 Nov 2021 15:04:52 -0500 Subject: [PATCH] Returns access and refresh tokens on registration as well as summary user info --- routes/api/account.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/routes/api/account.js b/routes/api/account.js index db5f4d22..f781b796 100644 --- a/routes/api/account.js +++ b/routes/api/account.js @@ -133,6 +133,7 @@ module.exports = function (app) { if (!req.body || !req.body.username || !req.body.name || !req.body.password) throw new JsonError('You must specify an email address, username and password', 400); const appId = req.site.server.client_id; + const secret = req.site.server.secret; const account = new User(appId); const obj = req.body; account.username = obj.username; @@ -166,8 +167,19 @@ module.exports = function (app) { if (err) { return next(new JsonError(err.message)); } - delete account.password; - res.json(account); + jsonToken(account, appId, secret, (err, json) => { + if (err) return next(err); + tokens.issueRefreshToken(req, account.id, deviceId, appId, ( + err, + refreshToken + ) => { + if (err) { + return next(err); + } + json.refresh_token = refreshToken.token; + return res.status(200).json(json); + }); + }); }); }); });