Merge pull request #33 from Superalgos/develop
v1.0 Production Realease
This commit is contained in:
20 files changed
+266
-19598
No files matched your search
+3
-3
@@ -1,7 +1,7 @@
|
||||
|
||||
client/node_modules/*
|
||||
server/node_modules/*
|
||||
client/src/auth/Auth0.js
|
||||
server/auth/Auth0.js
|
||||
server/models/MongoDB.js
|
||||
server/.env
|
||||
|
||||
client/package-lock.json
|
||||
server/package-lock.json
|
||||
@@ -1,5 +1,6 @@
|
||||
const { createLogger, format, transports } = require('winston')
|
||||
import { createLogger, format, transports } from 'winston'
|
||||
const { combine, timestamp, simple } = format
|
||||
import { inspect } from 'util'
|
||||
|
||||
const options = {
|
||||
file: {
|
||||
@@ -23,11 +24,12 @@ const options = {
|
||||
|
||||
const logger = createLogger({
|
||||
level: 'info',
|
||||
format: combine(
|
||||
timestamp({
|
||||
format: 'YYYY-MM-DD HH:mm:ss'
|
||||
}),
|
||||
simple()
|
||||
format: format.combine(
|
||||
format.colorize(),
|
||||
format.timestamp({ format: 'YY/MM/DD HH:mm' }),
|
||||
format.printf(
|
||||
info => `${info.timestamp} - ${info.level}: ${JSON.parse(JSON.stringify(inspect(info.message)))}`
|
||||
)
|
||||
),
|
||||
transports: [
|
||||
new transports.File(options.file),
|
||||
@@ -36,4 +38,4 @@ const logger = createLogger({
|
||||
exitOnError: false // do not exit on handled exceptions
|
||||
})
|
||||
|
||||
module.exports = logger
|
||||
export default logger
|
||||
Generated
-15329
File diff suppressed because it is too large.
Load diff
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@advancedalgos/users-client",
|
||||
"description": "Advanced Algos Users client-side web app",
|
||||
"version": "0.0.22",
|
||||
"version": "0.0.24",
|
||||
"main": "src/index.js",
|
||||
"dependencies": {
|
||||
"@material-ui/core": "^3.2.0",
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import React, { Component } from 'react'
|
||||
import BannerTopBar from './BannerTopBar'
|
||||
import { Typography } from '@material-ui/core'
|
||||
|
||||
class Home extends Component {
|
||||
|
||||
@@ -12,6 +13,26 @@ class Home extends Component {
|
||||
text='Responsible for all human users of the Advanced Algos Platform.'
|
||||
backgroundUrl='https://advancedalgos.net/img/photos/users.jpg'
|
||||
/>
|
||||
<div className='homePage container'>
|
||||
<Typography variant='h1' align='center' className='title'>Welcome to the Users Module!</Typography>
|
||||
<Typography variant='h2' align='center' className='subtitle'>The human component of the Advanced Algos Ecosystem.</Typography>
|
||||
<div className='column'>
|
||||
<Typography align='justify'>
|
||||
The Advanced Algos Ecosystem is made out of humans, financial beings and other entities such as teams.
|
||||
</Typography>
|
||||
<Typography align='justify'>
|
||||
Humans are either <strong>users</strong> or <strong>guests</strong>. If you haven’t signed up yet or you are logged off, then you are acting as a guest, with limited features. Please sign-up or log-in for a richer experience.
|
||||
</Typography>
|
||||
</div>
|
||||
<div className='column'>
|
||||
<Typography align='justify'>
|
||||
Users may have different roles, such as developer, trader, analyst, etc. Each of these roles usually have personalized features throughout the system.
|
||||
</Typography>
|
||||
<Typography align='justify'>
|
||||
The Users Module allows you to handle all of your details as a user of the system as well as finding other people in the ecosystem.
|
||||
</Typography>
|
||||
</div>
|
||||
</div>
|
||||
</React.Fragment>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -44,6 +44,8 @@ const styles = theme => ({
|
||||
flex: 1
|
||||
},
|
||||
grid: {
|
||||
width: '80%',
|
||||
marginLeft: '10%',
|
||||
paddingTop: '30',
|
||||
marginTop: 30
|
||||
},
|
||||
|
||||
+20
-1
@@ -1 +1,20 @@
|
||||
PRESHARED_GATEWAY_KEY=SHARED_KEY
|
||||
NODE_ENV=development
|
||||
|
||||
VIRTUAL_HOST=users-api.advancedalgos.net
|
||||
VIRTUAL_PORT=4000
|
||||
|
||||
PORT=4000
|
||||
|
||||
DB_USERNAME=
|
||||
DB_PASSWORD=
|
||||
DB_DOMAIN=
|
||||
|
||||
GATEWAY_ENDPOINT=http://localhost:4100/graphql
|
||||
USERS_API_PRESHARED=
|
||||
|
||||
AUTH0_DOMAIN=
|
||||
AUTH0_AUDIENCE=
|
||||
AUTH0_ISSUER=
|
||||
AUTH0_CLIENTID=
|
||||
AUTH0_CALLBACK_URL=
|
||||
AUTH0_LOGOUT_URL=
|
||||
@@ -1,63 +0,0 @@
|
||||
|
||||
/* This module imports */
|
||||
|
||||
const globals = require('./globals')
|
||||
const sessions = require('./sessions')
|
||||
const express = require('express')
|
||||
const graphqlHTTP = require('express-graphql')
|
||||
const schema = require('./schema/schema')
|
||||
const mongoose = require('mongoose')
|
||||
const mongodbConfig = require('./models/MongoDB')
|
||||
const checkJwt = require('./auth/middleware/jwt')
|
||||
const logger = require('./utils/logger')
|
||||
const wrongPreshared = require('./errors/notAllowed.json')
|
||||
const cors = require('cors')
|
||||
|
||||
require('dotenv').config()
|
||||
|
||||
const app = express()
|
||||
|
||||
// Checking preshared key
|
||||
app.post('/graphql', (req, res, next) => {
|
||||
if (req.headers.preshared === process.env.PRESHARED_GATEWAY_KEY) {
|
||||
next()
|
||||
} else {
|
||||
res.send(wrongPreshared)
|
||||
}
|
||||
})
|
||||
|
||||
// Allow crosss-origin requests
|
||||
app.use(cors())
|
||||
|
||||
// Connect to the database
|
||||
mongoose.connect(mongodbConfig.connectionString, { useNewUrlParser: true })
|
||||
mongoose.connection.once('open', () => {
|
||||
logger.info('Connected to Mongo')
|
||||
})
|
||||
|
||||
/* Here we bind all requests to this endpoint to be procecced by the GraphQL Library. */
|
||||
|
||||
app.get('/graphql', graphqlHTTP({
|
||||
schema,
|
||||
graphiql: true
|
||||
}))
|
||||
|
||||
app.post('/graphql', graphqlHTTP(req => {
|
||||
return {
|
||||
schema,
|
||||
graphiql: false,
|
||||
context: {
|
||||
user: req.user,
|
||||
userId: req.headers.userid
|
||||
}
|
||||
}
|
||||
}))
|
||||
|
||||
app.post('/graphql', checkJwt, (err, req, res, next) => {
|
||||
if (err) return res.status(401).send(`[Authenticate Token Error] ${err.message}`)
|
||||
next()
|
||||
})
|
||||
|
||||
app.listen(4000, () => {
|
||||
logger.info('Now listening for requests on port 4000')
|
||||
})
|
||||
@@ -1,31 +0,0 @@
|
||||
/* Debugging */
|
||||
|
||||
global.INFO_LOG = true;
|
||||
global.ERROR_LOG = true;
|
||||
|
||||
/* Callbacks default responses. */
|
||||
|
||||
global.DEFAULT_OK_RESPONSE = {
|
||||
result: "Ok",
|
||||
message: "Operation Succeeded"
|
||||
};
|
||||
|
||||
global.DEFAULT_FAIL_RESPONSE = {
|
||||
result: "Fail",
|
||||
message: "Operation Failed"
|
||||
};
|
||||
|
||||
global.DEFAULT_RETRY_RESPONSE = {
|
||||
result: "Retry",
|
||||
message: "Retry Later"
|
||||
};
|
||||
|
||||
global.CUSTOM_OK_RESPONSE = {
|
||||
result: "Ok, but check Message",
|
||||
message: "Custom Message"
|
||||
};
|
||||
|
||||
global.CUSTOM_FAIL_RESPONSE = {
|
||||
result: "Fail Because",
|
||||
message: "Custom Message"
|
||||
};
|
||||
Generated
-4073
File diff suppressed because it is too large.
Load diff
+10
-4
@@ -1,16 +1,23 @@
|
||||
{
|
||||
"name": "server",
|
||||
"version": "1.0.0",
|
||||
"description": "Advanced Algos Users Backedn API",
|
||||
"main": "app.js",
|
||||
"description": "Advanced Algos Users backend API",
|
||||
"main": "src/index.js",
|
||||
"scripts": {
|
||||
"start": "nodemon --exec babel-node --presets env,stage-2 src/index.js",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"babel-cli": "^6.26.0",
|
||||
"babel-preset-env": "^1.7.0",
|
||||
"babel-preset-stage-2": "^6.24.1",
|
||||
"nodemon": "^1.18.10"
|
||||
},
|
||||
"dependencies": {
|
||||
"cors": "^2.8.4",
|
||||
"dotenv": "^6.1.0",
|
||||
"dotenv": "^6.0.0",
|
||||
"express": "^4.16.3",
|
||||
"express-graphql": "^0.6.12",
|
||||
"express-jwt": "^5.3.1",
|
||||
@@ -19,7 +26,6 @@
|
||||
"jwks-rsa": "^1.3.0",
|
||||
"lodash": "^4.17.10",
|
||||
"mongoose": "^5.2.12",
|
||||
"npm": "^6.4.1",
|
||||
"winston": "^3.1.0"
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
const jwt = require('express-jwt');
|
||||
const jwksRsa = require('jwks-rsa');
|
||||
const AUTH_CONFIG = require('../Auth0');
|
||||
|
||||
const jwt = require('express-jwt')
|
||||
const jwksRsa = require('jwks-rsa')
|
||||
|
||||
// Authentication middleware. When used, the
|
||||
// if the access token exists, it be verified against
|
||||
// the Auth0 JSON Web Key Set
|
||||
@@ -12,14 +13,14 @@ const checkJwt = jwt({
|
||||
cache: true,
|
||||
rateLimit: true,
|
||||
jwksRequestsPerMinute: 1,
|
||||
jwksUri: `https://${AUTH_CONFIG.domain}/.well-known/jwks.json`
|
||||
jwksUri: `https://${process.env.AUTH0_DOMAIN}/.well-known/jwks.json`
|
||||
}),
|
||||
|
||||
// Validate the audience and the issuer.
|
||||
credentialsRequired: false,
|
||||
audience: AUTH_CONFIG.api_audience,
|
||||
issuer: AUTH_CONFIG.issuer,
|
||||
audience: process.env.AUTH0_AUDIENCE,
|
||||
issuer: process.env.AUTH0_ISSUER,
|
||||
algorithms: [`RS256`]
|
||||
});
|
||||
})
|
||||
|
||||
module.exports = checkJwt ;
|
||||
module.exports = checkJwt
|
||||
@@ -13,19 +13,16 @@ const MODULE_NAME = 'token-decoder'
|
||||
const JSONWebToken = require('jsonwebtoken') // A library to deal with JSON Web Tokens.
|
||||
const webTokenLibrary = require('jwks-rsa') // A library to retrieve RSA signing keys from a JWKS (JSON Web Key Set) endpoint.
|
||||
|
||||
const AUTH_CONFIG = require('./Auth0') // Config where we have our secrets.
|
||||
const logger = require('../utils/logger')
|
||||
|
||||
const decoder = webTokenLibrary({
|
||||
cache: true,
|
||||
rateLimit: true,
|
||||
jwksRequestsPerMinute: 1,
|
||||
jwksUri: `https://${AUTH_CONFIG.domain}/.well-known/jwks.json`
|
||||
jwksUri: `https://${process.env.AUTH0_DOMAIN}/.well-known/jwks.json`
|
||||
})
|
||||
|
||||
function decodeToken (token, callBackFunction) {
|
||||
try {
|
||||
if (global.INFO_LOG === true) { logger.info('[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
|
||||
@@ -36,8 +33,8 @@ function decodeToken (token, callBackFunction) {
|
||||
header.kid === null ||
|
||||
payload === null
|
||||
) {
|
||||
if (global.ERROR_LOG === true) { logger.error('[ERROR] ' + MODULE_NAME + ' -> decodeToken -> Invalid Token. ') }
|
||||
if (global.ERROR_LOG === true) { logger.error('[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
|
||||
}
|
||||
@@ -45,12 +42,12 @@ function decodeToken (token, callBackFunction) {
|
||||
decoder.getSigningKey(header.kid, onKeyReady)
|
||||
|
||||
function onKeyReady (err, key) {
|
||||
if (global.INFO_LOG === true) { logger.info('[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) { logger.error('[ERROR] ' + MODULE_NAME + ' -> decodeToken -> onKeyReady -> Error getting the key. ') }
|
||||
if (global.ERROR_LOG === true) { logger.error('[ERROR] ' + MODULE_NAME + ' -> decodeToken -> onKeyReady -> key = ' + key) }
|
||||
if (global.ERROR_LOG === true) { logger.error('[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
|
||||
}
|
||||
@@ -62,12 +59,12 @@ function decodeToken (token, callBackFunction) {
|
||||
onVerified)
|
||||
|
||||
function onVerified (err, decoded) {
|
||||
if (global.INFO_LOG === true) { logger.info('[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) { logger.error('[ERROR] ' + MODULE_NAME + ' -> decodeToken -> onKeyReady -> onVerified -> Error verifying. ') }
|
||||
if (global.ERROR_LOG === true) { logger.error('[ERROR] ' + MODULE_NAME + ' -> decodeToken -> onKeyReady -> onVerified -> decoded = ' + decoded) }
|
||||
if (global.ERROR_LOG === true) { logger.error('[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
|
||||
}
|
||||
@@ -76,7 +73,7 @@ function decodeToken (token, callBackFunction) {
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
if (global.ERROR_LOG === true) { logger.error('[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)
|
||||
}
|
||||
}
|
||||
File renamed without changes.
@@ -0,0 +1,27 @@
|
||||
|
||||
/* Callbacks default responses. */
|
||||
|
||||
global.DEFAULT_OK_RESPONSE = {
|
||||
result: 'Ok',
|
||||
message: 'Operation Succeeded'
|
||||
}
|
||||
|
||||
global.DEFAULT_FAIL_RESPONSE = {
|
||||
result: 'Fail',
|
||||
message: 'Operation Failed'
|
||||
}
|
||||
|
||||
global.DEFAULT_RETRY_RESPONSE = {
|
||||
result: 'Retry',
|
||||
message: 'Retry Later'
|
||||
}
|
||||
|
||||
global.CUSTOM_OK_RESPONSE = {
|
||||
result: 'Ok, but check Message',
|
||||
message: 'Custom Message'
|
||||
}
|
||||
|
||||
global.CUSTOM_FAIL_RESPONSE = {
|
||||
result: 'Fail Because',
|
||||
message: 'Custom Message'
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
|
||||
/* This module imports */
|
||||
|
||||
import 'dotenv/config'
|
||||
import './globals'
|
||||
import logger from './logger'
|
||||
import express from 'express'
|
||||
import graphqlHTTP from 'express-graphql'
|
||||
import schema from './schema/schema'
|
||||
import mongoose from 'mongoose'
|
||||
import checkJwt from './auth/jwt'
|
||||
import wrongPreshared from './errors/notAllowed.json'
|
||||
import cors from 'cors'
|
||||
|
||||
require('dotenv').config()
|
||||
|
||||
const app = express()
|
||||
|
||||
// Checking preshared key
|
||||
app.post('/graphql', (req, res, next) => {
|
||||
if (req.headers.preshared === process.env.USERS_API_PRESHARED) {
|
||||
next()
|
||||
} else {
|
||||
logger.error('Wrong Pre-Shared Received', req.headers.preshared)
|
||||
res.send(wrongPreshared)
|
||||
}
|
||||
})
|
||||
|
||||
// Allow crosss-origin requests
|
||||
app.use(cors())
|
||||
|
||||
// Database Connection
|
||||
mongoose.connect(`mongodb://${process.env.DB_USERNAME}:${process.env.DB_PASSWORD}@${process.env.DB_DOMAIN}`, { useNewUrlParser: true })
|
||||
|
||||
mongoose.connection.once('open', () => {
|
||||
logger.info('Connected to the DB.')
|
||||
})
|
||||
|
||||
/* Here we bind all requests to this endpoint to be procecced by the GraphQL Library. */
|
||||
|
||||
app.get('/graphql', graphqlHTTP({
|
||||
schema,
|
||||
graphiql: true
|
||||
}))
|
||||
|
||||
app.post('/graphql', graphqlHTTP(req => {
|
||||
return {
|
||||
schema,
|
||||
graphiql: false,
|
||||
context: {
|
||||
user: req.user,
|
||||
userId: req.headers.userid
|
||||
}
|
||||
}
|
||||
}))
|
||||
|
||||
app.post('/graphql', checkJwt, (err, req, res, next) => {
|
||||
if (err) return res.status(401).send(`[Authenticate Token Error] ${err.message}`)
|
||||
next()
|
||||
})
|
||||
|
||||
app.listen(4000, () => {
|
||||
logger.info('Now listening for requests on port 4000')
|
||||
})
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
import { createLogger, format, transports } from 'winston'
|
||||
const { combine, timestamp, simple } = format
|
||||
import { inspect } from 'util'
|
||||
|
||||
const options = {
|
||||
file: {
|
||||
level: 'info',
|
||||
filename: '../logs/app.log',
|
||||
handleExceptions: true,
|
||||
json: true,
|
||||
maxsize: 5242880, // 5MB
|
||||
maxFiles: 5,
|
||||
colorize: false,
|
||||
timestamp: true
|
||||
},
|
||||
console: {
|
||||
level: 'debug',
|
||||
handleExceptions: true,
|
||||
json: false,
|
||||
colorize: true,
|
||||
timestamp: true
|
||||
}
|
||||
}
|
||||
|
||||
const logger = createLogger({
|
||||
level: 'info',
|
||||
format: format.combine(
|
||||
format.colorize(),
|
||||
format.timestamp({ format: 'YY/MM/DD HH:mm' }),
|
||||
format.printf(
|
||||
info => `${info.timestamp} - ${info.level}: ${JSON.parse(JSON.stringify(inspect(info.message)))}`
|
||||
)
|
||||
),
|
||||
transports: [
|
||||
new transports.File(options.file),
|
||||
new transports.Console(options.console)
|
||||
],
|
||||
exitOnError: false // do not exit on handled exceptions
|
||||
})
|
||||
|
||||
export default logger
|
||||
File renamed without changes.
@@ -1,10 +1,11 @@
|
||||
const MODULE_NAME = 'schema'
|
||||
|
||||
import logger from '../logger'
|
||||
import _ from 'lodash'
|
||||
import User from '../models/user'
|
||||
import tokenDecoder from '../auth/token-decoder'
|
||||
|
||||
const graphql = require('graphql')
|
||||
const _ = require('lodash')
|
||||
const User = require('../models/user')
|
||||
const logger = require('../utils/logger')
|
||||
const tokenDecoder = require('../auth/token-decoder')
|
||||
|
||||
const {
|
||||
GraphQLObjectType,
|
||||
@@ -104,22 +105,22 @@ const RootQuery = new GraphQLObjectType({
|
||||
resolve (parent, args) {
|
||||
// Code to get data from data source.
|
||||
|
||||
if (INFO_LOG === true) { logger.info('[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.info('[INFO] ' + MODULE_NAME + ' -> RootQuery -> userByAuthId -> resolve -> Promise -> Entering function.') }
|
||||
if (INFO_LOG === true) { logger.info('[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.info('[INFO] ' + MODULE_NAME + ' -> RootQuery -> userByAuthId -> resolve -> Promise -> onUserFound -> Entering function.') }
|
||||
if (INFO_LOG === true) { logger.info('[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)
|
||||
@@ -154,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.info('[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: [] }
|
||||
|
||||
@@ -172,7 +173,7 @@ const RootQuery = new GraphQLObjectType({
|
||||
type: new GraphQLList(DescendentType),
|
||||
args: {id: {type: GraphQLString}},
|
||||
resolve (parent, args) {
|
||||
if (INFO_LOG === true) { logger.info('[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})
|
||||
}
|
||||
@@ -191,20 +192,20 @@ const Mutation = new GraphQLObjectType({
|
||||
idToken: {type: new GraphQLNonNull(GraphQLString)}
|
||||
},
|
||||
resolve (parent, args) {
|
||||
if (INFO_LOG === true) { logger.info('[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.info('[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.info('[INFO] ' + MODULE_NAME + ' -> Mutation -> authenticate -> resolve -> Promise -> onAuthenticated -> Entering function.') }
|
||||
if (INFO_LOG === true) { logger.info('[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)
|
||||
@@ -287,12 +288,12 @@ const Mutation = new GraphQLObjectType({
|
||||
|
||||
function findUserByAuthId (authId, callBackFunction) {
|
||||
try {
|
||||
if (INFO_LOG === true) { logger.info('[INFO] ' + MODULE_NAME + ' -> findUserByAuthId -> Entering function.') }
|
||||
if (INFO_LOG === true) { logger.info('[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.info('[INFO] ' + MODULE_NAME + ' -> findUserByAuthId -> User requested not specified.') }
|
||||
if (INFO_LOG === true) { logger.info('[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
|
||||
@@ -307,8 +308,8 @@ function findUserByAuthId (authId, callBackFunction) {
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE, { error: err })
|
||||
} else {
|
||||
if (user === null) {
|
||||
if (INFO_LOG === true) { logger.info('[INFO] ' + MODULE_NAME + ' -> findUserByAuthId -> onUserReceived -> User not found at Database.') }
|
||||
if (INFO_LOG === true) { logger.info('[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,
|
||||
@@ -320,15 +321,15 @@ function findUserByAuthId (authId, callBackFunction) {
|
||||
}
|
||||
|
||||
if (user.authId === authId && user.authId !== undefined) {
|
||||
if (INFO_LOG === true) { logger.info('[INFO] ' + MODULE_NAME + ' -> findUserByAuthId -> onUserReceived -> User found at Database.') }
|
||||
if (INFO_LOG === true) { logger.info('[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.info('[INFO] ' + MODULE_NAME + ' -> findUserByAuthId -> onUserReceived -> User found at Database is not the user requested.') }
|
||||
if (INFO_LOG === true) { logger.info('[INFO] ' + MODULE_NAME + ' -> findUserByAuthId -> onUserReceived -> args.authId = ' + authId) }
|
||||
if (INFO_LOG === true) { logger.info('[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
|
||||
@@ -336,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.info('[INFO] ' + MODULE_NAME + ' -> authenticate -> Entering function.') }
|
||||
if (process.env.INFO_LOG === true) { logger.debug('[INFO] ' + MODULE_NAME + ' -> authenticate -> Entering function.') }
|
||||
|
||||
let authId = ''
|
||||
let alias = ''
|
||||
@@ -353,10 +354,10 @@ function authenticate (encodedToken, callBackFunction) {
|
||||
tokenDecoder(encodedToken, onValidated)
|
||||
|
||||
function onValidated (err, decodedToken) {
|
||||
if (global.INFO_LOG === true) { logger.info('[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
|
||||
}
|
||||
@@ -376,27 +377,18 @@ function authenticate (encodedToken, callBackFunction) {
|
||||
findUserByAuthId(authId, onUserFound)
|
||||
|
||||
function onUserFound (err, user) {
|
||||
if (global.INFO_LOG === true) { logger.info('[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.info('[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.info('[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)
|
||||
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
|
||||
@@ -406,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.info('[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') }
|
||||
|
||||
/*
|
||||
|
||||
@@ -425,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
|
||||
@@ -444,29 +436,20 @@ function authenticate (encodedToken, callBackFunction) {
|
||||
roleId: '1'
|
||||
})
|
||||
|
||||
if (global.INFO_LOG === true) { logger.info('[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.info('[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.info('[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)
|
||||
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 })
|
||||
}
|
||||
@@ -474,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 })
|
||||
}
|
||||
}
|
||||
File renamed without changes.
Reference in new issue
Block a user