Skip to content

Commit

Permalink
Fix account activation success showing as error - Fix #122
Browse files Browse the repository at this point in the history
  • Loading branch information
MrEliasen committed Apr 30, 2018
1 parent bc9a61e commit 46fb903
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
31 changes: 21 additions & 10 deletions client/src/components/auth/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class AuthLogin extends React.Component {
this.state = {
email: '',
password: '',
error: '',
error: null,
success: null,
};

this.authenticate = this.authenticate.bind(this);
Expand All @@ -27,9 +28,11 @@ class AuthLogin extends React.Component {
componentDidMount() {
const url = new URL(document.location);
const error = url.searchParams.get('error');
const success = url.searchParams.get('success');

this.setState({
error: error || null,
success: success || null,
});

this.props.getStrategies();
Expand Down Expand Up @@ -68,12 +71,26 @@ class AuthLogin extends React.Component {
}

showStatus() {
if (!this.state.status) {
const state = {...this.state};

if (state.error) {
return <p className="alert alert-danger">
{state.error}
</p>;
}

if (state.success) {
return <p className="alert alert-success">
{state.success}
</p>;
}

if (!state.status) {
return null;
}

return <p className={`alert alert-${this.state.status.isError ? 'danger' : 'success'}`}>
{this.state.status.message}
return <p className={`alert alert-${state.status.isError ? 'danger' : 'success'}`}>
{state.status.message}
</p>;
}

Expand Down Expand Up @@ -124,12 +141,6 @@ class AuthLogin extends React.Component {
</Form>
}
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Officia, laboriosam!</p>
{
this.state.error &&
<p className="alert alert-danger">
{this.state.error}
</p>
}
{
this.props.strategies.map((strat) => {
if (strat.id === 'local') {
Expand Down
4 changes: 2 additions & 2 deletions server/src/api/authentication/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import oauthSetup from './strategies/oauth';
*/
function output(req, res, output, forceRedirect = false) {
const redirect = req.params.provider ? true : false;
const errorUrl = `${req.app.get('config').app.clientUrl}/auth?error=`;
const errorUrl = `${req.app.get('config').app.clientUrl}/auth?${output.status > 203 ? 'error' : 'success'}=`;

if (redirect || forceRedirect) {
return res.redirect(`${errorUrl}${output.error || output.message}`);
Expand Down Expand Up @@ -255,7 +255,7 @@ export function authenticate(req, res, next) {

return passport.authenticate(provider.id, Object.assign({session: false}, {scope: provider.scope || null}), (err, userDetails, info, status) => {
if (err) {
if (typeof err !== 'string') {
if (typeof err !== 'string') {
req.app.get('logger').error(err);
}

Expand Down

0 comments on commit 46fb903

Please sign in to comment.