Passport must be initialized using passport.initialize() middleware.
To use login sessions, passport.session() middleware is required.
Note that passport.serialize() and passport.deserializeUser() methods must be defined. Passport will serialize and deserialize user instances to and from the sessi...
The passport-local module is used to implement a local authentication.
This module lets you authenticate using a username and password in your Node.js applications.
Registering the user :
const passport = require('passport');
const LocalStrategy = require('passport-local').Strategy;
// A ...
The passport-facebook module is used to implement a Facebook authentication.
In this example, if the user does not exist on sign-in, he is created.
Implementing strategy :
const passport = require('passport');
const FacebookStrategy = require('passport-facebook').Strategy;
// Strategy is name...
In your routes/index.js
Here user is the model for the userSchema
router.post('/login', function(req, res, next) {
if (!req.body.username || !req.body.password) {
return res.status(400).json({
message: 'Please fill out all fields'
});
}
passpor...
We have simple module available in npm for goggle authetication name passport-google-oauth20
Consider the following example
In this example have created a folder namely config having the passport.js and google.js file in the root directory.
In your app.js include the following
var express = requ...