Cleaning out all unnecesary code for checking if a user was already at the database
This commit is contained in:
1 parent
96202ff439
commit
5fb4b06b8b
3 files changed
+1
-43
No files matched your search
+1
-5
@@ -9,7 +9,6 @@ const schema = require('./schema/schema')
|
||||
const mongoose = require('mongoose')
|
||||
|
||||
const checkJwt = require('./auth/middleware/jwt')
|
||||
const checkUser = require('./auth/middleware/check-user')
|
||||
|
||||
const cors = require('cors')
|
||||
|
||||
@@ -41,10 +40,7 @@ app.post('/graphql', checkJwt, (err, req, res, next) => {
|
||||
console.log(req)
|
||||
if (err) return res.status(401).send(`[Authenticate Token Error] ${err.message}`)
|
||||
next()
|
||||
}
|
||||
)
|
||||
|
||||
app.post('/graphql', (req, res, done) => checkUser(req, res, done))
|
||||
})
|
||||
|
||||
app.listen(4000, () => {
|
||||
console.log('Now listening for requests on port 4000')
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
/*
|
||||
This is how Users are added to the User collection on Mongo DB.
|
||||
Note that only the authId and alias is saved during user creation.
|
||||
This means that this should only be executed from within the authentication
|
||||
process.
|
||||
*/
|
||||
|
||||
const mongoose = require('mongoose')
|
||||
|
||||
const UserSchema = require('../../models/User')
|
||||
|
||||
class UserMongo {
|
||||
addUser ({ authId, alias }) {
|
||||
return UserSchema.create({
|
||||
authId: String,
|
||||
alias: String
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = UserMongo
|
||||
@@ -1,17 +0,0 @@
|
||||
/*
|
||||
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) => {
|
||||
if (!req.user) return next()
|
||||
const { sub, nickname } = req.user
|
||||
return UserMongo.addUser({ authid: sub, alias: nickname })
|
||||
req.user = { token: req.user, ...user }
|
||||
next()
|
||||
}
|
||||
|
||||
module.exports = getUser
|
||||
Reference in new issue
Block a user