Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/souravpl8092/facebook-auth

Facebook Authentication using Node.js, Express, and Mongoose
https://github.com/souravpl8092/facebook-auth

bootstrap dotenv ejs express-sessions expressjs mongodb moongose nodejs passport passport-facebook

Last synced: 19 days ago
JSON representation

Facebook Authentication using Node.js, Express, and Mongoose

Awesome Lists containing this project

README

        

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:

- git clone https://github.com/souravpl8092/QuestLabs-Assignment.git
- cd QuestLabs-Assignment
- npm install


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