Skip to content

Instantly share code, notes, and snippets.

@srph
Created May 23, 2017 23:35
Show Gist options
  • Select an option

  • Save srph/5d9b725faff0215105dd5fd090873b04 to your computer and use it in GitHub Desktop.

Select an option

Save srph/5d9b725faff0215105dd5fd090873b04 to your computer and use it in GitHub Desktop.
Full Story: User identification with React+REdux
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