Skip to content

Commit bcf25c1

Browse files
committed
Show error popup when linking OAuth accounts
1 parent 170e201 commit bcf25c1

File tree

7 files changed

+89
-12
lines changed

7 files changed

+89
-12
lines changed

client/modules/IDE/components/ErrorModal.jsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ class ErrorModal extends React.Component {
1515
);
1616
}
1717

18+
oauthError() {
19+
return (
20+
<p>
21+
{'There was an error linking your GitHub account. This account has already been linked'}
22+
{' to another account.'}
23+
</p>
24+
);
25+
}
26+
1827
staleSession() {
1928
return (
2029
<p>
@@ -42,6 +51,8 @@ class ErrorModal extends React.Component {
4251
return this.staleSession();
4352
} else if (this.props.type === 'staleProject') {
4453
return this.staleProject();
54+
} else if (this.props.type === 'oauthError') {
55+
return this.oauthError();
4556
}
4657
})()}
4758
</div>

client/modules/User/components/AccountForm.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ AccountForm.propTypes = {
115115
newPassword: PropTypes.object.isRequired, // eslint-disable-line
116116
}).isRequired,
117117
user: PropTypes.shape({
118-
verified: PropTypes.number.isRequired,
118+
verified: PropTypes.string.isRequired,
119119
emailVerificationInitiate: PropTypes.bool.isRequired,
120120
}).isRequired,
121121
handleSubmit: PropTypes.func.isRequired,

client/modules/User/pages/AccountView.jsx

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@ import { bindActionCreators } from 'redux';
55
import { Tab, Tabs, TabList, TabPanel } from 'react-tabs';
66
import { Helmet } from 'react-helmet';
77
import { withTranslation } from 'react-i18next';
8+
import { withRouter, browserHistory } from 'react-router';
9+
import { parse } from 'query-string';
810
import { updateSettings, initiateVerification, createApiKey, removeApiKey } from '../actions';
911
import AccountForm from '../components/AccountForm';
1012
import apiClient from '../../../utils/apiClient';
1113
import { validateSettings } from '../../../utils/reduxFormUtils';
1214
import SocialAuthButton from '../components/SocialAuthButton';
1315
import APIKeyForm from '../components/APIKeyForm';
1416
import Nav from '../../../components/Nav';
17+
import ErrorModal from '../../IDE/components/ErrorModal';
18+
import Overlay from '../../App/components/Overlay';
1519

1620
function SocialLoginPanel(props) {
1721
const { user } = props;
@@ -53,6 +57,9 @@ class AccountView extends React.Component {
5357
}
5458

5559
render() {
60+
const queryParams = parse(this.props.location.search);
61+
const showError = !!queryParams.error;
62+
const errorType = queryParams.error;
5663
const accessTokensUIEnabled = window.process.env.UI_ACCESS_TOKEN_ENABLED;
5764

5865
return (
@@ -63,6 +70,20 @@ class AccountView extends React.Component {
6370

6471
<Nav layout="dashboard" />
6572

73+
{showError &&
74+
<Overlay
75+
title="Error Linking Account"
76+
ariaLabel="OAuth Error"
77+
closeOverlay={() => {
78+
browserHistory.push(this.props.location.pathname);
79+
}}
80+
>
81+
<ErrorModal
82+
type="oauthError"
83+
/>
84+
</Overlay>
85+
}
86+
6687
<main className="account-settings">
6788
<header className="account-settings__header">
6889
<h1 className="account-settings__title">{this.props.t('AccountView.Settings')}</h1>
@@ -127,13 +148,17 @@ function asyncValidate(formProps, dispatch, props) {
127148
AccountView.propTypes = {
128149
previousPath: PropTypes.string.isRequired,
129150
theme: PropTypes.string.isRequired,
130-
t: PropTypes.func.isRequired
151+
t: PropTypes.func.isRequired,
152+
location: PropTypes.shape({
153+
search: PropTypes.string.isRequired,
154+
pathname: PropTypes.string.isRequired
155+
}).isRequired
131156
};
132157

133-
export default withTranslation()(reduxForm({
158+
export default withTranslation()(withRouter(reduxForm({
134159
form: 'updateAllSettings',
135160
fields: ['username', 'email', 'currentPassword', 'newPassword'],
136161
validate: validateSettings,
137162
asyncValidate,
138163
asyncBlurFields: ['username', 'email', 'currentPassword']
139-
}, mapStateToProps, mapDispatchToProps)(AccountView));
164+
}, mapStateToProps, mapDispatchToProps)(AccountView)));

client/styles/components/_error-modal.scss

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717

1818
.error-modal__content {
1919
padding: #{20 / $base-font-size}rem;
20-
padding-top: 0;
20+
padding-top: #{40 / $base-font-size}rem;
2121
padding-bottom: #{60 / $base-font-size}rem;
22+
max-width: #{500 / $base-font-size}rem;
23+
& p {
24+
font-size: #{16 / $base-font-size}rem;
25+
}
2226
}

package-lock.json

Lines changed: 41 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@
195195
"primer-tooltips": "^1.5.11",
196196
"prop-types": "^15.6.2",
197197
"q": "^1.4.1",
198+
"query-string": "^6.13.2",
198199
"react": "^16.12.0",
199200
"react-dom": "^16.12.0",
200201
"react-helmet": "^5.1.3",

server/server.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ app.get('/auth/github/callback', (req, res, next) => {
140140
passport.authenticate('github', { failureRedirect: '/login' }, (err, user) => {
141141
if (err) {
142142
// use query string param to show error;
143-
res.redirect('/account');
143+
res.redirect('/account?error=github');
144144
return;
145145
}
146146

@@ -159,7 +159,7 @@ app.get('/auth/google/callback', (req, res, next) => {
159159
passport.authenticate('google', { failureRedirect: '/login' }, (err, user) => {
160160
if (err) {
161161
// use query string param to show error;
162-
res.redirect('/account');
162+
res.redirect('/account?error=google');
163163
return;
164164
}
165165

0 commit comments

Comments
 (0)