mirror of
https://gitlab.com/wheres-the-tp/ui-mobile.git
synced 2026-01-25 06:04:55 -06:00
27 lines
718 B
JavaScript
27 lines
718 B
JavaScript
import mapPropsStream from 'recompose/mapPropsStream';
|
|
import { compose, lifecycle } from 'recompose';
|
|
import AuthManager from '../AuthManager';
|
|
import { withRouterContext } from './routeEnhancers';
|
|
import { getPathname, loginWithBackto } from '../helpers/RouteHelpers';
|
|
|
|
export const withAuthed = mapPropsStream(props$ =>
|
|
props$.combineLatest(AuthManager.checkIsAuthed(), (props, isAuthed) => {
|
|
return {
|
|
...props,
|
|
isAuthed,
|
|
};
|
|
})
|
|
);
|
|
|
|
export const withAuthRedirect = compose(
|
|
withRouterContext,
|
|
withAuthed,
|
|
lifecycle({
|
|
componentDidMount() {
|
|
if (!this.props.isAuthed) {
|
|
const pathname = getPathname(this.props);
|
|
this.props.router.history.replace(loginWithBackto(pathname));
|
|
}
|
|
},
|
|
})
|
|
);
|