{"size": 573, "ext": "js", "max_stars_repo_path": "lib/require-account-redirect.js", "max_stars_repo_name": "warncke/immutable-commerce", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lib/require-account-redirect.js", "max_issues_repo_name": "warncke/immutable-commerce", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lib/require-account-redirect.js", "max_forks_repo_name": "warncke/immutable-commerce", "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.9130434783, "max_line_length": 99, "alphanum_fraction": 0.6719022688}
'use strict'

/* application libraries */
var redirect = require('./redirect')

/* public functions */
module.exports = requireAccountRedirect

/**
 * @function requireAccount
 *
 * @param {object} req - request
 *
 * @returns {Promise}
 */
function requireAccountRedirect (req) {
    // check if session has account
    return req.session.accountId
        // resolve if accountId set for session
        ? Promise.resolve()
        // return reject with redirect if not
        : redirect('/site/user/register?redirect=https://'+req.headers['x-forwarded-host']+req.url)
}