-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
issue #21 - adds auth HoCs to for redirecting with or without an orga…
…nization - [x] adds hasOrgRedirect to go to /main if on /enroll and has an org already - [x] adds withOrg to send back to /enroll if on /main and you don't have an org yet - [x] wraps /enroll and /main components in protection - [x] updates redux hydration to make sure correct data is sent back and not null errors occur
- Loading branch information
ortonomy
committed
Feb 20, 2018
1 parent
e20105b
commit 9da2d8a
Showing
6 changed files
with
81 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// react | ||
import React, { Component } from 'react'; | ||
|
||
// library dependencies | ||
import { Redirect } from 'react-router-dom'; | ||
import { connect } from 'react-redux'; | ||
|
||
//debug | ||
import Debug from '../../../utils/Debug'; | ||
|
||
|
||
const hasOrgRedirect = (WrappedComponent) => { | ||
|
||
@connect( | ||
state => ( | ||
{ | ||
Login: state.Login | ||
} | ||
), | ||
null | ||
) | ||
class hasOrgRedirector extends Component { | ||
render() { | ||
Debug.log('[render] of <hasOrgRedirect>: ', this.props); | ||
const { Login } = this.props; | ||
if ( Login.user.userOrg ) { | ||
return (<Redirect to='/main' />); | ||
} else { | ||
return (<WrappedComponent {...this.props} />); | ||
} | ||
} | ||
} | ||
|
||
return hasOrgRedirector; | ||
} | ||
|
||
export default hasOrgRedirect; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// react | ||
import React, { Component } from 'react'; | ||
|
||
// library dependencies | ||
import { Redirect } from 'react-router-dom'; | ||
import { connect } from 'react-redux'; | ||
|
||
//debug | ||
import Debug from '../../../utils/Debug'; | ||
|
||
|
||
const withOrg = (ProtectedComponent) => { | ||
|
||
@connect( | ||
state => ( | ||
{ | ||
Login: state.Login, | ||
} | ||
), | ||
null | ||
) | ||
class HasOrg extends Component { | ||
render() { | ||
Debug.log('[render] of <withOrg>: ', this.props); | ||
const { Login } = this.props; | ||
if ( Login.user.userOrg ) { | ||
return (<ProtectedComponent {...this.props} />); | ||
} else { | ||
return (<Redirect to='/enroll' />); | ||
} | ||
} | ||
} | ||
|
||
return HasOrg; | ||
} | ||
|
||
export default withOrg; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters