Build HTTP APIs with routing, middleware, validation, controllers, and error handling.
Lessons
Plug in strategies for local, OAuth, and social login.
Authentication with Passport is easiest to learn by reading the example, changing it, and observing the result.
// npm install passport passport-local
import passport from 'passport';
import { Strategy as LocalStrategy } from 'passport-local';
passport.use(new LocalStrategy(async (username, password, done) => {
const user = await findUser(username);
if (!user || !(await user.verify(password))) {
return done(null, false, { message: 'Bad credentials' });
}
return done(null, user);
}));Practice the Authentication with Passport example in a small scratch file, then explain what changed and why.