Created
May 23, 2017 23:35
-
-
Save srph/5d9b725faff0215105dd5fd090873b04 to your computer and use it in GitHub Desktop.
Full Story: User identification with React+REdux
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
| import React, { Component } from 'react'; | |
| import {connect} from 'react-redux'; | |
| /** | |
| * Initializes fullstory | |
| */ | |
| class FullStory extends Component { | |
| componentDidMount() { | |
| if (this.props.authenticated) { | |
| this.identify(); | |
| } | |
| } | |
| componentWillReceiveProps(nextProps) { | |
| if (this.props.authenticated && !nextProps.authenticated) { | |
| window.FS.clearUserCookie(); | |
| } else if (!this.props.authenticated && nextProps.authenticated) { | |
| this.identify(); | |
| } | |
| } | |
| identify() { | |
| const {auth} = this.props; | |
| window.FS.identify(auth.id, { | |
| displayName: auth.name, | |
| email: auth.email | |
| }); | |
| } | |
| render() { | |
| return null; | |
| } | |
| } | |
| export default connect(state => ({ | |
| auth: state.auth.data, | |
| authenticated: state.auth.token != null | |
| }))(FullStory); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment