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:
committed by
Stuart Taylor
parent
74eb179c7b
commit
b4332a0def
@ -4,6 +4,7 @@ import { PassportConfigurator } from
|
|||||||
import passportProviders from './passport-providers';
|
import passportProviders from './passport-providers';
|
||||||
import url from 'url';
|
import url from 'url';
|
||||||
import jwt from 'jsonwebtoken';
|
import jwt from 'jsonwebtoken';
|
||||||
|
import dedent from 'dedent';
|
||||||
|
|
||||||
const passportOptions = {
|
const passportOptions = {
|
||||||
emailOptional: true,
|
emailOptional: true,
|
||||||
@ -133,11 +134,24 @@ export default function setupPassport(app) {
|
|||||||
delete redirect.search;
|
delete redirect.search;
|
||||||
|
|
||||||
const { accessToken } = userInfo;
|
const { accessToken } = userInfo;
|
||||||
|
const { provider } = config;
|
||||||
if (accessToken && accessToken.id) {
|
if (accessToken && accessToken.id) {
|
||||||
|
if (provider === 'auth0') {
|
||||||
req.flash(
|
req.flash(
|
||||||
'success',
|
'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 = {
|
const cookieConfig = {
|
||||||
signed: !!req.signedCookies,
|
signed: !!req.signedCookies,
|
||||||
maxAge: accessToken.ttl,
|
maxAge: accessToken.ttl,
|
||||||
|
@ -23,6 +23,7 @@ export default {
|
|||||||
authPath: '/auth/facebook',
|
authPath: '/auth/facebook',
|
||||||
callbackURL: '/auth/facebook/callback',
|
callbackURL: '/auth/facebook/callback',
|
||||||
callbackPath: '/auth/facebook/callback',
|
callbackPath: '/auth/facebook/callback',
|
||||||
|
useCustomCallback: true,
|
||||||
successRedirect: successRedirect,
|
successRedirect: successRedirect,
|
||||||
failureRedirect: failureRedirect,
|
failureRedirect: failureRedirect,
|
||||||
scope: ['email'],
|
scope: ['email'],
|
||||||
@ -51,6 +52,7 @@ export default {
|
|||||||
authPath: '/auth/google',
|
authPath: '/auth/google',
|
||||||
callbackURL: '/auth/google/callback',
|
callbackURL: '/auth/google/callback',
|
||||||
callbackPath: '/auth/google/callback',
|
callbackPath: '/auth/google/callback',
|
||||||
|
useCustomCallback: true,
|
||||||
successRedirect: successRedirect,
|
successRedirect: successRedirect,
|
||||||
failureRedirect: failureRedirect,
|
failureRedirect: failureRedirect,
|
||||||
scope: ['email', 'profile'],
|
scope: ['email', 'profile'],
|
||||||
@ -78,6 +80,7 @@ export default {
|
|||||||
authPath: '/auth/twitter',
|
authPath: '/auth/twitter',
|
||||||
callbackURL: '/auth/twitter/callback',
|
callbackURL: '/auth/twitter/callback',
|
||||||
callbackPath: '/auth/twitter/callback',
|
callbackPath: '/auth/twitter/callback',
|
||||||
|
useCustomCallback: true,
|
||||||
successRedirect: successRedirect,
|
successRedirect: successRedirect,
|
||||||
failureRedirect: failureRedirect,
|
failureRedirect: failureRedirect,
|
||||||
consumerKey: process.env.TWITTER_KEY,
|
consumerKey: process.env.TWITTER_KEY,
|
||||||
@ -105,6 +108,7 @@ export default {
|
|||||||
authPath: '/auth/linkedin',
|
authPath: '/auth/linkedin',
|
||||||
callbackURL: '/auth/linkedin/callback',
|
callbackURL: '/auth/linkedin/callback',
|
||||||
callbackPath: '/auth/linkedin/callback',
|
callbackPath: '/auth/linkedin/callback',
|
||||||
|
useCustomCallback: true,
|
||||||
successRedirect: successRedirect,
|
successRedirect: successRedirect,
|
||||||
failureRedirect: failureRedirect,
|
failureRedirect: failureRedirect,
|
||||||
clientID: process.env.LINKEDIN_ID,
|
clientID: process.env.LINKEDIN_ID,
|
||||||
@ -142,6 +146,7 @@ export default {
|
|||||||
authPath: '/auth/github',
|
authPath: '/auth/github',
|
||||||
callbackURL: '/auth/github/callback',
|
callbackURL: '/auth/github/callback',
|
||||||
callbackPath: '/auth/github/callback',
|
callbackPath: '/auth/github/callback',
|
||||||
|
useCustomCallback: true,
|
||||||
successRedirect: successRedirect,
|
successRedirect: successRedirect,
|
||||||
failureRedirect: failureRedirect,
|
failureRedirect: failureRedirect,
|
||||||
clientID: process.env.GITHUB_ID,
|
clientID: process.env.GITHUB_ID,
|
||||||
|
@ -4,7 +4,8 @@ block content
|
|||||||
.col-xs-12
|
.col-xs-12
|
||||||
.row
|
.row
|
||||||
.text-center
|
.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
|
br
|
||||||
a.btn.btn-lg.btn-block.btn-social.btn-github(href='/auth/github')
|
a.btn.btn-lg.btn-block.btn-social.btn-github(href='/auth/github')
|
||||||
i.fa.fa-github
|
i.fa.fa-github
|
||||||
@ -21,43 +22,3 @@ block content
|
|||||||
a.btn.btn-lg.btn-block.btn-social.btn-twitter(href='/auth/twitter')
|
a.btn.btn-lg.btn-block.btn-social.btn-twitter(href='/auth/twitter')
|
||||||
i.fa.fa-twitter
|
i.fa.fa-twitter
|
||||||
| Sign in with 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));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
Reference in New Issue
Block a user