Created
October 8, 2016 02:01
-
-
Save VictorCoding/dd3996a4f29aad694af45f0924f4e349 to your computer and use it in GitHub Desktop.
auth comonent
This file contains hidden or 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
class MatchWhenAuthorized extends Component { | |
constructor(props) { | |
super(); | |
console.log(props); | |
this.props = props; | |
this.state = { | |
isAuthenticated: false, | |
} | |
} | |
componentWillMount() { | |
Firebase.auth().onAuthStateChanged((user) => { | |
this.setState({ | |
isAuthenticated: user ? true : false, | |
}); | |
}); | |
} | |
render() { | |
const { isAuthenticated } = this.state; | |
const props = this.props; | |
return ( | |
<Match {...props} render={props => ( | |
isAuthenticated ? ( | |
<this.props.component {...this.props}/> | |
) : ( | |
<Redirect to={{ | |
pathname: '/login', | |
state: { from: props.location } | |
}}/> | |
) | |
)}/> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment