Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(social Oauth):add social media login route #29

Merged
merged 1 commit into from
Sep 5, 2019

Conversation

okikiola11
Copy link
Collaborator

@okikiola11 okikiola11 commented Aug 22, 2019

What does this PR do?

  • add social Oauth login

Description of Task to be completed?

  • implement social media login route for Facebook and Google

How should this be manually tested?

  • Clone the repo and cd into the project directory
  • Run yarn install to install the project's dependency
  • Run yarn start to start the app

What are the relevant pivotal tracker stories?

#167727629

Screenshot

pix-barefoot

pix2-barefoot

fb-barefoot

fb2-baf

@@ -2,4 +2,4 @@ const router = require("express").Router();

router.use("/api", require("./api"));

module.exports = router;
export default router;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parsing error: 'import' and 'export' may appear only with 'sourceType: module'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A add a new line here.

src/routes/authRoutes.js Outdated Show resolved Hide resolved
@@ -0,0 +1,17 @@
import passport from "passport";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parsing error: 'import' and 'export' may appear only with 'sourceType: module'

@@ -0,0 +1,8 @@
import dotenv from 'dotenv';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parsing error: 'import' and 'export' may appear only with 'sourceType: module'

@okikiola11 okikiola11 added the W.I.P The PR is still being worked on label Aug 22, 2019
@okikiola11 okikiola11 force-pushed the ft-soial-auth-#167727629 branch 2 times, most recently from eb31152 to 8bd5891 Compare August 26, 2019 02:13
src/utils/helpers.js Outdated Show resolved Hide resolved
@@ -0,0 +1,7 @@
class Helper {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing JSDoc comment require-jsdoc

router.get('/facebook/redirect',
passport.authenticate('facebook', {
session: false
}), SocialController.socialLogin);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected a newline before ')' function-paren-newline

scope: ['profile']
}));

router.get('/facebook/redirect',
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected a newline after '(' function-paren-newline

router.get('/google/redirect',
passport.authenticate('google', {
session: false
}), SocialController.socialLogin);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected a newline before ')' function-paren-newline

}
});
} catch (error) {
console.log(error.message);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected console statement no-console

try {
const {
_json: user,
provider
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'provider' is assigned a value but never used no-unused-vars

config();

class SocialController {
static async socialLogin(req, res) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing JSDoc comment require-jsdoc


config();

class SocialController {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing JSDoc comment require-jsdoc

import jwt from 'jsonwebtoken';
import {
config
} from 'dotenv';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected line break before this closing brace object-curly-newline

@okikiola11 okikiola11 added Ready-for-review The PR is ready to be reviewed by teammates and removed W.I.P The PR is still being worked on labels Aug 26, 2019
@@ -0,0 +1,57 @@
import jwt from 'jsonwebtoken';
import {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected line break after this opening brace object-curly-newline

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love the way you created a new file for this and for also following the naming convention. 👍

clientID: FACEBOOK_CLIENT_ID,
clientSecret: FACEBOOK_CLIENT_SECRET
}, passportCb)
);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected newline before ')' function-paren-newline

clientSecret: GOOGLE_CLIENT_SECRET
}, passportCb)
);
passport.use(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected newline after '(' function-paren-newline

clientID: GOOGLE_CLIENT_ID,
clientSecret: GOOGLE_CLIENT_SECRET
}, passportCb)
);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected newline before ')' function-paren-newline

} = env;

const setupPassport = () => {
passport.use(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected newline after '(' function-paren-newline

import passport from 'passport';
import {
Strategy as GoogleStrategy
} from 'passport-google-oauth20';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected line break before this closing brace object-curly-newline

@@ -0,0 +1,44 @@
import passport from 'passport';
import {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected line break after this opening brace object-curly-newline

first_name,
email
} = user;
const userData = await SocialController.findOrCreateUserByEmail(first_name, last_name, email);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 80 exceeds the maximum line length of 80 max-len


const {
last_name,
first_name,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Identifier 'first_name' is not in camel case camelcase

}

const {
last_name,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Identifier 'last_name' is not in camel case camelcase

_raw,
_json: user
} = req.user;
console.log(user);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected console statement no-console

static async facebookLogin(req, res) {
try {
const {
_raw,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'_raw' is assigned a value but never used no-unused-vars

}
}

static async facebookLogin(req, res) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing JSDoc comment require-jsdoc

}
});
} catch (error) {
console.log(error.message);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected console statement no-console

error: 'No email address is found for this user'
});
}
const userData = await SocialController.findOrCreateUserByEmail(user.firstName, user.lastName, user.email);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 39 exceeds the maximum line length of 80 max-len

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, just login not to create a user.

return userData;
}

static async googleLogin(req, res) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing JSDoc comment require-jsdoc

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a JSDOC. look at other controllers to see how we have been writing JSDOCs for controller

callbackURL: 'http://localhost:3000/api/v1/auth/facebook/redirect',
clientID: FACEBOOK_CLIENT_ID,
clientSecret: FACEBOOK_CLIENT_SECRET,
profileFields: ['id', 'email', 'gender', 'link', 'locale', 'name', 'timezone', 'updated_time', 'verified']
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 34 exceeds the maximum line length of 80 max-len

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix this hound error by doing

[
  'id', 'email', 'gender', 'link', 'locale',
  'name', 'timezone', 'updated_time', 'verified'
];

.sequelizerc Outdated
@@ -1,5 +1,7 @@
require('@babel/register');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are you importing babel register in here?

.sequelizerc Outdated
const path = require('path');


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did you add a new line here?.

env
} = process;

export default env;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this file created?. Is it necessary?

Strategy as GoogleStrategy
} from 'passport-google-oauth20';
import env from './env-config';
import Helpers from '../utils/helpers';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not how we have been importing helpermethods in the codebase. Please import it correctly.

src/config/passport.js Show resolved Hide resolved
error: 'No email address is found for this user'
});
}
const userData = await SocialController.findOrCreateUserByEmail(user.firstName, user.lastName, user.email);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, just login not to create a user.

src/models/User.js Outdated Show resolved Hide resolved
@@ -2,4 +2,4 @@ const router = require("express").Router();

router.use("/api", require("./api"));

module.exports = router;
export default router;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A add a new line here.

src/routes/v1/index.js Outdated Show resolved Hide resolved
src/routes/v1/socialRoutes.js Outdated Show resolved Hide resolved
* @param {string} done - user profile
* @return {object} - user profile
*/
export const passportCb = (accessToken, requestToken, profile, done) => done(null, profile);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 9 exceeds the maximum line length of 90 max-len
Prefer default export import/prefer-default-export

@@ -0,0 +1,3 @@
import sinon from 'sinon';
import chai from 'chai';
import passport from 'passport';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'passport' is defined but never used no-unused-vars

@@ -0,0 +1,3 @@
import sinon from 'sinon';
import chai from 'chai';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'chai' is defined but never used no-unused-vars

@@ -0,0 +1,3 @@
import sinon from 'sinon';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'sinon' is defined but never used no-unused-vars

import { SendEmail } from '../../utils';
import {
SendEmail
} from '../../utils';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected line break before this closing brace object-curly-newline

scope: ['profile', 'email']
}));

app.get('/api/v1/auth/google/redirect',
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected a newline after '(' function-paren-newline

@@ -9,4 +11,4 @@ const requestRoutes = app => {
RequestController.bookATrip);
};

export default requestRoutes;
export default requestRoutes;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Newline required at end of file but not found eol-last

import { RequestController } from '../controllers';
import {
RequestController
} from '../controllers';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected line break before this closing brace object-curly-newline

@@ -1,4 +1,6 @@
import { RequestController } from '../controllers';
import {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected line break after this opening brace object-curly-newline

import { CryptData } from '../utils';
import {
CryptData
} from '../utils';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected line break before this closing brace object-curly-newline

@@ -1,4 +1,6 @@
import { CryptData } from '../utils';
import {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected line break after this opening brace object-curly-newline

import app from '../../index';
import {
passportCb
} from '../../utils/helpers';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected line break before this closing brace object-curly-newline

import chaiHttp from 'chai-http';
import passport from 'passport';
import app from '../../index';
import {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected line break after this opening brace object-curly-newline

callbackURL: 'http://localhost:3000/api/v1/auth/facebook/redirect',
clientID: FACEBOOK_CLIENT_ID,
clientSecret: FACEBOOK_CLIENT_SECRET,
profileFields: ['id', 'email', 'gender', 'link', 'locale', 'name', 'timezone', 'updated_time', 'verified']
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 34 exceeds the maximum line length of 90 max-len

src/config/passport.js Outdated Show resolved Hide resolved
src/seeders/01-demo-user.js Show resolved Hide resolved
value: userEmail
}] = emails;
if (!userEmail) {
return HelperMethods.clientError(res, 'No email address is found for this user', 400);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 91 exceeds the maximum line length of 90 max-len

static async facebookLogin(req, res) {
try {
const {
_json: user,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'user' is assigned a value but never used no-unused-vars

value: userEmail
}] = emails;
if (!userEmail) {
return HelperMethods.clientError(res, 'No email address is found for this user', 400);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 51 exceeds the maximum line length of 90 max-len

// check if user exist
try {
const {
_json: user,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'user' is assigned a value but never used no-unused-vars

* @memberof socialController
*/

static async googleLogin(req, res) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing JSDoc comment require-jsdoc


dotenv.config();

class SocialController {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing JSDoc comment require-jsdoc

import { UserController } from '../../controllers';
import {
UserController
} from '../../controllers';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected line break before this closing brace object-curly-newline

import { UserController } from '../controllers';
import {
UserController
} from '../controllers';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected line break before this closing brace object-curly-newline

@@ -1,4 +1,6 @@
import { UserController } from '../controllers';
import {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected line break after this opening brace object-curly-newline

src/seeders/01-demo-user.js Outdated Show resolved Hide resolved
createdAt: new Date(),
updatedAt: new Date()
},
{
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected indentation of 2 spaces but found 4 indent

password: await init(),
createdAt: new Date(),
updatedAt: new Date()
},
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected indentation of 2 spaces but found 4 indent

username: 'user2',
password: await init(),
createdAt: new Date(),
updatedAt: new Date()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected indentation of 4 spaces but found 6 indent

src/seeders/01-demo-user.js Outdated Show resolved Hide resolved
src/seeders/01-demo-user.js Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
@@ -68,4 +71,4 @@
"nyc": "^14.1.1",
"sinon": "^7.4.1"
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a new line here.

src/config/passport.js Show resolved Hide resolved
src/config/passport.js Show resolved Hide resolved
@okikiola11 okikiola11 force-pushed the ft-soial-auth-#167727629 branch 9 times, most recently from 732d57b to 9a4f9d7 Compare September 2, 2019 13:44
};

export default routes;
export default routes;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Newline required at end of file but not found eol-last

if (!userData) {
return HelperMethods.clientError(res,
'You are not a registered user. Please, signup',
404);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected a newline before ')' function-paren-newline

}
const userData = await SocialController.findByEmail(userEmail);
if (!userData) {
return HelperMethods.clientError(res,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected a newline after '(' function-paren-newline

if (!userEmail) {
return HelperMethods.clientError(res,
'No email address is found for this user',
400);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected a newline before ')' function-paren-newline

try {
const [{ value: userEmail }] = req.user.emails;
if (!userEmail) {
return HelperMethods.clientError(res,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected a newline after '(' function-paren-newline

try {
const [{ value: userEmail }] = req.user.emails;
if (!userEmail) {
return HelperMethods.clientError(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected newline after '(' function-paren-newline

'name', 'timezone', 'updated_time', 'verified'
],
}, passportCb)
);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected newline before ')' function-paren-newline

clientSecret: GOOGLE_CLIENT_SECRET
}, passportCb)
);
passport.use(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected newline after '(' function-paren-newline

clientID: GOOGLE_CLIENT_ID,
clientSecret: GOOGLE_CLIENT_SECRET
}, passportCb)
);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected newline before ')' function-paren-newline

const passportCb = (accessToken, requestToken, profile, done) => done(null, profile);

const setupPassport = () => {
passport.use(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected newline after '(' function-paren-newline

*/
export const passportCb = (accessToken, requestToken, profile, done) => done(
null, profile
);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected newline before ')' function-paren-newline

* @param {string} done - user profile
* @return {object} - user profile
*/
export const passportCb = (accessToken, requestToken, profile, done) => done(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected newline after '(' function-paren-newline

@Daymorelah Daymorelah merged commit d6a0ceb into develop Sep 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ready-for-review The PR is ready to be reviewed by teammates
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants