Skip to content

Instantly share code, notes, and snippets.

@jaywon
Last active November 13, 2017 20:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaywon/b5c430c2becc1e1ba19ee06bc475f909 to your computer and use it in GitHub Desktop.
Save jaywon/b5c430c2becc1e1ba19ee06bc475f909 to your computer and use it in GitHub Desktop.
Just Another Way
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