Skip to content

Commit

Permalink
Merged in return-tokens-when-registering-api (pull request auth0#29)
Browse files Browse the repository at this point in the history
Returns access and refresh tokens on registration
  • Loading branch information
David Lenton committed Nov 24, 2021
2 parents c6a0c2d + 7aca73d commit 525ed49
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions routes/api/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
});
});
});
});
});
Expand Down

0 comments on commit 525ed49

Please sign in to comment.