Skip to content
This repository has been archived by the owner on Apr 15, 2019. It is now read-only.

Setup auto-login option and fix login redirect for better developer experience - Closes #633 #640

Merged
merged 5 commits into from
Aug 23, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/components/login/loginForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { isValidPassphrase } from '../../utils/passphrase';
import networksRaw from './networks';
import Passphrase from '../passphrase';
import styles from './login.css';
import env from '../../constants/env';

/**
* The container component containing login
Expand Down Expand Up @@ -42,7 +43,9 @@ class LoginForm extends React.Component {

componentDidUpdate() {
if (this.props.account && this.props.account.address) {
this.props.history.replace('/main/transactions');
const search = this.props.history.location.search;
this.props.history.replace(
search.indexOf('?referrer') === 0 ? search.replace('?referrer=', '') : '/main/transactions');
if (this.state.address) {
Cookies.set('address', this.state.address);
}
Expand Down Expand Up @@ -111,6 +114,14 @@ class LoginForm extends React.Component {
...this.validators.address(address),
...this.validators.passphrase(passphrase),
});

// ignore this in coverage as it is hard to test and does not run in production
/* istanbul ignore if */
if (!env.production && Cookies.get('autologin') && passphrase) {
setTimeout(() => {
this.onLoginSubmission(passphrase);
});
}
}

render() {
Expand Down
5 changes: 4 additions & 1 deletion src/components/login/loginForm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('LoginForm', () => {
const props = {
peers: {},
account,
history: [],
history: {},
onAccountUpdated: () => {},
setActiveDialog: spy(),
activePeerSet: (network) => {
Expand Down Expand Up @@ -73,6 +73,9 @@ describe('LoginForm', () => {
props.account = { address: 'dummy' };
props.history = {
replace: spy(),
location: {
search: '',
},
};

it('calls this.props.history.replace(\'/main/transactions\')', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/privateRoute/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { connect } from 'react-redux';

export const PrivateRouteRender = ({ render, isAuthenticated, ...rest }) => (
<Route {...rest} render={ matchProps => (
isAuthenticated ? render(matchProps) : <Redirect to='/' />
isAuthenticated ? render(matchProps) : <Redirect to={`/?referrer=${rest.history.location.pathname}`} />
)}/>
);

Expand Down
1 change: 1 addition & 0 deletions src/components/privateRoute/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ describe('PrivateRouteRender', () => {
<div>
<Route path='/' component={Public} />
<PrivateRouteRender
history={ { location: { pathname: '' } } }
path='/private'
render={({ match }) => <Route to={`${match.url}/test`} component={Private}/>}
isAuthenticated={isAuthenticated} />
Expand Down