Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@bmc/react-common / dist / login / Login.js
Size: Mime:
import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import React, { Component } from 'react';
import { Redirect } from 'react-router-dom';
import SignIn from './SignIn';
import { withAuth } from '@okta/okta-react';
export default withAuth(
/*#__PURE__*/
function (_Component) {
  _inherits(Login, _Component);

  function Login(props) {
    var _this;

    _classCallCheck(this, Login);

    _this = _possibleConstructorReturn(this, _getPrototypeOf(Login).call(this, props));
    _this.onSuccess = _this.onSuccess.bind(_assertThisInitialized(_this));
    _this.onError = _this.onError.bind(_assertThisInitialized(_this));
    _this.state = {
      authenticated: null
    };

    _this.checkAuthentication();

    return _this;
  }

  _createClass(Login, [{
    key: "checkAuthentication",
    value: function () {
      var _checkAuthentication = _asyncToGenerator(
      /*#__PURE__*/
      _regeneratorRuntime.mark(function _callee() {
        var authenticated;
        return _regeneratorRuntime.wrap(function _callee$(_context) {
          while (1) {
            switch (_context.prev = _context.next) {
              case 0:
                _context.next = 2;
                return this.props.auth.isAuthenticated();

              case 2:
                authenticated = _context.sent;

                if (authenticated !== this.state.authenticated) {
                  this.setState({
                    authenticated: authenticated
                  });
                }

              case 4:
              case "end":
                return _context.stop();
            }
          }
        }, _callee, this);
      }));

      function checkAuthentication() {
        return _checkAuthentication.apply(this, arguments);
      }

      return checkAuthentication;
    }()
  }, {
    key: "componentDidUpdate",
    value: function componentDidUpdate() {
      this.checkAuthentication();
    }
  }, {
    key: "onSuccess",
    value: function onSuccess(res) {
      if (res.status === 'SUCCESS') {
        return this.props.auth.redirect({
          sessionToken: res.session.token,
          scopes: ['openid', 'groups', 'profile', 'email']
        });
      } else {
        console.error("Unexpected authentication state.");
        console.log(res); // The user can be in another authentication state that requires further action.
        // For more information about these states, see:
        //   https://github.com/okta/okta-signin-widget#rendereloptions-success-error
      }

      if (this.props.onSuccess) {
        this.props.onSuccess.call(this, res);
      }
    }
  }, {
    key: "onError",
    value: function onError(err) {
      console.log('error logging in', err);

      if (this.props.onError) {
        this.props.onError.call(this, err);
      }
    }
  }, {
    key: "render",
    value: function render() {
      if (this.state.authenticated === null) return null;

      if (this.state.authenticated) {
        var referrer_path = localStorage.getItem("secureLoginReferrerPath");
        var pathname = referrer_path || '/';
        return React.createElement(Redirect, {
          to: {
            pathname: pathname
          }
        });
      } else {
        return React.createElement(SignIn, {
          baseUrl: this.props.baseUrl,
          onSuccess: this.onSuccess,
          onError: this.onError,
          scopes: ['openid', 'groups', 'profile', 'email']
        });
      } // return this.state.authenticated ?
      //     <Redirect to={{pathname: '/'}}/> :
      //     <SignIn
      //         baseUrl={this.props.baseUrl}
      //         onSuccess={this.onSuccess}
      //         onError={this.onError}
      //         scopes={['openid', 'groups', 'profile', 'email']}
      //     />;

    }
  }]);

  return Login;
}(Component));
//# sourceMappingURL=Login.js.map