introduce props.credentials.authenticating

helps prevent auth dupes and allows "flash" of Login component to be avoided
while waiting for an authentication attempt that may succeed
This commit is contained in:
Michael Bradley, Jr 2018-10-19 18:39:04 -05:00
parent ee13fcf3ad
commit 3071c489a7
2 changed files with 17 additions and 5 deletions

View File

@ -28,6 +28,10 @@ class AppContainer extends Component {
}
queryStringAuthenticate() {
if (this.props.credentials.authenticating) {
return;
}
const token = this.getQueryToken();
if (!token) {
@ -46,7 +50,10 @@ class AppContainer extends Component {
}
requireAuthentication() {
return this.props.credentials.token && this.props.credentials.host && !this.props.credentials.authenticated;
return !this.props.credentials.authenticating &&
!this.props.credentials.authenticated &&
this.props.credentials.token &&
this.props.credentials.host;
}
componentDidUpdate(){
@ -71,7 +78,8 @@ class AppContainer extends Component {
}
shouldRenderLogin() {
return this.props.authenticationError || !this.props.credentials.authenticated;
return this.props.authenticationError ||
!(this.props.credentials.authenticated || this.props.credentials.authenticating);
}
toggleTheme() {

View File

@ -200,7 +200,7 @@ function compilingContract(state = false, action) {
return state;
}
const DEFAULT_CREDENTIALS_STATE = {host: DEFAULT_HOST, token: '', authenticated: false};
const DEFAULT_CREDENTIALS_STATE = {host: DEFAULT_HOST, token: '', authenticated: false, authenticating: false};
function credentials(state = DEFAULT_CREDENTIALS_STATE, action) {
if (action.type === LOGOUT[SUCCESS]) {
@ -208,17 +208,21 @@ function credentials(state = DEFAULT_CREDENTIALS_STATE, action) {
}
if (action.type === AUTHENTICATE[FAILURE]) {
return {error: action.error, authenticated: false};
return {error: action.error, authenticated: false, authenticating: false};
}
if (action.type === AUTHENTICATE[SUCCESS]) {
return {...state, ...{authenticated: true, token: action.token, host: action.host, error: null}};
return {...state, ...{authenticated: true, authenticating: false, token: action.token, host: action.host, error: null}};
}
if (action.type === FETCH_CREDENTIALS[SUCCESS]) {
return {...state, ...{token: action.token, host: action.host}};
}
if (action.type === AUTHENTICATE[REQUEST]) {
return {...state, ...{authenticating: true}};
}
return state;
}