<commit_before>/**
	AS - Auth Server Library
	@description
		If access token exists on cookies,
		automatically get information from
		authentication server then pass it to
		next middleware. Accessible on req.user
	@author <NAME>
*/

var as_helper = require(__dirname + '/../helpers/auth_server'),
	config = require(__dirname + '/../config/config');

module.exports = function () {
	return function (req, res, next) {
		var set_user = function (err, data) {
				if (err) {
					res.clearCookie('access_token');
					return next(err);
				}
				req.user = data.user_data;
				req.user_id = req.user._id;
				req.user_data = data.user_data[config.app_id + '_data'] || {};
				req.is_admin = req.user_data.admin ? 1 : (req.user.admin ? 1 : 0);
				req.access_token = req.signedCookies.access_token;

				console.dir(req.user_id);
				console.dir(req.access_token);
				console.dir(req.user_data);

				next();
			};

		if (req.signedCookies.access_token) {
			as_helper.get_info({
				access_token : req.signedCookies.access_token,
				self : true
			}, set_user);
		}
		else {<commit_msg>Changed field name on as.js<commit_after>/**
	AS - Auth Server Library
	@description
		If access token exists on cookies,
		automatically get information from
		authentication server then pass it to
		next middleware. Accessible on req.user
	@author <NAME>
*/

var as_helper = require(__dirname + '/../helpers/auth_server'),
	config = require(__dirname + '/../config/config');

module.exports = function () {
	return function (req, res, next) {
		var set_user = function (err, data) {
				if (err) {
					res.clearCookie('access_token');
					return next(err);
				}
				req.user = data.user_data;
				req.user_id = req.user._id;
				req.user_data = data.user_data['data_' + config.app_id] || {};
				req.is_admin = req.user_data.admin ? 1 : (req.user.admin ? 1 : 0);
				req.access_token = req.signedCookies.access_token;

				console.dir(req.user_id);
				console.dir(req.access_token);
				console.dir(req.user_data);

				next();
			};

		if (req.signedCookies.access_token) {
			as_helper.get_info({
				access_token : req.signedCookies.access_token,
				self : true
			}, set_user);
		}
		else {
{'fraction_non_alphanumeric': 0.13574040219378428, 'fraction_numerical': 0.002742230347349177, 'mean_word_length': 3.2587548638132295, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '7403542', 'n_tokens_mistral': 874, 'n_tokens_neox': 735, 'n_words': 166}