Get login form working!
This commit is contained in:
parent
83a711cd3e
commit
9e50293e67
3 changed files with 13 additions and 8 deletions
|
@ -6,7 +6,7 @@ export const AUTH_LOGGED_IN = 'AUTH_LOGGED_IN';
|
||||||
|
|
||||||
export function createAuthApp() {
|
export function createAuthApp() {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
api(getState).post('/api/v1/apps', {
|
return api(getState).post('/api/v1/apps', {
|
||||||
// TODO: Add commit hash to client_name
|
// TODO: Add commit hash to client_name
|
||||||
client_name: `SoapboxFE_${(new Date()).toISOString()}`,
|
client_name: `SoapboxFE_${(new Date()).toISOString()}`,
|
||||||
redirect_uris: 'urn:ietf:wg:oauth:2.0:oob',
|
redirect_uris: 'urn:ietf:wg:oauth:2.0:oob',
|
||||||
|
@ -30,7 +30,7 @@ export function createAuthApp() {
|
||||||
export function logIn(username, password) {
|
export function logIn(username, password) {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
const app = getState().getIn(['auth', 'app']);
|
const app = getState().getIn(['auth', 'app']);
|
||||||
api(getState).post('/oauth/token', {
|
return api(getState).post('/oauth/token', {
|
||||||
client_id: app.get('client_id'),
|
client_id: app.get('client_id'),
|
||||||
client_secret: app.get('client_secret'),
|
client_secret: app.get('client_secret'),
|
||||||
redirect_uri: 'urn:ietf:wg:oauth:2.0:oob',
|
redirect_uri: 'urn:ietf:wg:oauth:2.0:oob',
|
||||||
|
|
|
@ -3,6 +3,7 @@ import { connect } from 'react-redux'
|
||||||
import ImmutablePureComponent from 'react-immutable-pure-component';
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
||||||
import { createAuthApp, logIn } from 'gabsocial/actions/auth';
|
import { createAuthApp, logIn } from 'gabsocial/actions/auth';
|
||||||
import { Redirect } from 'react-router-dom';
|
import { Redirect } from 'react-router-dom';
|
||||||
|
import { fetchMe } from 'gabsocial/actions/me';
|
||||||
|
|
||||||
const mapStateToProps = (state, props) => ({
|
const mapStateToProps = (state, props) => ({
|
||||||
me: state.get('me'),
|
me: state.get('me'),
|
||||||
|
@ -21,8 +22,11 @@ class LoginForm extends ImmutablePureComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
handleSubmit = (event) => {
|
handleSubmit = (event) => {
|
||||||
const {username, password} = this.getFormData(event.target);
|
const { dispatch } = this.props;
|
||||||
this.props.dispatch(logIn(username, password));
|
const { username, password } = this.getFormData(event.target);
|
||||||
|
dispatch(logIn(username, password)).then(() => {
|
||||||
|
dispatch(fetchMe());
|
||||||
|
});
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -74,10 +74,11 @@ class WrappedRoute extends React.Component {
|
||||||
|
|
||||||
if (!publicRoute && me == false) {
|
if (!publicRoute && me == false) {
|
||||||
const actualUrl = encodeURIComponent(this.props.computedMatch.url);
|
const actualUrl = encodeURIComponent(this.props.computedMatch.url);
|
||||||
return <Route path={this.props.path} component={() => {
|
return <Redirect to={`/auth/sign_in?redirect_uri=${actualUrl}`} />;
|
||||||
window.location.href = `/auth/sign_in?redirect_uri=${actualUrl}`;
|
// return <Route path={this.props.path} component={() => {
|
||||||
return null;
|
// window.location.href = `/auth/sign_in?redirect_uri=${actualUrl}`;
|
||||||
}}/>
|
// return null;
|
||||||
|
// }}/>
|
||||||
}
|
}
|
||||||
|
|
||||||
return <Route {...rest} render={this.renderComponent} />;
|
return <Route {...rest} render={this.renderComponent} />;
|
||||||
|
|
Loading…
Reference in a new issue