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

#166240994 Enable social login #26

Merged
merged 1 commit into from
Jun 17, 2019

Conversation

mifeille
Copy link
Contributor

What does this PR do?

Enables social login.

Description of Task to be completed?

Allow users to login with their pre-existing social media accounts

How should this be manually tested?

Clone the repo, cd into it and RUN yarn install to install all the dependencies, then RUN yarn dev to start the server.

  • Log in the account that you want to use and go to the browser and write :
    http://localhost:3001/api/auth/login/facebook for Facebook
    http://localhost:3001/api/auth/login/google for Google
    http://localhost:3001/api/auth/login/twitter for Twitter

What are the relevant pivotal tracker stories?
#166240994

@mifeille mifeille added the WIP label Jun 13, 2019
test/auth.js Outdated
import server from '../src/index';

const { expect } = chai;
chai.use(chaiHttp);

const authenticatedUser = request.agent(server);

Choose a reason for hiding this comment

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

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

if (currentUser) {
console.log('this is not a new user');
console.log(currentUser);
console.log(currentUser.length);

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

}).then((currentUser) => {
if (currentUser) {
console.log('this is not a new user');
console.log(currentUser);

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

},
}).then((currentUser) => {
if (currentUser) {
console.log('this is not a new user');

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

id, displayName, provider
} = req.user;
console.log('hey');
console.log(req.user);

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

},
),
);
passport.use(

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

done(null, profile);
},
),
);

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

},
),
);
passport.use(

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

src/config/passportSetup.js Outdated Show resolved Hide resolved

dotenv.config();

passport.use(

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

@mifeille mifeille force-pushed the ft-enable-social-login-166240994 branch from 3b28c8a to c1bff32 Compare June 16, 2019 13:21
@@ -4,16 +4,14 @@ import dotenv from 'dotenv';
import server from '../src/index';
import db from '../src/sequelize/models';
import tokenHelper from '../src/helpers/Token.helper';

import socialController from '../src/middleware/socialAccountExists';

Choose a reason for hiding this comment

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

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

const userExists = {
async google(req, res, next) {
const { emails, displayName } = req.user;
console.log(emails[0].value);

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

src/api/routes/authRouter.js Outdated Show resolved Hide resolved
authRouter.get('/login/google/redirect', passport.authenticate('google', { session: false }), google, socialLogin.googleLogin);

// routes for facebook
authRouter.get('/login/facebook', passport.authenticate('facebook', { scope: ['email'] }),);

Choose a reason for hiding this comment

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

A space is required after ',' comma-spacing

verified: req.user.emails[0].verified,
socialId: req.user.id,
});
//console.log(newUser.dataValues);

Choose a reason for hiding this comment

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

Expected exception block, space or tab after '//' in comment spaced-comment


const userInfo = {
async googleLogin(req, res) {
console.log(req.user);

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

@mifeille mifeille force-pushed the ft-enable-social-login-166240994 branch from c1bff32 to 9ad5790 Compare June 16, 2019 13:51
profileFields: ['id', 'displayName', 'photos', 'email'],
},
(accessToken, refreshToken, profile, done) => { done(null, profile); },
),);

Choose a reason for hiding this comment

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

A space is required after ',' comma-spacing

callbackURL: '/api/auth/login/google/redirect',
},
(accessToken, refreshToken, profile, done) => { done(null, profile); },
),);

Choose a reason for hiding this comment

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

A space is required after ',' comma-spacing

@mifeille mifeille force-pushed the ft-enable-social-login-166240994 branch 2 times, most recently from a05b043 to d53be91 Compare June 16, 2019 14:05
profileFields: ['id', 'displayName', 'photos', 'email'],
}, (accessToken, refreshToken, profile, done) => { done(null, profile); },
),);
passport.use(new TwitterTokenStrategy(

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

callbackURL: '/api/auth/login/facebook/redirect',
profileFields: ['id', 'displayName', 'photos', 'email'],
}, (accessToken, refreshToken, profile, done) => { done(null, profile); },
),);

Choose a reason for hiding this comment

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

A space is required after ',' comma-spacing
Unexpected newline before ')' function-paren-newline

},
(accessToken, refreshToken, profile, done) => { done(null, profile); },
),);
passport.use(new FacebookStrategy(

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

@mifeille mifeille force-pushed the ft-enable-social-login-166240994 branch from d53be91 to 0092997 Compare June 16, 2019 14:16
clientSecret: process.env.FCBK_APP_SECRET,
callbackURL: '/api/auth/login/facebook/redirect',
profileFields: ['id', 'displayName', 'photos', 'email']
}, (accessToken, refreshToken, profile, done) => { done(null, profile); },),);

Choose a reason for hiding this comment

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

A space is required after ',' comma-spacing

clientSecret: process.env.GOOGLE_SECRET,
includeEmail: true,
callbackURL: '/api/auth/login/google/redirect'
}, (accessToken, refreshToken, profile, done) => { done(null, profile); },),);

Choose a reason for hiding this comment

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

A space is required after ',' comma-spacing

@mifeille mifeille force-pushed the ft-enable-social-login-166240994 branch from 0092997 to 52f33f3 Compare June 16, 2019 14:24
consumerSecret: process.env.TWITTER_APP_SECRET,
callbackURL: 'http://localhost:3001/api/auth/login/twitter/redirect'
},
(token, tokenSecret, profile, done) => { done(null, profile); }));

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

},
(accessToken, refreshToken, profile, done) => { done(null, profile); },),);

passport.use(new TwitterTokenStrategy({

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

callbackURL: '/api/auth/login/facebook/redirect',
profileFields: ['id', 'displayName', 'photos', 'email']
},
(accessToken, refreshToken, profile, done) => { done(null, profile); },),);

Choose a reason for hiding this comment

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

A space is required after ',' comma-spacing
Expected a newline before ')' function-paren-newline

},
(accessToken, refreshToken, profile, done) => { done(null, profile); },),);

passport.use(new FacebookStrategy({

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

includeEmail: true,
callbackURL: '/api/auth/login/google/redirect'
},
(accessToken, refreshToken, profile, done) => { done(null, profile); },),);

Choose a reason for hiding this comment

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

A space is required after ',' comma-spacing
Expected a newline before ')' function-paren-newline


dotenv.config();

passport.use(new GoogleStrategy({

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

@mifeille mifeille force-pushed the ft-enable-social-login-166240994 branch 2 times, most recently from 342afe8 to 762233e Compare June 16, 2019 14:34
// callback route for twitter to redirect to

authRouter.get('/login/twitter/redirect', passport.authenticate('twitter', { session: false }),
twitter, socialLogin.twitterLogin);

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


// callback route for twitter to redirect to

authRouter.get('/login/twitter/redirect', passport.authenticate('twitter', { session: false }),

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

// callback route for facebook to redirect to

authRouter.get('/login/facebook/redirect', passport.authenticate('facebook', { session: false }),
google, socialLogin.facebookLogin);

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


// callback route for facebook to redirect to

authRouter.get('/login/facebook/redirect', passport.authenticate('facebook', { session: false }),

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

// callback route for google to redirect to

authRouter.get('/login/google/redirect', passport.authenticate('google', { session: false }),
google, socialLogin.googleLogin);

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


// callback route for google to redirect to

authRouter.get('/login/google/redirect', passport.authenticate('google', { session: false }),

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

@mifeille mifeille force-pushed the ft-enable-social-login-166240994 branch from 762233e to ac21763 Compare June 16, 2019 14:37
@mifeille mifeille added Needs Review and removed WIP labels Jun 16, 2019
@mifeille mifeille force-pushed the ft-enable-social-login-166240994 branch from ac21763 to 3f46d6e Compare June 16, 2019 14:43
}, (accessToken, refreshToken, profile, done) => {
done(null, profile);
}
),);

Choose a reason for hiding this comment

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

A space is required after ',' comma-spacing
Unexpected newline before ')' function-paren-newline

@mifeille mifeille force-pushed the ft-enable-social-login-166240994 branch 2 times, most recently from 1b57b89 to c139fcd Compare June 16, 2019 15:16
},
(token, tokenSecret, profile, done) => {
done(null, profile);
}));

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

},
(accessToken, refreshToken, profile, done) => {
done(null, profile);
},),);

Choose a reason for hiding this comment

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

A space is required after ',' comma-spacing
Expected a newline before ')' function-paren-newline

},
(accessToken, refreshToken, profile, done) => {
done(null, profile);
}),);

Choose a reason for hiding this comment

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

A space is required after ',' comma-spacing
Expected a newline before ')' function-paren-newline

@mifeille mifeille force-pushed the ft-enable-social-login-166240994 branch from c139fcd to 00fa044 Compare June 16, 2019 15:23
@mifeille mifeille force-pushed the ft-enable-social-login-166240994 branch 4 times, most recently from cb5bf95 to e2e39ba Compare June 16, 2019 15:51
@mifeille mifeille force-pushed the ft-enable-social-login-166240994 branch 10 times, most recently from b326f5a to 451219f Compare June 17, 2019 10:10
@mifeille mifeille added Needs Merge Needs To merge and removed Needs Review labels Jun 17, 2019
package.json Outdated
"handlebars": "^4.1.2",
"install": "^0.12.2",

Choose a reason for hiding this comment

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

Remove unused packages.

package.json Outdated
@@ -37,7 +39,11 @@
"morgan": "^1.9.1",
"nodemailer": "^6.2.1",
"passport": "^0.4.0",
"passport-auth0": "^1.1.0",

Choose a reason for hiding this comment

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

Remove this Package.

if (newUser) {
const {
id, firstName, lastName, email, provider
} = newUser.dataValues;

Choose a reason for hiding this comment

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

const {
dataValues: {id, firstName, lastName, email, provider}
} = newUser;

{
consumerKey: process.env.TWITTER_ID,
consumerSecret: process.env.TWITTER_APP_SECRET,
callbackURL: 'http://localhost:3001/api/auth/login/twitter/redirect'

Choose a reason for hiding this comment

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

Remove the hardcoded base_url.

${}

@mifeille mifeille force-pushed the ft-enable-social-login-166240994 branch 2 times, most recently from 17867be to 9cb491e Compare June 17, 2019 13:46
@mifeille mifeille force-pushed the ft-enable-social-login-166240994 branch from 9cb491e to 5f8af5a Compare June 17, 2019 14:10
@Quantum-35 Quantum-35 merged commit 1e25f12 into develop Jun 17, 2019
Diama1 pushed a commit that referenced this pull request Jul 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Merge Needs To merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants