passport.use(new LocalStrategy({ usernameField: 'userName', passwordField: 'password' }, function (username, password, done) { User.find({ 'username': username }, {}, function (err, results) { if (err) { console.log(`*** getBookById error: ${err}`); } if (results.password === password) { var user = results; done(null, user); } else { done(null, false, {message: 'Bad password'}); } }); }));
passport.use( new BasicStrategy(async (email, password, cb) => { const user = (await db.query('SELECT * FROM account WHERE email=$1', [ email ])).rows[0] if (!user) return cb(null, false) if (!user.activated) return cb(null, false) const passwordValid = await bcrypt.compare(password, user.password) if (!passwordValid) return cb(null, false) let token = jwt.sign( { // jwt claims go here // this includes standard claims like iat (issued at) // as well as any custom data you would like to include email: email }, process.env.JWT_SECRET ) return cb(null, token) }) )
<HelpBlock>{this.state.errors.identifier}</HelpBlock> </FormGroup> <FormGroup validationState={this.state.errors.password && 'error'}> <FormControl name="password" onChange={this.handleValueChange} /> <Glyphicon glyph="lock" className="form-control-feedback" /> <HelpBlock>{this.state.errors.password}</HelpBlock> </FormGroup> <div className="text-center">
passport.use( new BasicStrategy(async (email, password, cb) => { const user = (await db.query('SELECT * FROM account WHERE email=$1', [ email ])).rows[0] if (!user) return cb(null, false) if (!user.activated) return cb(null, false) const passwordValid = await bcrypt.compare(password, user.password) if (!passwordValid) return cb(null, false) let token = jwt.sign( { // jwt claims go here // this includes standard claims like iat (issued at) // as well as any custom data you would like to include email: email }, process.env.JWT_SECRET ) return cb(null, token) }) )