passport-local-register
Passport strategy for authenticating with a username and password and registering new accounts on failure.
This module differs from passport-local by allowing you to turn failed authentication requests into user registrations. Using this module correctly, login should only fail if the account identifier (e.g., username) supplied is already taken.
Except where explicitly specified, this module works as passport-local would. It is strongly suggested that you be familiar with passport-local before using this module, as this document will not seek to duplicate passport-local's documentation.
Install
$ npm install passport-local-register
Usage
Configure Strategy
Configuring this strategy is almost identical to configuring passport-local, except that it requires one more callback to be passed to the constructor.
Example
passport;
verify
callback
This is an important note regarding verify
: invoke the passed-in
callback (done
) with false
as the second argument only if
your code has determined that the account exists and that the
passwords do not match. Passing null
as the second argument will
prevent the strategy from attempting to create an account.
Authenticate Requests
Use passport.authenticate()
, specifying the 'localRegister'
strategy, to
authenticate requests.
For example, as route middleware in an Express application:
app;
Credits
- Saad Rhoulam, register-on-fail functionality
- Jared Hanson, passport-local strategy