Skip to content

Instantly share code, notes, and snippets.

@vdelacou
Created June 14, 2018 09:06
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 vdelacou/c596cab4667f485fedcd2a0e0303908d to your computer and use it in GitHub Desktop.
Save vdelacou/c596cab4667f485fedcd2a0e0303908d to your computer and use it in GitHub Desktop.
Change Jhipster login to work with Auth0
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