mirror of
https://github.com/ascribe/onion.git
synced 2025-02-14 21:10:27 +01:00
Add whitelabel and isLoggedIn as arguments to ProxyHandler's redirectFunctions
This commit is contained in:
parent
b02695a33a
commit
34b1a2c1fc
@ -5,14 +5,14 @@ import withRouter from 'react-router/es6/withRouter';
|
|||||||
|
|
||||||
import UserStore from '../../stores/user_store';
|
import UserStore from '../../stores/user_store';
|
||||||
|
|
||||||
import { currentUserShape } from '../prop_types';
|
import { currentUserShape, whitelabelShape } from '../prop_types';
|
||||||
|
|
||||||
import AppConstants from '../../constants/application_constants';
|
import AppConstants from '../../constants/application_constants';
|
||||||
|
|
||||||
import { withCurrentUser } from '../../utils/react_utils';
|
import { withCurrentUser, withWhitelabel } from '../../utils/react_utils';
|
||||||
|
|
||||||
|
|
||||||
const { object } = React.PropTypes;
|
const { bool, object } = React.PropTypes;
|
||||||
const WHEN_ENUM = ['loggedIn', 'loggedOut'];
|
const WHEN_ENUM = ['loggedIn', 'loggedOut'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -28,7 +28,7 @@ export function AuthRedirect({ to, when }) {
|
|||||||
throw new Error(`"when" must be one of: [${whenValues}] got "${when}" instead`);
|
throw new Error(`"when" must be one of: [${whenValues}] got "${when}" instead`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return function redirectRoute(router, currentUser, query) {
|
return function redirectRoute(router, { query }, { isLoggedIn }) {
|
||||||
const { redirectAuthenticated, redirect } = query;
|
const { redirectAuthenticated, redirect } = query;
|
||||||
|
|
||||||
// The user of this handler specifies with `when`, what kind of status
|
// The user of this handler specifies with `when`, what kind of status
|
||||||
@ -37,7 +37,6 @@ export function AuthRedirect({ to, when }) {
|
|||||||
//
|
//
|
||||||
// So if when === 'loggedIn', we're checking if the user is logged in (and
|
// So if when === 'loggedIn', we're checking if the user is logged in (and
|
||||||
// vice versa)
|
// vice versa)
|
||||||
const isLoggedIn = !!currentUser.email;
|
|
||||||
const exprToValidate = when === 'loggedIn' ? isLoggedIn : !isLoggedIn;
|
const exprToValidate = when === 'loggedIn' ? isLoggedIn : !isLoggedIn;
|
||||||
|
|
||||||
// and redirect if `true`.
|
// and redirect if `true`.
|
||||||
@ -84,13 +83,11 @@ export function ProxyHandler(...redirectFunctions) {
|
|||||||
displayName: 'ProxyHandler',
|
displayName: 'ProxyHandler',
|
||||||
|
|
||||||
propTypes: {
|
propTypes: {
|
||||||
router: React.PropTypes.object.isRequired,
|
|
||||||
|
|
||||||
// Injected through HOCs
|
// Injected through HOCs
|
||||||
currentUser: currentUserShape.isRequired, // eslint-disable-line react/sort-prop-types
|
currentUser: currentUserShape.isRequired,
|
||||||
|
isLoggedIn: bool.isRequired,
|
||||||
// Provided from AscribeApp, after the routes have been initialized
|
router: React.PropTypes.object.isRequired,
|
||||||
whitelabel: React.PropTypes.object,
|
whitelabel: whitelabelShape.isRequired,
|
||||||
|
|
||||||
// Provided from router
|
// Provided from router
|
||||||
location: object,
|
location: object,
|
||||||
@ -116,15 +113,15 @@ export function ProxyHandler(...redirectFunctions) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
evaluateRedirectFunctions(props = this.props) {
|
evaluateRedirectFunctions(props = this.props) {
|
||||||
const { currentUser, location: { query }, router } = props;
|
const { currentUser, isLoggedIn, location, router, whitelabel } = props;
|
||||||
|
|
||||||
if (UserStore.hasLoaded() && !UserStore.isLoading()) {
|
if (UserStore.hasLoaded() && !UserStore.isLoading()) {
|
||||||
|
const context = { currentUser, isLoggedIn, whitelabel };
|
||||||
|
|
||||||
for (let i = 0; i < redirectFunctions.length; i++) {
|
for (let i = 0; i < redirectFunctions.length; i++) {
|
||||||
// if a redirectFunction redirects the user,
|
// if a redirectFunction redirects the user, it should return `true` and
|
||||||
// it should return `true` and therefore
|
// therefore stop/avoid the execution of all functions that follow
|
||||||
// stop/avoid the execution of all functions
|
if (redirectFunctions[i](router, location, context)) {
|
||||||
// that follow
|
|
||||||
if (redirectFunctions[i](router, currentUser, query)) {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -138,6 +135,6 @@ export function ProxyHandler(...redirectFunctions) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return withRouter(withCurrentUser(ProxyHandlerComponent));
|
return withRouter(withCurrentUser(withWhitelabel(ProxyHandlerComponent)));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ import { currentUserShape, whitelabelShape } from '../../../../prop_types';
|
|||||||
|
|
||||||
import { setDocumentTitle } from '../../../../../utils/dom_utils';
|
import { setDocumentTitle } from '../../../../../utils/dom_utils';
|
||||||
import { getLangText } from '../../../../../utils/lang_utils';
|
import { getLangText } from '../../../../../utils/lang_utils';
|
||||||
import { withCurrentUser, withWhiteLabel } from '../../../../../utils/react_utils';
|
import { withCurrentUser, withWhitelabel } from '../../../../../utils/react_utils';
|
||||||
|
|
||||||
let MarketPieceList = React.createClass({
|
let MarketPieceList = React.createClass({
|
||||||
propTypes: {
|
propTypes: {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user