Allow using custom Passport LocalStrategy for local authentication
See original GitHub issueThis is related to https://github.com/iaincollins/next-auth/issues/9 as it is about doing local authentication, but it is about using a custom Passport LocalStrategy I have written. Is it possible to use Passport LocalStrategy with next-auth? I tried creating a provider and passing the strategy in the Strategy property, but that wouldn’t work. I wonder if I am doing something wrong. Does it only work with OAuth providers?
providers.push({
providerName: 'Local Login',
providerOptions: {
scope: ['profile', 'email'],
},
Strategy: require('./passport/local-login'),
strategyOptions: {
},
getProfile(profile) {
// Normalize profile into one with {id, name, email} keys
return {
id: profile.id,
name: profile.displayName,
email: profile.emails[0].value,
};
}
});
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:15 (7 by maintainers)
Top Results From Across the Web
Allow using custom Passport LocalStrategy for local ... - GitHub
Is it possible to use Passport LocalStrategy with next-auth? I tried creating a provider and passing the strategy in the Strategy property, but ......
Read more >How can I develop custom passport-local authentication ...
I would like to create an authentication strategy with passport that can be used to parse out the login token email and password....
Read more >Node JS with Passport Authentication simplified - Medium
Users could be authenticated against a username/password saved in a database that you created either locally or on a cloud (called “Local Strategy”),...
Read more >Local Authentication Using Passport in Node.js - SitePoint
In this tutorial, we'll be using session-based authentication, which is at the heart of the passport-local strategy.
Read more >Documentation: Username & Password - Passport.js
var passport = require('passport'); var LocalStrategy = require('passport-local'); var crypto = require('crypto'); passport.use(new LocalStrategy(function ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
To confirm, you don’t call NextAuth.signin(), just post to the new end point.
You can do this using just a normal form post and/or in JavaScript.
You don’t actually also need to do it in JavaScript unless you want to - a normal form post will work just fine, but if you want to you could have a sign in method like this in your sign in page (assumes email and password are stored in ‘this.state’).
If you find this works for you I am happy to look at both adding localStrategy support and at changing
NextAuth.signin()
to work with them (so it can be passed options to post to a local strategy, e.g. username or email, password, 2-factor-auth-token, etc).None of these changes should be breaking - so anything you have done will keep working! - but should make it easier for anyone else in future.
@iaincollins I did this, added a password field to the signin component, and updated my form action URL to /auth/password and it works with JavaScript disabled, but when JavaScript is enabled the call to NextAuth.signin() in handleSubmit() ends up sending the verification email anyway, I think because next-auth-client does the POST to /auth/email/signin. Should I not call NextAuth.signin()? Can I use next-auth/next-auth-client when wanting to have password authentication?
I understand the single-use login token links sent via email can be seen as more secure than keeping passwords, but I am in an organization that precludes me from doing it that way.
Support for password-based authentication would be great, but I really just want to get this working the way I need. I had considered rolling back and modifying the code from before you moved it to the next-auth module, but I am so far down the line now there would be a lot to do over again.