Created
June 14, 2018 09:06
-
-
Save vdelacou/c596cab4667f485fedcd2a0e0303908d to your computer and use it in GitHub Desktop.
Change Jhipster login to work with Auth0
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 * as React from 'react'; | |
import { connect } from 'react-redux'; | |
import { RouteComponentProps } from 'react-router-dom'; | |
import { Storage } from 'react-jhipster'; | |
import { IRootState } from 'app/shared/reducers'; | |
import { getSession } from 'app/shared/reducers/authentication'; | |
import Auth0 from 'app/config/auth0'; | |
export interface ILoginProps extends StateProps, DispatchProps, RouteComponentProps<{}> { } | |
export class Login extends React.Component<ILoginProps> { | |
componentDidMount() { | |
const auth0 = new Auth0(); | |
auth0.lock.on('authenticated', authResult => { | |
Storage.local.set('jhi-authenticationToken', authResult.accessToken); | |
this.props.getSession(); | |
// go be done better by using axios and redux | |
window.location.href = '/#/'; | |
}); | |
auth0.lock.on('hide', () => { | |
this.props.history.push('/'); | |
}); | |
auth0.lock.show(); | |
} | |
render() { | |
return ( | |
<div /> | |
); | |
} | |
} | |
const mapStateToProps = (storeState: IRootState) => ({}); | |
const mapDispatchToProps = { getSession }; | |
type StateProps = ReturnType<typeof mapStateToProps>; | |
type DispatchProps = typeof mapDispatchToProps; | |
export default connect(mapStateToProps, mapDispatchToProps)(Login); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment