Last active
November 13, 2017 20:23
-
-
Save jaywon/b5c430c2becc1e1ba19ee06bc475f909 to your computer and use it in GitHub Desktop.
Just Another Way
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const allowedStatus = ['artist', 'client', 'shop']; | |
const authorizeUser = (req, res, next) => { | |
let Model; | |
if(!allowedStatus.includes(req.body.status)){ | |
res.status(422).json("Credentials don't match"); | |
} | |
if(req.body.status === 'artist'){ | |
Model = Artist; | |
} | |
if(req.body.status === 'client'){ | |
Model = Client; | |
} | |
if(req.body.status === 'shop'){ | |
Model = Shop; | |
} | |
Model.findOne({username: req.body.username}) | |
.exec((err, user) => { | |
if(err) return res.status(401); | |
const token; //token conversion logic here | |
req.token = token; | |
}); | |
} | |
const signup = (req, res) => { | |
//just do your biz, status type has already been validated and assigned to req. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment