<commit_before>'use strict';

import models      from '../../models';
import { GENERIC } from '../../utils/errorTypes.js';

let User = models.User;

export default function resolveUser(req, res, next)  {
    let jwtUserId = req.user.id;

    User.findById(jwtUserId)
        .then(function (loggedInUser) {
            req.user = loggedInUser;
            return next();
        })
        .catch(function (err) {
            res.err(500)
        })
};

<commit_msg>Bail out if user resolved from JWT token doesn't exist<commit_after>'use strict';

import models      from '../../models';
import { GENERIC } from '../../utils/errorTypes.js';

let User = models.User;

export default function resolveUser(req, res, next)  {
    let jwtUserId = req.user.id;

    User.findById(jwtUserId)
        .then(function (loggedInUser) {
            if (!loggedInUser) {
                res.err(404, 'User not found!')
            } else {
                req.user = loggedInUser;
                return next();
            }
        })
        .catch(function (err) {
            res.err(500)
        })
};


{'fraction_non_alphanumeric': 0.13764813126709208, 'fraction_numerical': 0.008204193254329991, 'mean_word_length': 1.8445595854922279, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5511726', 'n_tokens_mistral': 339, 'n_tokens_neox': 331, 'n_words': 80}