From 7567f7bd45ccd2fe525c075c727bff348809c7e8 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 6 Apr 2021 11:58:14 -0500 Subject: [PATCH] Redirect user away from /auth/sign_in after success --- app/soapbox/features/auth_login/components/login_page.js | 7 ++++++- .../features/auth_login/components/otp_auth_form.js | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/soapbox/features/auth_login/components/login_page.js b/app/soapbox/features/auth_login/components/login_page.js index 1ebdc8dda..9f9b3b8ce 100644 --- a/app/soapbox/features/auth_login/components/login_page.js +++ b/app/soapbox/features/auth_login/components/login_page.js @@ -1,5 +1,6 @@ import React from 'react'; import { connect } from 'react-redux'; +import { Redirect } from 'react-router-dom'; import ImmutablePureComponent from 'react-immutable-pure-component'; import LoginForm from './login_form'; import OtpAuthForm from './otp_auth_form'; @@ -22,6 +23,7 @@ class LoginPage extends ImmutablePureComponent { isLoading: false, mfa_auth_needed: false, mfa_token: '', + shouldRedirect: false, } getFormData = (form) => { @@ -36,6 +38,7 @@ class LoginPage extends ImmutablePureComponent { dispatch(logIn(username, password)).then(({ access_token }) => { return dispatch(verifyCredentials(access_token)); }).then(account => { + this.setState({ shouldRedirect: true }); if (typeof me === 'string') { dispatch(switchAccount(account.id)); } @@ -50,7 +53,9 @@ class LoginPage extends ImmutablePureComponent { } render() { - const { isLoading, mfa_auth_needed, mfa_token } = this.state; + const { isLoading, mfa_auth_needed, mfa_token, shouldRedirect } = this.state; + + if (shouldRedirect) return ; if (mfa_auth_needed) return ; diff --git a/app/soapbox/features/auth_login/components/otp_auth_form.js b/app/soapbox/features/auth_login/components/otp_auth_form.js index d6b21664a..132e4e3c5 100644 --- a/app/soapbox/features/auth_login/components/otp_auth_form.js +++ b/app/soapbox/features/auth_login/components/otp_auth_form.js @@ -1,5 +1,6 @@ import React from 'react'; import { connect } from 'react-redux'; +import { Redirect } from 'react-router-dom'; import { injectIntl, FormattedMessage, defineMessages } from 'react-intl'; import ImmutablePureComponent from 'react-immutable-pure-component'; import { otpVerify, verifyCredentials, switchAccount } from 'soapbox/actions/auth'; @@ -18,6 +19,7 @@ class OtpAuthForm extends ImmutablePureComponent { state = { isLoading: false, code_error: '', + shouldRedirect: false, } static propTypes = { @@ -39,6 +41,7 @@ class OtpAuthForm extends ImmutablePureComponent { this.setState({ code_error: false }); return dispatch(verifyCredentials(access_token)); }).then(account => { + this.setState({ shouldRedirect: true }); return dispatch(switchAccount(account.id)); }).catch(error => { this.setState({ isLoading: false }); @@ -52,7 +55,9 @@ class OtpAuthForm extends ImmutablePureComponent { render() { const { intl } = this.props; - const { code_error } = this.state; + const { code_error, shouldRedirect } = this.state; + + if (shouldRedirect) return ; return (