GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - AmirMustafa/Google-and-Facebook-Login---MERN-Stack: Login with Google and Facebook OAuth2 - Node JS, React JS, Redux, Passport JS, Axios, MERN Stack

BranchesTags
Open more actions menu

Latest commit

 

History

13 Commits
13 Commits

Folders and files

NameName
Last commit message
Last commit date
client
client
 
 
config
config
 
 
models
models
 
 
node_modules
node_modules
 
 
routes
routes
 
 
services
services
 
 
.gitignore
.gitignore
 
 
Google OAUTH LOGIN NODE JS(MERN).docx
Google OAUTH LOGIN NODE JS(MERN).docx
 
 
README.md
README.md
 
 
index.js
index.js
 
 
package-lock.json
package-lock.json
 
 
package.json
package.json
 
 

Repository files navigation

Google-and-Facebook-Login---MERN-Stack

Passport JS is for using Login with Google and Facebook. For the backend Node JS (Express JS) is used and in front end for visual React JS and Redux is used. For the database Mongo DB Atlas is used. Axios is used for fetching data from React JS to Node JS.

Please leave a star if it was helpful.

Production

https://google-fb-oauth-mern.herokuapp.com/

Installation

  1. Clone the Project
  2. Run npm install on root - Node Dependencies
  3. Run npm install on /client - React JS Dependencies
  4. Create your account in Mongo DB Atlas
  5. In config/keys.js - paste your mongo db atlas url

Review

Please leave a ⭐ if you like it

Snippets

  1. Passport Js(services/passport.js)
const passport = require("passport");
const GoogleStrategy = require("passport-google-oauth20").Strategy;
const FacebookStrategy = require("passport-facebook").Strategy;
const keys = require("../config/keys");
const mongoose = require("mongoose");
const User = mongoose.model("users"); // getting Schema

/* =================== Handeling Infinite run: Start ===================  */
passport.serializeUser((user, done) => {
  done(null, user.id);
});

passport.deserializeUser((id, done) => {
  User.findById(id).then(user => {
    done(null, user);
  });
});

// For Google
passport.use(
  new GoogleStrategy(
    {
      clientID: keys.googleClientID,
      clientSecret: keys.googleClientSecret,
      callbackURL: "/auth/google/callback"
    },
    (accessToken, refreshToken, profile, done) => {
      console.log(profile);
      // profile has all google login data
      /* ========= DATABASE CHECK PRE EXIST AND INSERT QUERY: START =========  */

      // check if user id already inserted
      User.findOne({ userId: profile.id }).then(existingUser => {
        if (existingUser) {
          done(null, existingUser);
        } else {
          // new user case
          // insert new user id
          new User({
            userId: profile.id,
            username: profile.displayName,
            picture: profile._json.picture
          })
            .save()
            .then(user => {
              done(null, user);
            });
        }
      });
      /* ========= DATABASE CHECK PRE EXIST AND INSERT QUERY: END =========  */
    }
  )
);

// For facebook
passport.use(
  new FacebookStrategy(
    {
      clientID: keys.FACEBOOK_APP_ID,
      clientSecret: keys.FACEBOOK_APP_SECRET,
      callbackURL: "/auth/facebook/callback"
    },
    (accessToken, refreshToken, profile, done) => {
      console.log(profile);
      /* ========= DATABASE CHECK PRE EXIST AND INSERT QUERY: START =========  */
      // check if user id already inserted
      User.findOne({ userId: profile.id }).then(existingUser => {
        if (existingUser) {
          done(null, existingUser);
        } else {
          // new user case
          // insert new user id
          new User({
            userId: profile.id,
            username: profile.displayName,
            picture: profile._json.picture
          })
            .save()
            .then(user => {
              done(null, user);
            });
        }
      });
      /* ========= DATABASE CHECK PRE EXIST AND INSERT QUERY: END =========  */
    }
  )
);


Screenshot

Project image

Google Signin

FB Signin

Redux Implementation

Project image

Getting Data

Mongo DB Atlas

Project Video (Explaination)

Overall(Browser + Code explaination) - https://www.loom.com/share/1661fda5295e4325b12621b3185bbac6 Get client id and secret key from Facebook for Developers - https://www.loom.com/share/80a8ca2b0d6b4290a51b308412c7022f Get client id and secret key from Google for Developers - https://www.loom.com/share/f6741234dcb64b079c9346bc3485de16 Get SRV key from Mongo DB Atlas - https://www.loom.com/share/57d80d7684894d84b590fc75c1a75e29

About

Login with Google and Facebook OAuth2 - Node JS, React JS, Redux, Passport JS, Axios, MERN Stack

google-fb-oauth-mern.herokuapp.com/

Resources

Readme
Activity

Stars

7 stars

Watchers

1 watching

Forks

8 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.