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

Don't show old login screen when user is not authed #1193

Merged
merged 2 commits into from
Aug 14, 2017
Merged
Show file tree
Hide file tree
Changes from all 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
18 changes: 0 additions & 18 deletions static_src/components/login.jsx

This file was deleted.

33 changes: 10 additions & 23 deletions static_src/components/main_container.jsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@

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';
import Header from './header.jsx';
import Login from './login.jsx';
import LoginStore from '../stores/login_store.js';
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 +26,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 +44,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 +62,7 @@ class App extends React.Component {
}
}

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

App.defaultProps = {
children: []
Expand Down
33 changes: 6 additions & 27 deletions static_src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import appActions from './actions/app_actions.js';
import cfApi from './util/cf_api.js';
import errorActions from './actions/error_actions';
import Loading from './components/loading.jsx';
import Login from './components/login.jsx';
import loginActions from './actions/login_actions';
import LoginStore from './stores/login_store';
import NotFound from './components/not_found.jsx';
Expand All @@ -25,11 +24,6 @@ import routerActions from './actions/router_actions.js';

const MAX_OVERVIEW_SPACES = 10;

export function login(next) {
routerActions.navigate(Login);
next();
}

export function overview(next) {
pageActions.load();

Expand Down Expand Up @@ -133,43 +127,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 All @@ -190,7 +170,6 @@ export function notFound(next) {
const routes = {
'/': overview,
'/dashboard': overview,
'/login': login,
'/org': {
'/:orgGuid': {
'/spaces': {
Expand Down