Commit 47434e1c authored by Alf Eaton's avatar Alf Eaton

Move stateless variables outside the AuthenticatedComponent class

parent 29e867c3
Pipeline #1378 failed with stage
in 4 minutes and 5 seconds
......@@ -8,19 +8,20 @@ import Authsome from 'authsome'
import Actions from '../actions'
const authsome = new Authsome(
CONFIG['authsome'].mode,
{teams: CONFIG['authsome'].teams}
)
const failRedirect = CONFIG['authsome']['fail-redirect']
export function requireAuthentication (Component, operation, selector) {
class AuthenticatedComponent extends React.Component {
constructor (props) {
super(props)
this.authsome = new Authsome(
CONFIG['authsome'].mode,
{ teams: CONFIG['authsome'].teams }
)
this.checkAuthorization = this.checkAuthorization.bind(this)
this.checkAuth = this.checkAuth.bind(this)
this.failRedirect = CONFIG['authsome']['fail-redirect']
}
componentWillMount () {
......@@ -40,10 +41,10 @@ export function requireAuthentication (Component, operation, selector) {
let object = selector(this.props.state)
try {
if (this.authsome.can(currentUser, operation, object)) {
if (authsome.can(currentUser, operation, object)) {
return <Component {...this.props} />
} else if (this.failRedirect) {
return this.props.pushState(this.failRedirect)
} else if (failRedirect) {
return this.props.pushState(failRedirect)
} else {
<span />
}
......@@ -76,7 +77,7 @@ export function requireAuthentication (Component, operation, selector) {
currentUser: PropTypes.object.isRequired,
pushState: PropTypes.func.isRequired,
state: PropTypes.object
}
}
function mapState (state) {
return {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment