{"size": 629, "ext": "js", "max_stars_repo_path": "api/account/refresh-token.js", "max_stars_repo_name": "nfssfn/FIIT-MTAA-BE", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "api/account/refresh-token.js", "max_issues_repo_name": "nfssfn/FIIT-MTAA-BE", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "api/account/refresh-token.js", "max_forks_repo_name": "nfssfn/FIIT-MTAA-BE", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 24.1923076923, "max_line_length": 90, "alphanum_fraction": 0.6295707472}
const of = require('await-of').of;
const jwt = require('../../misc/jwt');
const useGuard = require('../../misc/useGuard');
const User = require('../../models/User');

async function controller(req, res) {
  const [user, userError] = await of(User.findById(req.User._id, 'name username').exec());

  if (!user || userError)
    return res.sendStatus(400);

  const newToken = jwt.sign({
    _id: user._id,
    name: user.name,
    username: user.username
  });

  return res
    .cookie('x-token', newToken)
    .status(200)
    .send();
}

module.exports = (app) => {
  app.post('/account/refresh-token', useGuard, controller);
}