From 46fb9030d371053932001dcba73d990c1f1bb709 Mon Sep 17 00:00:00 2001 From: SirMrE Date: Wed, 18 Apr 2018 00:02:56 +0100 Subject: [PATCH] Fix account activation success showing as error - Fix #122 --- client/src/components/auth/login.js | 31 +++++++++++++++++--------- server/src/api/authentication/index.js | 4 ++-- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/client/src/components/auth/login.js b/client/src/components/auth/login.js index 1df6672..df0368e 100644 --- a/client/src/components/auth/login.js +++ b/client/src/components/auth/login.js @@ -18,7 +18,8 @@ class AuthLogin extends React.Component { this.state = { email: '', password: '', - error: '', + error: null, + success: null, }; this.authenticate = this.authenticate.bind(this); @@ -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(); @@ -68,12 +71,26 @@ class AuthLogin extends React.Component { } showStatus() { - if (!this.state.status) { + const state = {...this.state}; + + if (state.error) { + return

+ {state.error} +

; + } + + if (state.success) { + return

+ {state.success} +

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

- {this.state.status.message} + return

+ {state.status.message}

; } @@ -124,12 +141,6 @@ class AuthLogin extends React.Component { }

Lorem ipsum dolor sit amet consectetur adipisicing elit. Officia, laboriosam!

- { - this.state.error && -

- {this.state.error} -

- } { this.props.strategies.map((strat) => { if (strat.id === 'local') { diff --git a/server/src/api/authentication/index.js b/server/src/api/authentication/index.js index d6d39fe..4d16276 100644 --- a/server/src/api/authentication/index.js +++ b/server/src/api/authentication/index.js @@ -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}`); @@ -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); }