File tree Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,9 @@ password. The strategy requires a `verify` callback, which accepts these
3131credentials and calls ` done ` providing a user.
3232
3333``` js
34+ passport = require (' passport' );
35+ LocalStrategy = require (' passport-local' ).Strategy ;
36+
3437passport .use (new LocalStrategy (
3538 function (username , password , done ) {
3639 User .findOne ({ username: username }, function (err , user ) {
@@ -96,12 +99,17 @@ passport.use(new LocalStrategy({
9699#### Authenticate Requests
97100
98101Use ` passport.authenticate() ` , specifying the ` 'local' ` strategy, to
99- authenticate requests.
102+ authenticate requests. It searches for fields in the query string and
103+ ` req.body ` , so ensure body parsers are in place if these fields are
104+ sent in the body.
100105
101106For example, as route middleware in an [ Express] ( http://expressjs.com/ )
102107application:
103108
104109``` js
110+ app .use (require (' body-parser' ).urlencoded ({ extended: true }));
111+ app .use (passport .initialize ());
112+
105113app .post (' /login' ,
106114 passport .authenticate (' local' , { failureRedirect: ' /login' }),
107115 function (req , res ) {
You can’t perform that action at this time.
0 commit comments