Skip to content

souravpl8092/Facebook-Auth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Facebook Authentication using Node.js, Express, and Mongoose



Before Login

After Login

Before Login After Login

Overview

This code implements a Facebook authentication system using Node.js, Express, Passport.js and Mongoose.


Requirements

  • Node.js
  • npm or yarn
  • MongoDB instance
  • Facebook App credentials

Installation

1. Clone the repository and install the dependencies:


2. Create a .env file in the root directory of the project and add the following variables:

  • SESSION_SECRET = [ your session secret ]
  • FACEBOOK_CLIENT_ID = [ your facebook app client ID ]
  • FACEBOOK_SECRET_KEY = [ your facebook app secret key ]
  • FACEBOOK_CALLBACK_URL = [ your facebook app callback URL ]
  • mongoURL = [ your mongodb URL ]
  • PORT = [ port number to run the server ]


3. Start the server:

  • npm start

Code Explanation

config/db.js

  • This file connects to the MongoDB server using the mongoose library.

models/User.model.js

  • This file defines a User schema using the mongoose.Schema method.

routes/facebook-auth.js

  • This file defines a facebook-auth router using the express.Router method and implements the Facebook authentication strategy using the passport-facebook library.

server.js

  • This file initializes the Express application, sets up the session middleware, passport.js authentication, and defines the routes for the Facebook authentication.

Thank You

Releases

No releases published

Packages

No packages published