From f1bcd8368110c485ecd6815045d33c01c7f72d97 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 15 Nov 2018 14:35:12 +0100 Subject: [PATCH 1/2] Eliminating session object --- server/src/schema/schema.js | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/server/src/schema/schema.js b/server/src/schema/schema.js index 35f482a4a..369feea87 100644 --- a/server/src/schema/schema.js +++ b/server/src/schema/schema.js @@ -390,15 +390,6 @@ function authenticate (encodedToken, callBackFunction) { if (global.INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> authenticate -> onValidated -> onUserFound -> Existing User: ' + JSON.stringify(user)) } - /* - - Here we save the user id of the logged in user at the server Sessions map, from there it will - be used to validate any further transaction comming from this same user. - - */ - - global.Sessions.set(encodedToken, user.id) - callBackFunction(global.DEFAULT_OK_RESPONSE, { authId: authId, alias: user.alias }) return } @@ -460,15 +451,6 @@ function authenticate (encodedToken, callBackFunction) { if (global.INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> authenticate -> onValidated -> onUserFound -> onSaved -> Saved User: ' + JSON.stringify(savedUser)) } - /* - - Here we save the user id of the logged in user at the server Sessions map, from there it will - be used to validate any further transaction comming from this same user. - - */ - - global.Sessions.set(encodedToken, savedUser.id) - callBackFunction(global.DEFAULT_OK_RESPONSE, { authId, alias }) } } From 51244e9b27a48cd4a3070478536342c2b4c0dff4 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 15 Nov 2018 14:41:29 +0100 Subject: [PATCH 2/2] INFO LOG now at ENV File --- server/src/auth/token-decoder.js | 24 +++++----- server/src/globals.js | 34 ++++++-------- server/src/schema/schema.js | 80 ++++++++++++++++---------------- 3 files changed, 67 insertions(+), 71 deletions(-) diff --git a/server/src/auth/token-decoder.js b/server/src/auth/token-decoder.js index c31691520..44c90c839 100644 --- a/server/src/auth/token-decoder.js +++ b/server/src/auth/token-decoder.js @@ -22,7 +22,7 @@ const decoder = webTokenLibrary({ function decodeToken (token, callBackFunction) { try { - if (global.INFO_LOG === true) { console.log('[INFO] ' + MODULE_NAME + ' -> decodeToken -> Entering function.') } + if (process.env.INFO_LOG === true) { console.log('[INFO] ' + MODULE_NAME + ' -> decodeToken -> Entering function.') } const decoded = JSONWebToken.decode(token, { complete: true }) const header = decoded.header @@ -33,8 +33,8 @@ function decodeToken (token, callBackFunction) { header.kid === null || payload === null ) { - if (global.ERROR_LOG === true) { console.log('[ERROR] ' + MODULE_NAME + ' -> decodeToken -> Invalid Token. ') } - if (global.ERROR_LOG === true) { console.log('[ERROR] ' + MODULE_NAME + ' -> decodeToken -> token = ' + token) } + if (process.env.ERROR_LOG === true) { console.log('[ERROR] ' + MODULE_NAME + ' -> decodeToken -> Invalid Token. ') } + if (process.env.ERROR_LOG === true) { console.log('[ERROR] ' + MODULE_NAME + ' -> decodeToken -> token = ' + token) } callBackFunction(global.DEFAULT_FAIL_RESPONSE) return } @@ -42,12 +42,12 @@ function decodeToken (token, callBackFunction) { decoder.getSigningKey(header.kid, onKeyReady) function onKeyReady (err, key) { - if (global.INFO_LOG === true) { console.log('[INFO] ' + MODULE_NAME + ' -> decodeToken -> onKeyReady -> Entering function.') } + if (process.env.INFO_LOG === true) { console.log('[INFO] ' + MODULE_NAME + ' -> decodeToken -> onKeyReady -> Entering function.') } if (err) { - if (global.ERROR_LOG === true) { console.log('[ERROR] ' + MODULE_NAME + ' -> decodeToken -> onKeyReady -> Error getting the key. ') } - if (global.ERROR_LOG === true) { console.log('[ERROR] ' + MODULE_NAME + ' -> decodeToken -> onKeyReady -> key = ' + key) } - if (global.ERROR_LOG === true) { console.log('[ERROR] ' + MODULE_NAME + ' -> decodeToken -> onKeyReady -> err = ' + err) } + if (process.env.ERROR_LOG === true) { console.log('[ERROR] ' + MODULE_NAME + ' -> decodeToken -> onKeyReady -> Error getting the key. ') } + if (process.env.ERROR_LOG === true) { console.log('[ERROR] ' + MODULE_NAME + ' -> decodeToken -> onKeyReady -> key = ' + key) } + if (process.env.ERROR_LOG === true) { console.log('[ERROR] ' + MODULE_NAME + ' -> decodeToken -> onKeyReady -> err = ' + err) } callBackFunction(global.DEFAULT_FAIL_RESPONSE) return } @@ -59,12 +59,12 @@ function decodeToken (token, callBackFunction) { onVerified) function onVerified (err, decoded) { - if (global.INFO_LOG === true) { console.log('[INFO] ' + MODULE_NAME + ' -> decodeToken -> onKeyReady -> onVerified -> Entering function.') } + if (process.env.INFO_LOG === true) { console.log('[INFO] ' + MODULE_NAME + ' -> decodeToken -> onKeyReady -> onVerified -> Entering function.') } if (err) { - if (global.ERROR_LOG === true) { console.log('[ERROR] ' + MODULE_NAME + ' -> decodeToken -> onKeyReady -> onVerified -> Error verifying. ') } - if (global.ERROR_LOG === true) { console.log('[ERROR] ' + MODULE_NAME + ' -> decodeToken -> onKeyReady -> onVerified -> decoded = ' + decoded) } - if (global.ERROR_LOG === true) { console.log('[ERROR] ' + MODULE_NAME + ' -> decodeToken -> onKeyReady -> onVerified -> err = ' + err) } + if (process.env.ERROR_LOG === true) { console.log('[ERROR] ' + MODULE_NAME + ' -> decodeToken -> onKeyReady -> onVerified -> Error verifying. ') } + if (process.env.ERROR_LOG === true) { console.log('[ERROR] ' + MODULE_NAME + ' -> decodeToken -> onKeyReady -> onVerified -> decoded = ' + decoded) } + if (process.env.ERROR_LOG === true) { console.log('[ERROR] ' + MODULE_NAME + ' -> decodeToken -> onKeyReady -> onVerified -> err = ' + err) } callBackFunction(global.DEFAULT_FAIL_RESPONSE) return } @@ -73,7 +73,7 @@ function decodeToken (token, callBackFunction) { } } } catch (err) { - if (global.ERROR_LOG === true) { console.log('[ERROR] ' + MODULE_NAME + ' -> decodeToken -> err = ' + err) } + if (process.env.ERROR_LOG === true) { console.log('[ERROR] ' + MODULE_NAME + ' -> decodeToken -> err = ' + err) } callBackFunction(global.DEFAULT_FAIL_RESPONSE) } } diff --git a/server/src/globals.js b/server/src/globals.js index 22a40b8da..3a9aa2fae 100644 --- a/server/src/globals.js +++ b/server/src/globals.js @@ -1,31 +1,27 @@ -/* Debugging */ - -global.INFO_LOG = true; -global.ERROR_LOG = true; /* Callbacks default responses. */ global.DEFAULT_OK_RESPONSE = { - result: "Ok", - message: "Operation Succeeded" -}; + result: 'Ok', + message: 'Operation Succeeded' +} global.DEFAULT_FAIL_RESPONSE = { - result: "Fail", - message: "Operation Failed" -}; + result: 'Fail', + message: 'Operation Failed' +} global.DEFAULT_RETRY_RESPONSE = { - result: "Retry", - message: "Retry Later" -}; + result: 'Retry', + message: 'Retry Later' +} global.CUSTOM_OK_RESPONSE = { - result: "Ok, but check Message", - message: "Custom Message" -}; + result: 'Ok, but check Message', + message: 'Custom Message' +} global.CUSTOM_FAIL_RESPONSE = { - result: "Fail Because", - message: "Custom Message" -}; + result: 'Fail Because', + message: 'Custom Message' +} diff --git a/server/src/schema/schema.js b/server/src/schema/schema.js index 369feea87..6e7cdd49e 100644 --- a/server/src/schema/schema.js +++ b/server/src/schema/schema.js @@ -105,22 +105,22 @@ const RootQuery = new GraphQLObjectType({ resolve (parent, args) { // Code to get data from data source. - if (INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> RootQuery -> userByAuthId -> resolve -> Entering function.') } + if (process.env.INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> RootQuery -> userByAuthId -> resolve -> Entering function.') } /* In order to be able to wait for asyc calls to the database, we need to return a promise to GraphQL. */ const promiseToGraphQL = new Promise((resolve, reject) => { - if (INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> RootQuery -> userByAuthId -> resolve -> Promise -> Entering function.') } - if (INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> RootQuery -> userByAuthId -> resolve -> Promise -> args.authId = ' + args.authId) } + if (process.env.INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> RootQuery -> userByAuthId -> resolve -> Promise -> Entering function.') } + if (process.env.INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> RootQuery -> userByAuthId -> resolve -> Promise -> args.authId = ' + args.authId) } findUserByAuthId(args.authId, onUserFound) function onUserFound (err, responseToGraphQL) { - if (INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> RootQuery -> userByAuthId -> resolve -> Promise -> onUserFound -> Entering function.') } - if (INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> RootQuery -> userByAuthId -> resolve -> Promise -> onUserFound -> responseToGraphQL = ' + JSON.stringify(responseToGraphQL)) } + if (process.env.INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> RootQuery -> userByAuthId -> resolve -> Promise -> onUserFound -> Entering function.') } + if (process.env.INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> RootQuery -> userByAuthId -> resolve -> Promise -> onUserFound -> responseToGraphQL = ' + JSON.stringify(responseToGraphQL)) } if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - if (global.ERROR_LOG === true) { logger.error('[ERROR] ' + MODULE_NAME + ' -> RootQuery -> userByAuthId -> resolve -> Promise -> onUserFound -> err.message = ' + err.message) } + if (process.env.ERROR_LOG === true) { logger.error('[ERROR] ' + MODULE_NAME + ' -> RootQuery -> userByAuthId -> resolve -> Promise -> onUserFound -> err.message = ' + err.message) } reject(responseToGraphQL) } else { resolve(responseToGraphQL) @@ -155,7 +155,7 @@ const RootQuery = new GraphQLObjectType({ type: new GraphQLList(UserType), args: {alias: {type: GraphQLString}, firstName: {type: GraphQLString}, middleName: {type: GraphQLString}, lastName: {type: GraphQLString}}, resolve (parent, args) { - if (INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> RootQuery -> usersSearch -> resolve -> Entering function.') } + if (process.env.INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> RootQuery -> usersSearch -> resolve -> Entering function.') } let mongoQuery = { $or: [] } @@ -173,7 +173,7 @@ const RootQuery = new GraphQLObjectType({ type: new GraphQLList(DescendentType), args: {id: {type: GraphQLString}}, resolve (parent, args) { - if (INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> RootQuery -> descendents -> resolve -> Entering function.') } + if (process.env.INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> RootQuery -> descendents -> resolve -> Entering function.') } return User.find({referrerId: args.id}) } @@ -192,20 +192,20 @@ const Mutation = new GraphQLObjectType({ idToken: {type: new GraphQLNonNull(GraphQLString)} }, resolve (parent, args) { - if (INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> Mutation -> authenticate -> resolve -> Entering function.') } + if (process.env.INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> Mutation -> authenticate -> resolve -> Entering function.') } /* In order to be able to wait for asyc calls to the database, and authorization authority, we need to return a promise to GraphQL. */ const promiseToGraphQL = new Promise((resolve, reject) => { - if (INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> Mutation -> authenticate -> resolve -> Promise -> Entering function.') } + if (process.env.INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> Mutation -> authenticate -> resolve -> Promise -> Entering function.') } authenticate(args.idToken, onAuthenticated) function onAuthenticated (err, responseToGraphQL) { - if (INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> Mutation -> authenticate -> resolve -> Promise -> onAuthenticated -> Entering function.') } - if (INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> Mutation -> authenticate -> resolve -> Promise -> onAuthenticated -> responseToGraphQL = ' + JSON.stringify(responseToGraphQL)) } + if (process.env.INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> Mutation -> authenticate -> resolve -> Promise -> onAuthenticated -> Entering function.') } + if (process.env.INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> Mutation -> authenticate -> resolve -> Promise -> onAuthenticated -> responseToGraphQL = ' + JSON.stringify(responseToGraphQL)) } if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - if (global.ERROR_LOG === true) { logger.error('[ERROR] ' + MODULE_NAME + ' -> Mutation -> authenticate -> resolve -> Promise -> onAuthenticated -> err.message = ' + err.message) } + if (process.env.ERROR_LOG === true) { logger.error('[ERROR] ' + MODULE_NAME + ' -> Mutation -> authenticate -> resolve -> Promise -> onAuthenticated -> err.message = ' + err.message) } reject(responseToGraphQL) } else { resolve(responseToGraphQL) @@ -288,12 +288,12 @@ const Mutation = new GraphQLObjectType({ function findUserByAuthId (authId, callBackFunction) { try { - if (INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> findUserByAuthId -> Entering function.') } - if (INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> findUserByAuthId -> authId = ' + authId) } + if (process.env.INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> findUserByAuthId -> Entering function.') } + if (process.env.INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> findUserByAuthId -> authId = ' + authId) } if (authId === null || authId === undefined) { - if (INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> findUserByAuthId -> User requested not specified.') } - if (INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> findUserByAuthId -> args.authId = ' + authId) } + if (process.env.INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> findUserByAuthId -> User requested not specified.') } + if (process.env.INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> findUserByAuthId -> args.authId = ' + authId) } callBackFunction(global.DEFAULT_FAIL_RESPONSE, { error: 'Bad Request' }) return @@ -308,8 +308,8 @@ function findUserByAuthId (authId, callBackFunction) { callBackFunction(global.DEFAULT_FAIL_RESPONSE, { error: err }) } else { if (user === null) { - if (INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> findUserByAuthId -> onUserReceived -> User not found at Database.') } - if (INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> findUserByAuthId -> onUserReceived -> args.authId = ' + authId) } + if (process.env.INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> findUserByAuthId -> onUserReceived -> User not found at Database.') } + if (process.env.INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> findUserByAuthId -> onUserReceived -> args.authId = ' + authId) } let customResponse = { result: global.CUSTOM_OK_RESPONSE.result, @@ -321,15 +321,15 @@ function findUserByAuthId (authId, callBackFunction) { } if (user.authId === authId && user.authId !== undefined) { - if (INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> findUserByAuthId -> onUserReceived -> User found at Database.') } - if (INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> findUserByAuthId -> onUserReceived -> args.authId = ' + authId) } + if (process.env.INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> findUserByAuthId -> onUserReceived -> User found at Database.') } + if (process.env.INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> findUserByAuthId -> onUserReceived -> args.authId = ' + authId) } callBackFunction(global.DEFAULT_OK_RESPONSE, user) return } else { - if (INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> findUserByAuthId -> onUserReceived -> User found at Database is not the user requested.') } - if (INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> findUserByAuthId -> onUserReceived -> args.authId = ' + authId) } - if (INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> findUserByAuthId -> onUserReceived -> user.authId = ' + user.authId) } + if (process.env.INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> findUserByAuthId -> onUserReceived -> User found at Database is not the user requested.') } + if (process.env.INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> findUserByAuthId -> onUserReceived -> args.authId = ' + authId) } + if (process.env.INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> findUserByAuthId -> onUserReceived -> user.authId = ' + user.authId) } callBackFunction(global.DEFAULT_FAIL_RESPONSE, { error: err }) return @@ -337,14 +337,14 @@ function findUserByAuthId (authId, callBackFunction) { } } } catch (err) { - if (global.ERROR_LOG === true) { logger.error('[ERROR] ' + MODULE_NAME + ' -> findUserByAuthId -> err.message = ' + err.message) } + if (process.env.ERROR_LOG === true) { logger.error('[ERROR] ' + MODULE_NAME + ' -> findUserByAuthId -> err.message = ' + err.message) } callBackFunction(global.DEFAULT_FAIL_RESPONSE, { error: err }) } } function authenticate (encodedToken, callBackFunction) { try { - if (INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> authenticate -> Entering function.') } + if (process.env.INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> authenticate -> Entering function.') } let authId = '' let alias = '' @@ -354,10 +354,10 @@ function authenticate (encodedToken, callBackFunction) { tokenDecoder(encodedToken, onValidated) function onValidated (err, decodedToken) { - if (global.INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> authenticate -> onValidated -> Entering function.') } + if (process.env.INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> authenticate -> onValidated -> Entering function.') } if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - if (global.ERROR_LOG === true) { logger.error('[ERROR] ' + MODULE_NAME + ' -> authenticate -> onValidated -> err.message = ' + err.message) } + if (process.env.ERROR_LOG === true) { logger.error('[ERROR] ' + MODULE_NAME + ' -> authenticate -> onValidated -> err.message = ' + err.message) } callBackFunction(global.DEFAULT_FAIL_RESPONSE, { error: err }) return } @@ -377,18 +377,18 @@ function authenticate (encodedToken, callBackFunction) { findUserByAuthId(authId, onUserFound) function onUserFound (err, user) { - if (global.INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> authenticate -> onValidated -> onUserFound -> Entering function.') } + if (process.env.INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> authenticate -> onValidated -> onUserFound -> Entering function.') } if (err.result === global.DEFAULT_FAIL_RESPONSE.result) { - if (global.ERROR_LOG === true) { logger.error('[ERROR] ' + MODULE_NAME + ' -> authenticate -> onValidated -> onUserFound -> err.message = ' + err.message) } + if (process.env.ERROR_LOG === true) { logger.error('[ERROR] ' + MODULE_NAME + ' -> authenticate -> onValidated -> onUserFound -> err.message = ' + err.message) } callBackFunction(global.DEFAULT_FAIL_RESPONSE, { error: err }) return } if (err.result === global.DEFAULT_OK_RESPONSE.result) { - if (global.INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> authenticate -> onValidated -> onUserFound -> User already exists at database') } + if (process.env.INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> authenticate -> onValidated -> onUserFound -> User already exists at database') } - if (global.INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> authenticate -> onValidated -> onUserFound -> Existing User: ' + JSON.stringify(user)) } + if (process.env.INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> authenticate -> onValidated -> onUserFound -> Existing User: ' + JSON.stringify(user)) } callBackFunction(global.DEFAULT_OK_RESPONSE, { authId: authId, alias: user.alias }) return @@ -398,7 +398,7 @@ function authenticate (encodedToken, callBackFunction) { err.result === global.CUSTOM_OK_RESPONSE.result && err.message === 'User Not Found' ) { - if (global.INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> authenticate -> onValidated -> onUserFound -> User does not exist at database') } + if (process.env.INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> authenticate -> onValidated -> onUserFound -> User does not exist at database') } /* @@ -417,8 +417,8 @@ function authenticate (encodedToken, callBackFunction) { socialAccountProvider !== 'github' && socialAccountProvider !== 'auth0' ) { - if (global.ERROR_LOG === true) { logger.error('[ERROR] ' + MODULE_NAME + ' -> authenticate -> onValidated -> onUserFound -> Social Account Provider not Supoorted. ') } - if (global.ERROR_LOG === true) { logger.error('[ERROR] ' + MODULE_NAME + ' -> authenticate -> onValidated -> onUserFound -> socialAccountProvider = ' + socialAccountProvider) } + if (process.env.ERROR_LOG === true) { logger.error('[ERROR] ' + MODULE_NAME + ' -> authenticate -> onValidated -> onUserFound -> Social Account Provider not Supoorted. ') } + if (process.env.ERROR_LOG === true) { logger.error('[ERROR] ' + MODULE_NAME + ' -> authenticate -> onValidated -> onUserFound -> socialAccountProvider = ' + socialAccountProvider) } callBackFunction(global.DEFAULT_FAIL_RESPONSE, { error: err }) return @@ -436,20 +436,20 @@ function authenticate (encodedToken, callBackFunction) { roleId: '1' }) - if (global.INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> authenticate -> onValidated -> onUserFound -> ' + alias + ' being added to the database') } + if (process.env.INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> authenticate -> onValidated -> onUserFound -> ' + alias + ' being added to the database') } newUser.save(onSaved) function onSaved (err, savedUser) { - if (global.INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> authenticate -> onValidated -> onUserFound -> onSaved -> Entering function.') } + if (process.env.INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> authenticate -> onValidated -> onUserFound -> onSaved -> Entering function.') } if (err) { - if (global.ERROR_LOG === true) { logger.error('[ERROR] ' + MODULE_NAME + ' -> authenticate -> onValidated -> onUserFound -> onSaved -> err = ' + err) } + if (process.env.ERROR_LOG === true) { logger.error('[ERROR] ' + MODULE_NAME + ' -> authenticate -> onValidated -> onUserFound -> onSaved -> err = ' + err) } callBackFunction(global.DEFAULT_FAIL_RESPONSE, { error: err }) return } - if (global.INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> authenticate -> onValidated -> onUserFound -> onSaved -> Saved User: ' + JSON.stringify(savedUser)) } + if (process.env.INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> authenticate -> onValidated -> onUserFound -> onSaved -> Saved User: ' + JSON.stringify(savedUser)) } callBackFunction(global.DEFAULT_OK_RESPONSE, { authId, alias }) } @@ -457,7 +457,7 @@ function authenticate (encodedToken, callBackFunction) { } } } catch (err) { - if (global.ERROR_LOG === true) { logger.error('[ERROR] ' + MODULE_NAME + ' -> authenticate -> err.message = ' + err.message) } + if (process.env.ERROR_LOG === true) { logger.error('[ERROR] ' + MODULE_NAME + ' -> authenticate -> err.message = ' + err.message) } callBackFunction(global.DEFAULT_FAIL_RESPONSE, { error: err }) } }