mirror of
https://github.com/Unleash/unleash.git
synced 2025-05-08 01:15:49 +02:00
fix: Cleanup logut flow
This commit is contained in:
parent
83e2e522f4
commit
51c29ca044
@ -17,12 +17,13 @@ export default class App extends PureComponent {
|
|||||||
static propTypes = {
|
static propTypes = {
|
||||||
location: PropTypes.object.isRequired,
|
location: PropTypes.object.isRequired,
|
||||||
match: PropTypes.object.isRequired,
|
match: PropTypes.object.isRequired,
|
||||||
|
history: PropTypes.object.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div className={styles.container}>
|
<div className={styles.container}>
|
||||||
<AuthenticationContainer />
|
<AuthenticationContainer history={this.props.history} />
|
||||||
<Layout fixedHeader>
|
<Layout fixedHeader>
|
||||||
<Header location={this.props.location} />
|
<Header location={this.props.location} />
|
||||||
<Content className="mdl-color--grey-50">
|
<Content className="mdl-color--grey-50">
|
||||||
|
@ -13,8 +13,6 @@ export default class FeatureListComponent extends React.Component {
|
|||||||
featureMetrics: PropTypes.object.isRequired,
|
featureMetrics: PropTypes.object.isRequired,
|
||||||
fetchFeatureToggles: PropTypes.func,
|
fetchFeatureToggles: PropTypes.func,
|
||||||
fetchArchive: PropTypes.func,
|
fetchArchive: PropTypes.func,
|
||||||
logoutUser: PropTypes.func,
|
|
||||||
logout: PropTypes.bool,
|
|
||||||
revive: PropTypes.func,
|
revive: PropTypes.func,
|
||||||
updateSetting: PropTypes.func.isRequired,
|
updateSetting: PropTypes.func.isRequired,
|
||||||
toggleFeature: PropTypes.func,
|
toggleFeature: PropTypes.func,
|
||||||
@ -24,10 +22,6 @@ export default class FeatureListComponent extends React.Component {
|
|||||||
};
|
};
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
if (this.props.logout) {
|
|
||||||
this.props.logoutUser();
|
|
||||||
this.props.history.push(`/`);
|
|
||||||
}
|
|
||||||
if (this.props.fetchFeatureToggles) {
|
if (this.props.fetchFeatureToggles) {
|
||||||
this.props.fetchFeatureToggles();
|
this.props.fetchFeatureToggles();
|
||||||
} else {
|
} else {
|
||||||
|
@ -3,7 +3,6 @@ import { toggleFeature, fetchFeatureToggles } from '../../store/feature-actions'
|
|||||||
import { updateSettingForGroup } from '../../store/settings/actions';
|
import { updateSettingForGroup } from '../../store/settings/actions';
|
||||||
|
|
||||||
import FeatureListComponent from './list-component';
|
import FeatureListComponent from './list-component';
|
||||||
import { logoutUser } from '../../store/user/actions';
|
|
||||||
import { hasPermission } from '../../permissions';
|
import { hasPermission } from '../../permissions';
|
||||||
|
|
||||||
export const mapStateToPropsConfigurable = isFeature => state => {
|
export const mapStateToPropsConfigurable = isFeature => state => {
|
||||||
@ -74,7 +73,6 @@ export const mapStateToPropsConfigurable = isFeature => state => {
|
|||||||
};
|
};
|
||||||
const mapStateToProps = mapStateToPropsConfigurable(true);
|
const mapStateToProps = mapStateToPropsConfigurable(true);
|
||||||
const mapDispatchToProps = {
|
const mapDispatchToProps = {
|
||||||
logoutUser,
|
|
||||||
toggleFeature,
|
toggleFeature,
|
||||||
fetchFeatureToggles,
|
fetchFeatureToggles,
|
||||||
updateSetting: updateSettingForGroup('feature'),
|
updateSetting: updateSettingForGroup('feature'),
|
||||||
|
@ -35,6 +35,7 @@ class AuthComponent extends React.Component {
|
|||||||
user: PropTypes.object.isRequired,
|
user: PropTypes.object.isRequired,
|
||||||
unsecureLogin: PropTypes.func.isRequired,
|
unsecureLogin: PropTypes.func.isRequired,
|
||||||
fetchFeatureToggles: PropTypes.func.isRequired,
|
fetchFeatureToggles: PropTypes.func.isRequired,
|
||||||
|
history: PropTypes.object.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@ -48,6 +49,7 @@ class AuthComponent extends React.Component {
|
|||||||
unsecureLogin={this.props.unsecureLogin}
|
unsecureLogin={this.props.unsecureLogin}
|
||||||
authDetails={authDetails}
|
authDetails={authDetails}
|
||||||
fetchFeatureToggles={this.props.fetchFeatureToggles}
|
fetchFeatureToggles={this.props.fetchFeatureToggles}
|
||||||
|
history={this.props.history}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
@ -7,6 +7,7 @@ class SimpleAuthenticationComponent extends React.Component {
|
|||||||
authDetails: PropTypes.object.isRequired,
|
authDetails: PropTypes.object.isRequired,
|
||||||
unsecureLogin: PropTypes.func.isRequired,
|
unsecureLogin: PropTypes.func.isRequired,
|
||||||
fetchFeatureToggles: PropTypes.func.isRequired,
|
fetchFeatureToggles: PropTypes.func.isRequired,
|
||||||
|
history: PropTypes.object.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
handleSubmit = evt => {
|
handleSubmit = evt => {
|
||||||
@ -15,7 +16,10 @@ class SimpleAuthenticationComponent extends React.Component {
|
|||||||
const user = { email };
|
const user = { email };
|
||||||
const path = evt.target.action;
|
const path = evt.target.action;
|
||||||
|
|
||||||
this.props.unsecureLogin(path, user).then(this.props.fetchFeatureToggles);
|
this.props
|
||||||
|
.unsecureLogin(path, user)
|
||||||
|
.then(this.props.fetchFeatureToggles)
|
||||||
|
.then(() => this.props.history.push(`/`));
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
23
frontend/src/component/user/logout-component.jsx
Normal file
23
frontend/src/component/user/logout-component.jsx
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import { Card, CardText, CardTitle } from 'react-mdl';
|
||||||
|
import { styles as commonStyles } from '../common';
|
||||||
|
|
||||||
|
export default class FeatureListComponent extends React.Component {
|
||||||
|
static propTypes = {
|
||||||
|
logoutUser: PropTypes.func.isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
this.props.logoutUser();
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<Card shadow={0} className={commonStyles.fullwidth}>
|
||||||
|
<CardTitle>Logged out</CardTitle>
|
||||||
|
<CardText>You have now been successfully logged out of Unleash. Thank you for using Unleash. </CardText>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
11
frontend/src/component/user/logout-container.jsx
Normal file
11
frontend/src/component/user/logout-container.jsx
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import { connect } from 'react-redux';
|
||||||
|
import LogoutComponent from './logout-component';
|
||||||
|
import { logoutUser } from '../../store/user/actions';
|
||||||
|
|
||||||
|
const mapDispatchToProps = {
|
||||||
|
logoutUser,
|
||||||
|
};
|
||||||
|
|
||||||
|
const mapStateToProps = () => ({});
|
||||||
|
|
||||||
|
export default connect(mapStateToProps, mapDispatchToProps)(LogoutComponent);
|
@ -1,11 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import FeatureListContainer from './../../component/feature/list-container';
|
import LogoutContainer from './../../component/user/logout-container';
|
||||||
import PropTypes from 'prop-types';
|
|
||||||
|
|
||||||
const render = ({ history }) => <FeatureListContainer logout history={history} />;
|
const render = () => <LogoutContainer />;
|
||||||
|
|
||||||
render.propTypes = {
|
|
||||||
history: PropTypes.object.isRequired,
|
|
||||||
};
|
|
||||||
|
|
||||||
export default render;
|
export default render;
|
||||||
|
@ -9,6 +9,8 @@ import {
|
|||||||
TOGGLE_FEATURE_TOGGLE,
|
TOGGLE_FEATURE_TOGGLE,
|
||||||
} from './feature-actions';
|
} from './feature-actions';
|
||||||
|
|
||||||
|
import { USER_LOGOUT } from './user/actions';
|
||||||
|
|
||||||
const features = (state = new List([]), action) => {
|
const features = (state = new List([]), action) => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case ADD_FEATURE_TOGGLE:
|
case ADD_FEATURE_TOGGLE:
|
||||||
@ -38,6 +40,9 @@ const features = (state = new List([]), action) => {
|
|||||||
case RECEIVE_FEATURE_TOGGLES:
|
case RECEIVE_FEATURE_TOGGLES:
|
||||||
debug(RECEIVE_FEATURE_TOGGLES, action);
|
debug(RECEIVE_FEATURE_TOGGLES, action);
|
||||||
return new List(action.featureToggles.map($Map));
|
return new List(action.featureToggles.map($Map));
|
||||||
|
case USER_LOGOUT:
|
||||||
|
debug(USER_LOGOUT, action);
|
||||||
|
return new List([]);
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import api from '../../data/user-api';
|
import api from '../../data/user-api';
|
||||||
import { dispatchAndThrow } from '../util';
|
import { dispatchAndThrow } from '../util';
|
||||||
export const UPDATE_USER = 'UPDATE_USER';
|
export const UPDATE_USER = 'UPDATE_USER';
|
||||||
|
export const USER_LOGOUT = 'USER_LOGOUT';
|
||||||
export const START_FETCH_USER = 'START_FETCH_USER';
|
export const START_FETCH_USER = 'START_FETCH_USER';
|
||||||
export const ERROR_FETCH_USER = 'ERROR_FETCH_USER';
|
export const ERROR_FETCH_USER = 'ERROR_FETCH_USER';
|
||||||
const debug = require('debug')('unleash:user-actions');
|
const debug = require('debug')('unleash:user-actions');
|
||||||
@ -38,5 +39,9 @@ export function unsecureLogin(path, user) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function logoutUser() {
|
export function logoutUser() {
|
||||||
return () => api.logoutUser().catch(handleError);
|
return dispatch => {
|
||||||
|
dispatch({ type: USER_LOGOUT });
|
||||||
|
|
||||||
|
return api.logoutUser().catch(handleError);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { Map as $Map } from 'immutable';
|
import { Map as $Map } from 'immutable';
|
||||||
import { UPDATE_USER } from './actions';
|
import { UPDATE_USER, USER_LOGOUT } from './actions';
|
||||||
import { AUTH_REQUIRED } from '../util';
|
import { AUTH_REQUIRED } from '../util';
|
||||||
|
|
||||||
const userStore = (state = new $Map(), action) => {
|
const userStore = (state = new $Map(), action) => {
|
||||||
@ -13,6 +13,8 @@ const userStore = (state = new $Map(), action) => {
|
|||||||
case AUTH_REQUIRED:
|
case AUTH_REQUIRED:
|
||||||
state = state.set('authDetails', action.error.body).set('showDialog', true);
|
state = state.set('authDetails', action.error.body).set('showDialog', true);
|
||||||
return state;
|
return state;
|
||||||
|
case USER_LOGOUT:
|
||||||
|
return new $Map();
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user