Skip to content

Commit 910232d

Browse files
committedDec 8, 2017
use proper auth as condition handling
1 parent d68754d commit 910232d

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed
 

‎src/components/Account/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@ AccountPage.contextTypes = {
1616
authUser: PropTypes.object,
1717
};
1818

19-
export default withAuthorization(true)(AccountPage);
19+
const authCondition = (authUser) => !!authUser;
20+
21+
export default withAuthorization(authCondition)(AccountPage);

‎src/components/Home/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,6 @@ const UserList = ({ users }) =>
4545
)}
4646
</div>
4747

48-
export default withAuthorization(true)(HomePage);
48+
const authCondition = (authUser) => !!authUser;
49+
50+
export default withAuthorization(authCondition)(HomePage);

‎src/components/Session/withAuthorization.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import { withRouter } from 'react-router-dom';
55
import { firebase } from '../../firebase';
66
import * as routes from '../../constants/routes';
77

8-
const withAuthorization = (needsAuthorization) => (Component) => {
8+
const withAuthorization = (condition) => (Component) => {
99
class WithAuthorization extends React.Component {
1010
componentDidMount() {
1111
firebase.auth.onAuthStateChanged(authUser => {
12-
if (!authUser && needsAuthorization) {
12+
if (!condition(authUser)) {
1313
this.props.history.push(routes.SIGN_IN);
1414
}
1515
});

0 commit comments

Comments
 (0)
Please sign in to comment.