auth0-react-lock
Version:
React Component for Auth0's Lock.js
92 lines (75 loc) • 3.64 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _auth0Lock = require('auth0-lock');
var _auth0Lock2 = _interopRequireDefault(_auth0Lock);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var Lock = function (_React$Component) {
_inherits(Lock, _React$Component);
function Lock() {
_classCallCheck(this, Lock);
return _possibleConstructorReturn(this, Object.getPrototypeOf(Lock).apply(this, arguments));
}
_createClass(Lock, [{
key: 'componentDidMount',
value: function componentDidMount() {
var clientID = this.props.clientID || this.props.clientId;
if (!clientID) {
throw Error("Client ID is strictly required");
}
var domain = this.props.domain;
this.lock = new _auth0Lock2.default(clientID, domain);
this.hash = this.lock.parseHash();
this.handleHash(this.hash, this.props.hashHandler);
}
}, {
key: 'handleHash',
value: function handleHash(hash, handlerFn) {
if (hash) {
if (hash.error) {
throw Error('There was an error logging in: ' + hash.error);
} else {
this.lock.getProfile(hash.id_token, handlerFn);
}
}
}
}, {
key: 'getLock',
value: function getLock() {
return this.lock;
}
}, {
key: 'showLock',
value: function showLock(cb) {
if (this.props.popup) {
if (typeof cb !== 'function') throw Error("Callback must be a function");
this.lock.show(this.props, cb);
} else {
this.lock.show(this.props);
}
}
}, {
key: 'render',
value: function render() {
var container = this.props.container;
if (container) {
return _react2.default.createElement('div', { id: container });
}
return false;
}
}]);
return Lock;
}(_react2.default.Component);
Lock.propTypes = {
domain: _react2.default.PropTypes.string.isRequired,
clientID: _react2.default.PropTypes.string,
clientId: _react2.default.PropTypes.string
};
exports.default = Lock;