All files / src/containers/SingleSignOn CallbackComponent.js

0% Statements 0/47
0% Branches 0/35
0% Functions 0/15
0% Lines 0/15
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36                                                                       
import PropTypes from 'prop-types';
import React, { PureComponent } from 'react';
 
class CallbackComponent extends PureComponent {
  componentDidMount() {
    this.props.userManager.signinRedirectCallback()
      .then((user) => this._onRedirectSuccess(user))
      .catch((error) => this._onRedirectError(error));
  }
 
  _onRedirectSuccess(user) {
    this.props.successCallback(user);
  }
 
  _onRedirectError(error) {
    if (this.props.errorCallback) {
      this.props.errorCallback(error);
    } else {
      throw new Error(`Error handling redirect callback: ${error.message}`);
    }
  }
 
  render() {
    return React.Children.only(this.props.children);
  }
}
 
CallbackComponent.propTypes = {
  children: PropTypes.element.isRequired,
  userManager: PropTypes.object.isRequired,
  successCallback: PropTypes.func.isRequired,
  errorCallback: PropTypes.func,
};
 
export default CallbackComponent;