Skip to content
This repository has been archived by the owner on May 19, 2020. It is now read-only.

Commit

Permalink
Don't show old login screen when user is no authed
Browse files Browse the repository at this point in the history
  • Loading branch information
el-mapache committed Aug 11, 2017
1 parent b0fa204 commit e514147
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 42 deletions.
32 changes: 10 additions & 22 deletions static_src/components/main_container.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@

import React from 'react';
import PropTypes from 'prop-types';
import style from 'cloudgov-style/css/cloudgov-style.css';
import overrideStyle from '../css/overrides.css';

import createStyler from '../util/create_styler';
import userProvider from './user_provider.jsx';

import Disclaimer from './disclaimer.jsx';
import Footer from './footer.jsx';
import GlobalErrorContainer from './global_error_container.jsx';
Expand All @@ -17,6 +12,10 @@ import OrgStore from '../stores/org_store.js';
import SpaceStore from '../stores/space_store.js';
import { Nav } from './navbar.jsx';

const propTypes = {
children: PropTypes.any
};

function stateSetter() {
return {
currentOrgGuid: OrgStore.currentOrgGuid,
Expand All @@ -28,7 +27,7 @@ function stateSetter() {
class App extends React.Component {
constructor(props) {
super(props);
this.styler = createStyler(style, overrideStyle);

this.state = stateSetter();;
this._onChange = this._onChange.bind(this);
}
Expand All @@ -46,24 +45,15 @@ class App extends React.Component {
}

render() {
let content;

if (this.state.isLoggedIn) {
content = this.props.children;
} else {
content = <Login />;
}


return (
<div>
<Disclaimer />
<Header />
<div className={ this.styler('main_content', 'content-no_sidebar') }>
<div className="main_content content-no_sidebar">
<GlobalErrorContainer />
<main className={ this.styler('usa-content') }>
<div className={ this.styler('content', 'grid') }>
{ content }
<main className="usa-content">
<div className="content grid">
{ this.props.children }
</div>
</main>
</div>
Expand All @@ -73,9 +63,7 @@ class App extends React.Component {
}
}

App.propTypes = {
children: PropTypes.any
};
App.propTypes = propTypes;

App.defaultProps = {
children: []
Expand Down
26 changes: 6 additions & 20 deletions static_src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,43 +133,29 @@ export function checkAuth(...args) {
// load. and kick off an error action so the user is aware that
// something is amiss. Definitely avoid sending them through a login
// flow which might also be broken.
const loginError = LoginStore.error;
return errorActions.noticeError(loginError);
return errorActions.noticeError(LoginStore.error);
}

// We're interested in the most recent fetchStatus, so avoid checking
// LoginStore.isLoggedIn which won't be the latest in case of an error.
if (authStatus.status === 'authorized') {
// Normal page load
return Promise.resolve();
}

// The user is Unauthenicated. We could redirect to a home page where
// user could click login but since we don't have any such page, just
// start the login flow by redirecting to /handshake. This is as if they
// had clicked login.
windowUtil.redirect('/handshake');

// Just in case something goes wrong, don't leave the user hanging. Show
// a delayed loading indicator to give them a hint. Hopefully the
// redirect is quick and they never see the loader.
// Show a redirect loading component in case of slow connection
routerActions.navigate(Loading, {
text: 'Redirecting to login',
loadingDelayMS: 3000,
style: 'inline'
});

// Stop the routing
next(false);

// Hang the promise chain to avoid additional loading and API calls
const hang = new Promise();
return hang;
// Redirect the user to the cloud.gov login page
return Promise.reject(windowUtil.redirect('/handshake'));
})
.then(() => {
userActions.fetchCurrentUser({ orgGuid, spaceGuid });
next();
});
})
.catch(() => next(false));
}

export function clearErrors(...args) {
Expand Down

0 comments on commit e514147

Please sign in to comment.