Created
February 14, 2019 13:14
-
-
Save bietkul/c484d8a27db0ad0a2a21ba42fc18c1b0 to your computer and use it in GitHub Desktop.
Route to handle the authentication response
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'; | |
| import Router from 'next/router'; | |
| import { func } from 'prop-types'; | |
| import Auth from '../utils/authenticate'; | |
| import { authConfig } from '../utils/constants'; | |
| import { login } from '../modules/actions/user'; | |
| import Page from '../components/Page'; | |
| class Authenticate extends Component { | |
| componentDidMount() { | |
| const { loginUser } = this.props; | |
| const auth = new Auth(authConfig); | |
| auth | |
| .parseTokens() | |
| .then((user) => { | |
| const userNameSplited = user.idTokenPayload.name.split(' '); | |
| loginUser({ | |
| first_name: userNameSplited[0], | |
| last_name: userNameSplited[1], | |
| email: user.idTokenPayload.email, | |
| verified_email: false, | |
| addresses: [], | |
| }).then(() => Router.push('/')); | |
| }) | |
| .catch(() => Router.push('/')); | |
| } | |
| render() { | |
| return <div>Loading ...</div>; | |
| } | |
| } | |
| Authenticate.propTypes = { | |
| loginUser: func, | |
| }; | |
| const mapDispatchToProps = dispatch => ({ | |
| loginUser: payload => dispatch(login(payload)), | |
| }); | |
| export default Page( | |
| connect( | |
| null, | |
| mapDispatchToProps, | |
| )(Authenticate), | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment