fix(auth): Login everyone with an social account (#17333)

* fix(auth): Login everyone with an social account

* fix: update the flash message for social
This commit is contained in:
mrugesh mohapatra
2018-06-01 02:29:27 +05:30
committed by Stuart Taylor
parent 74eb179c7b
commit b4332a0def
3 changed files with 25 additions and 45 deletions

View File

@ -4,6 +4,7 @@ import { PassportConfigurator } from
import passportProviders from './passport-providers';
import url from 'url';
import jwt from 'jsonwebtoken';
import dedent from 'dedent';
const passportOptions = {
emailOptional: true,
@ -133,11 +134,24 @@ export default function setupPassport(app) {
delete redirect.search;
const { accessToken } = userInfo;
const { provider } = config;
if (accessToken && accessToken.id) {
if (provider === 'auth0') {
req.flash(
'success',
'Success! You have signed in to your account. Happy Coding!'
dedent`
Success! You have signed in to your account. Happy Coding!
`
);
} else if (user.email) {
req.flash(
'info',
dedent`
We are moving away from social authentication for privacy reasons. Next time
we recommend using your email address: ${user.email} to sign in instead.
`
);
}
const cookieConfig = {
signed: !!req.signedCookies,
maxAge: accessToken.ttl,

View File

@ -23,6 +23,7 @@ export default {
authPath: '/auth/facebook',
callbackURL: '/auth/facebook/callback',
callbackPath: '/auth/facebook/callback',
useCustomCallback: true,
successRedirect: successRedirect,
failureRedirect: failureRedirect,
scope: ['email'],
@ -51,6 +52,7 @@ export default {
authPath: '/auth/google',
callbackURL: '/auth/google/callback',
callbackPath: '/auth/google/callback',
useCustomCallback: true,
successRedirect: successRedirect,
failureRedirect: failureRedirect,
scope: ['email', 'profile'],
@ -78,6 +80,7 @@ export default {
authPath: '/auth/twitter',
callbackURL: '/auth/twitter/callback',
callbackPath: '/auth/twitter/callback',
useCustomCallback: true,
successRedirect: successRedirect,
failureRedirect: failureRedirect,
consumerKey: process.env.TWITTER_KEY,
@ -105,6 +108,7 @@ export default {
authPath: '/auth/linkedin',
callbackURL: '/auth/linkedin/callback',
callbackPath: '/auth/linkedin/callback',
useCustomCallback: true,
successRedirect: successRedirect,
failureRedirect: failureRedirect,
clientID: process.env.LINKEDIN_ID,
@ -142,6 +146,7 @@ export default {
authPath: '/auth/github',
callbackURL: '/auth/github/callback',
callbackPath: '/auth/github/callback',
useCustomCallback: true,
successRedirect: successRedirect,
failureRedirect: failureRedirect,
clientID: process.env.GITHUB_ID,

View File

@ -4,7 +4,8 @@ block content
.col-xs-12
.row
.text-center
h3 Sign in with one of these options if you used them as your original sign up methods :
br
h4 Select from the following deprecated sign in methods to access your account and add a valid email address to it.
br
a.btn.btn-lg.btn-block.btn-social.btn-github(href='/auth/github')
i.fa.fa-github
@ -21,43 +22,3 @@ block content
a.btn.btn-lg.btn-block.btn-social.btn-twitter(href='/auth/twitter')
i.fa.fa-twitter
| Sign in with Twitter
br
h3
| We are unable to create new accounts using these methods
h4 If you haven't updated your email with us, you should do that as soon as possible,
| after you login here, to avoid losing access to your account.
br
p
a(href="/signin") Or click here to go back.
script.
$(document).ready(function() {
var method = localStorage.getItem('lastSigninMethodDeprecated'),
btnSelector = 'a.btn.btn-lg.btn-block.btn-social';
if (method) {
try {
var obj = JSON.parse(method);
} catch(e) {
console.error('Invalid sign in object stored', method);
return;
}
$.each($(btnSelector), function(i, item) {
if (
$(item).attr('href') === obj.methodLink &&
$(item).hasClass(obj.methodClass)
) {
$(item).addClass('active');
$(item).attr('title', 'This is your last signin method');
return false;
}
});
}
$(btnSelector).click(function() {
var obj = {};
$(this).removeClass('active');
obj.methodClass = $(this).attr('class').split(' ').pop();
obj.methodLink = $(this).attr('href');
localStorage.setItem('lastSigninMethodDeprecated', JSON.stringify(obj));
});
});