fix some minor eslint errors
This commit is contained in:
parent
e18a5e0941
commit
2bdd682771
3 changed files with 15 additions and 14 deletions
|
@ -1,8 +1,8 @@
|
||||||
const passport = require('passport');
|
const passport = require('passport');
|
||||||
const GitHubStrategy = require('passport-github').Strategy;
|
// const GitHubStrategy = require('passport-github').Strategy;
|
||||||
const LocalStrategy = require('passport-local').Strategy;
|
const LocalStrategy = require('passport-local').Strategy;
|
||||||
|
|
||||||
import User from '../models/user'
|
import User from '../models/user';
|
||||||
|
|
||||||
passport.serializeUser((user, done) => {
|
passport.serializeUser((user, done) => {
|
||||||
done(null, user.id);
|
done(null, user.id);
|
||||||
|
@ -18,11 +18,11 @@ passport.deserializeUser((id, done) => {
|
||||||
* Sign in using Email and Password.
|
* Sign in using Email and Password.
|
||||||
*/
|
*/
|
||||||
passport.use(new LocalStrategy({ usernameField: 'email' }, (email, password, done) => {
|
passport.use(new LocalStrategy({ usernameField: 'email' }, (email, password, done) => {
|
||||||
User.findOne({ email: email.toLowerCase() }, (err, user) => {
|
User.findOne({ email: email.toLowerCase() }, (err, user) => { // eslint-disable-line consistent-return
|
||||||
if (!user) {
|
if (!user) {
|
||||||
return done(null, false, { msg: `Email ${email} not found.` });
|
return done(null, false, { msg: `Email ${email} not found.` });
|
||||||
}
|
}
|
||||||
user.comparePassword(password, (err, isMatch) => {
|
user.comparePassword(password, (innerErr, isMatch) => {
|
||||||
if (isMatch) {
|
if (isMatch) {
|
||||||
return done(null, user);
|
return done(null, user);
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ passport.use(new LocalStrategy({ usernameField: 'email' }, (email, password, don
|
||||||
/**
|
/**
|
||||||
* Sign in with GitHub.
|
* Sign in with GitHub.
|
||||||
*/
|
*/
|
||||||
//TODO add dotenv so I can add github login
|
// TODO add github login
|
||||||
// passport.use(new GitHubStrategy({
|
// passport.use(new GitHubStrategy({
|
||||||
// clientID: process.env.GITHUB_ID,
|
// clientID: process.env.GITHUB_ID,
|
||||||
// clientSecret: process.env.GITHUB_SECRET,
|
// clientSecret: process.env.GITHUB_SECRET,
|
||||||
|
|
|
@ -15,15 +15,15 @@ const userSchema = new Schema({
|
||||||
/**
|
/**
|
||||||
* Password hash middleware.
|
* Password hash middleware.
|
||||||
*/
|
*/
|
||||||
userSchema.pre('save', function (next) {
|
userSchema.pre('save', function checkPassword(next) { // eslint-disable-line consistent-return
|
||||||
const user = this;
|
const user = this;
|
||||||
if (!user.isModified('password')) { return next(); }
|
if (!user.isModified('password')) { return next(); }
|
||||||
bcrypt.genSalt(10, (err, salt) => {
|
bcrypt.genSalt(10, (err, salt) => { // eslint-disable-line consistent-return
|
||||||
if (err) { return next(err); }
|
|
||||||
bcrypt.hash(user.password, salt, null, (err, hash) => {
|
|
||||||
if (err) { return next(err); }
|
if (err) { return next(err); }
|
||||||
|
bcrypt.hash(user.password, salt, null, (innerErr, hash) => {
|
||||||
|
if (innerErr) { return next(innerErr); }
|
||||||
user.password = hash;
|
user.password = hash;
|
||||||
next();
|
return next();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -31,7 +31,7 @@ userSchema.pre('save', function (next) {
|
||||||
/**
|
/**
|
||||||
* Helper method for validating user's password.
|
* Helper method for validating user's password.
|
||||||
*/
|
*/
|
||||||
userSchema.methods.comparePassword = function (candidatePassword, cb) {
|
userSchema.methods.comparePassword = function comparePassword(candidatePassword, cb) {
|
||||||
// userSchema.methods.comparePassword = (candidatePassword, cb) => {
|
// userSchema.methods.comparePassword = (candidatePassword, cb) => {
|
||||||
bcrypt.compare(candidatePassword, this.password, (err, isMatch) => {
|
bcrypt.compare(candidatePassword, this.password, (err, isMatch) => {
|
||||||
cb(err, isMatch);
|
cb(err, isMatch);
|
||||||
|
|
|
@ -58,7 +58,8 @@ app.use('/api', projects);
|
||||||
app.use('/', serverRoutes);
|
app.use('/', serverRoutes);
|
||||||
|
|
||||||
// configure passport
|
// configure passport
|
||||||
const passportConfig = require('./config/passport');
|
require('./config/passport');
|
||||||
|
// const passportConfig = require('./config/passport');
|
||||||
|
|
||||||
// Connect to MongoDB
|
// Connect to MongoDB
|
||||||
// mongoose.connect(process.env.MONGODB_URI || process.env.MONGOLAB_URI);
|
// mongoose.connect(process.env.MONGODB_URI || process.env.MONGOLAB_URI);
|
||||||
|
|
Loading…
Reference in a new issue