Skip to content

Instantly share code, notes, and snippets.

@alexanmtz
Created January 13, 2019 20:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexanmtz/5b9d4dc1e5833c5565e029136d01365d to your computer and use it in GitHub Desktop.
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
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