Redirect login form if user is already logged in
This commit is contained in:
parent
8f07c6ea2a
commit
da4f5b200c
1 changed files with 10 additions and 1 deletions
|
@ -2,6 +2,11 @@ import React from 'react';
|
||||||
import { connect } from 'react-redux'
|
import { connect } from 'react-redux'
|
||||||
import ImmutablePureComponent from 'react-immutable-pure-component';
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
||||||
import { createApp, logIn } from 'gabsocial/actions/auth';
|
import { createApp, logIn } from 'gabsocial/actions/auth';
|
||||||
|
import { Redirect } from 'react-router-dom';
|
||||||
|
|
||||||
|
const mapStateToProps = (state, props) => ({
|
||||||
|
me: state.get('me'),
|
||||||
|
});
|
||||||
|
|
||||||
class LoginForm extends ImmutablePureComponent {
|
class LoginForm extends ImmutablePureComponent {
|
||||||
|
|
||||||
|
@ -22,6 +27,10 @@ class LoginForm extends ImmutablePureComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
const { me } = this.props;
|
||||||
|
|
||||||
|
if (me) return <Redirect to="/home" />;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form onSubmit={this.handleSubmit}>
|
<form onSubmit={this.handleSubmit}>
|
||||||
<input name='username' placeholder='me@example.com' />
|
<input name='username' placeholder='me@example.com' />
|
||||||
|
@ -32,4 +41,4 @@ class LoginForm extends ImmutablePureComponent {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default connect()(LoginForm);
|
export default connect(mapStateToProps)(LoginForm);
|
||||||
|
|
Loading…
Reference in a new issue