mirror of https://github.com/embarklabs/embark.git
separate "should authenticate" logic from "do authenticate" logic
but don't maintain separate methods for query string vs. props
This commit is contained in:
parent
a5c972903b
commit
8a9b8f25ab
|
@ -24,38 +24,46 @@ import {
|
||||||
} from '../reducers/selectors';
|
} from '../reducers/selectors';
|
||||||
|
|
||||||
class AppContainer extends Component {
|
class AppContainer extends Component {
|
||||||
queryStringAuthenticate() {
|
|
||||||
if (this.props.credentials.authenticating) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const token = getQueryToken(this.props.lcation);
|
|
||||||
|
|
||||||
if (!token) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const host = DEFAULT_HOST;
|
|
||||||
if (token === this.props.credentials.token && this.props.credentials.host === host) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
return this.props.authenticate(host, token);
|
|
||||||
}
|
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.props.fetchCredentials();
|
this.props.fetchCredentials();
|
||||||
this.props.fetchTheme();
|
this.props.fetchTheme();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
doAuthenticate() {
|
||||||
|
let {host, token} = this.props.credentials;
|
||||||
|
const queryToken = getQueryToken(this.props.location);
|
||||||
|
|
||||||
|
if (queryToken) {
|
||||||
|
host = DEFAULT_HOST;
|
||||||
|
token = queryToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.props.authenticate(host, token);
|
||||||
|
}
|
||||||
|
|
||||||
requireAuthentication() {
|
requireAuthentication() {
|
||||||
return !(this.props.credentials.authenticating ||
|
if (this.props.credentials.authenticating) {
|
||||||
this.props.credentials.authenticated) &&
|
return false;
|
||||||
this.props.credentials.token &&
|
}
|
||||||
this.props.credentials.host;
|
|
||||||
|
const queryToken = getQueryToken(this.props.location);
|
||||||
|
if (queryToken && !(queryToken === this.props.credentials.token &&
|
||||||
|
this.props.credentials.host === DEFAULT_HOST)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.props.credentials.authenticated &&
|
||||||
|
this.props.credentials.host &&
|
||||||
|
this.props.credentials.token) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidUpdate(){
|
componentDidUpdate(){
|
||||||
if (!this.queryStringAuthenticate() && this.requireAuthentication()) {
|
if (this.requireAuthentication()) {
|
||||||
this.props.authenticate(this.props.credentials.host, this.props.credentials.token);
|
this.doAuthenticate();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getQueryToken(this.props.location) &&
|
if (getQueryToken(this.props.location) &&
|
||||||
|
|
Loading…
Reference in New Issue