Created
January 13, 2019 20:52
-
-
Save alexanmtz/5b9d4dc1e5833c5565e029136d01365d to your computer and use it in GitHub Desktop.
A Session component implemented on React to store in localStorage the user token
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
import React, { Component } from 'react' | |
import PropTypes from 'prop-types' | |
import Auth from '../../modules/auth' | |
class Session extends Component { | |
componentWillMount () { | |
const token = this.props.match.params.token | |
const referer = Auth.getReferer() | |
Auth.authenticateUser(token) | |
if (referer && referer !== '/') { | |
this.props.history.replace(referer) | |
} | |
else { | |
this.props.history.replace('/profile') | |
} | |
} | |
render () { | |
return ( | |
<div> | |
Session created | |
</div> | |
) | |
} | |
} | |
Session.propTypes = { | |
match: PropTypes.object, | |
history: PropTypes.object | |
} | |
export default Session |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment