Refactoring Names during the check user process

This commit is contained in:
Luis Fernando Molina committed 2018-09-14 11:24:19 +02:00
1 parent 03f3b1694c
commit 96202ff439
2 files changed
+30 -24

No files matched your search

+24 -24
View File
@@ -1,27 +1,27 @@
/* 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 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 checkJwt = require('./auth/middleware/jwt');
const getUser = require('./auth/middleware/get-user');
const checkJwt = require('./auth/middleware/jwt')
const checkUser = require('./auth/middleware/check-user')
const cors = require('cors');
const cors = require('cors')
const app = express();
const app = express()
// Allow crosss-origin requests
app.use(cors());
app.use(cors())
// Connect to the database
mongoose.connect('mongodb://users-module-graphql-server:dsadTRYUtrsgg34@ds141952.mlab.com:41952/users', { useNewUrlParser: true });
mongoose.connect('mongodb://users-module-graphql-server:dsadTRYUtrsgg34@ds141952.mlab.com:41952/users', { useNewUrlParser: true })
mongoose.connection.once('open', () => {
console.log('Connected to database');
console.log('Connected to database')
})
/* Here we bind all requests to this endpoint to be procecced by the GraphQL Library. */
@@ -29,23 +29,23 @@ mongoose.connection.once('open', () => {
app.get('/graphql', graphqlHTTP({
schema,
graphiql: true
}));
}))
app.post('/graphql', graphqlHTTP({
schema,
graphiql: false,
context: req => ({ ...req })
}));
}))
app.post('/graphql', checkJwt, (err, req, res, next) => {
console.log(req);
if (err) return res.status(401).send(`[Authenticate Token Error] ${err.message}`);
next();
}
);
console.log(req)
if (err) return res.status(401).send(`[Authenticate Token Error] ${err.message}`)
next()
}
)
app.post('/graphql', (req, res, done) => getUser(req, res, done));
app.post('/graphql', (req, res, done) => checkUser(req, res, done))
app.listen(4000,() => {
console.log('Now listening for requests on port 4000');
});
app.listen(4000, () => {
console.log('Now listening for requests on port 4000')
})
@@ -1,3 +1,9 @@
/*
We check here if the User that have just logged in or signed up already exists at
the Mongo DB Database or not. If now then we should create it with the minimun
set of information available.
*/
const UserMongo = require('./add-user')
const getUser = async (req, res, next) => {