I keep getting a SyntaxError: Unexpected token )'
error for the following code:
const bCrypt = require('bcrypt-nodejs');
const LocalStrategy = require('passport-local').Strategy;
module.exports = (passport, user) => {
const User = user;
passport.use(
'local-signup',
new LocalStrategy({
usernameField: 'email',
passwordField: 'password',
passReqToCallback: true, // pass back req to callback
},
(req, email, password, done) => {
const generateHash = password => bCrypt.hashSync(password, bCrypt.genSaltSync(8), null);
User.findOne({
where: {
email,
},
}).then(user => {
if (user) {
return done(null, false, {
message: 'That email is already taken',
});
}
const userPassword = generateHash(password);
const data = {
email,
username: req.body.username,
password: userPassword,
};
User.create(data).then((newUser) => !newUser ? done(null, false) : done(null, newUser));
// creates user, callback with user that exists or false if something went wrong
});
},
),
);
};
It really only started after I put arrow functions in. I think I'm missing something syntax-wise. I'm using the airbnb style guide & linter btw. Running node lts. VS Code doesn't give any parsing errors either in the editor itself. This is the error log in the terminal:
Also, this line in the terminal: at require (internal/module.js:20:19) at Object.<anonymous> (/Users/Rishi/www/Courses/bootcamp/blogapp/app/routes/home.js:8:1)
EDIT -- The code works when transpiled to ES2015 via Babel. I'm still curious why it isn't working with the ES6 syntax.
via Rishi Speets
No comments:
Post a Comment