<commit_before>'use strict';

require('env2')('config.env');
const isAMemberOfSet = require('../db/redis.js').isAMemberOfSet;
const isExistingUser = require('../db/redis.js').isExistingUser;

exports.register = (server, options, next) => {

      server.ext({
        type: 'onRequest',
        method: (request, reply) => {
          let error;
          if (request.query.error) { error = request.query.error;}
          //console.log(' REQUEST >>>>>>>>>>', request);
          if (error === 'access_denied' && request.url.path.indexOf(process.env.AGENCY_AUTH_ENDPOINT) > -1) {
            request.setUrl('/' + process.env.AGENCY_LOGIN_ENDPOINT);
          } else if (error === 'access_denied') {
            request.setUrl('/');
          }
          if(error === 'Unauthorized'){
            request.setUrl('/');
          }
            return reply.continue();
        }
    });

    server.route({

        method: 'GET',
        path: '/login/{user*}',
        config: {
            auth: {
                strategies: ['hrns-cookie','linkedin-oauth']
            },
            plugins: { 'hapi-auth-cookie': { redirectTo: false } }, // stops redirecting to home if not authenticated.
            handler: (request, reply) => {
                let failOpts = { message: 'Bad request... please return <a href="/">home</a> and try again'};
                const credentials = request.auth.credentials;
                console.log('0 EXPIRES IN >>>>>>>>>>>>>>>>>>>',credentials.expiresIn);
                //credentials.refreshToken;
                console.log('1 EXPIRES IN >>>>>>>>>>>>>>>>>>>',credentials.expiresIn);

                if (request.auth.isAuthenticated) {

                    let userType = request.params.user;
                    let id = credentials.profile.id;
                console.log('2 EXPIRES IN >>>>>>>>>>>>>>>>>>>',credentials.expiresIn);
                    request.cookieAuth.set(credentials);

                    if (userType === 'candidate') {

                        request.cookieAuth.set('type', 'candidate');
                        request.cookieAuth.set('scope', 'candidate');

                        reply.redirect('/candidate');

                    } else if (userType === 'client') {

                        request.cookieAuth.set('type', 'client');

                        isExistingUser(id, (res) => {
                            if (!res) {
                                reply.redirect('/clientsignup');
                            } else {
                                isAMemberOfSet(id, 'approvedUsers', (res) => {<commit_msg>remove console logs<commit_after>'use strict';

require('env2')('config.env');
const isAMemberOfSet = require('../db/redis.js').isAMemberOfSet;
const isExistingUser = require('../db/redis.js').isExistingUser;

exports.register = (server, options, next) => {

      server.ext({
        type: 'onRequest',
        method: (request, reply) => {
          let error;
          if (request.query.error) { error = request.query.error;}
          //console.log(' REQUEST >>>>>>>>>>', request);
          if (error === 'access_denied' && request.url.path.indexOf(process.env.AGENCY_AUTH_ENDPOINT) > -1) {
            request.setUrl('/' + process.env.AGENCY_LOGIN_ENDPOINT);
          } else if (error === 'access_denied') {
            request.setUrl('/');
          }
          if(error === 'Unauthorized'){
            request.setUrl('/');
          }
            return reply.continue();
        }
    });

    server.route({

        method: 'GET',
        path: '/login/{user*}',
        config: {
            auth: {
                strategies: ['hrns-cookie','linkedin-oauth']
            },
            plugins: { 'hapi-auth-cookie': { redirectTo: false } }, // stops redirecting to home if not authenticated.
            handler: (request, reply) => {
                let failOpts = { message: 'Bad request... please return <a href="/">home</a> and try again'};
                const credentials = request.auth.credentials;
                if (request.auth.isAuthenticated) {

                    let userType = request.params.user;
                    let id = credentials.profile.id;
                    request.cookieAuth.set(credentials);

                    if (userType === 'candidate') {

                        request.cookieAuth.set('type', 'candidate');
                        request.cookieAuth.set('scope', 'candidate');

                        reply.redirect('/candidate');

                    } else if (userType === 'client') {

                        request.cookieAuth.set('type', 'client');

                        isExistingUser(id, (res) => {
                            if (!res) {
                                reply.redirect('/clientsignup');
                            } else {
                                isAMemberOfSet(id, 'approvedUsers', (res) => {
{'fraction_non_alphanumeric': 0.15745290745290746, 'fraction_numerical': 0.0014332514332514332, 'mean_word_length': 1.609508547008547, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 96, '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': '2807762', 'n_tokens_mistral': 1347, 'n_tokens_neox': 1278, 'n_words': 245}