react-facebook-next
Version:
Facebook components like a Login button, Like, Share, Comments or Embedded Post
97 lines (76 loc) • 3.08 kB
JavaScript
import _extends from 'babel-runtime/helpers/extends';
import _regeneratorRuntime from 'babel-runtime/regenerator';
import _asyncToGenerator from 'babel-runtime/helpers/asyncToGenerator';
import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
import _inherits from 'babel-runtime/helpers/inherits';
var _class, _temp;
import PropTypes from 'prop-types';
import Process from './Process';
var Login = (_temp = _class = function (_Process) {
_inherits(Login, _Process);
function Login() {
_classCallCheck(this, Login);
return _possibleConstructorReturn(this, _Process.apply(this, arguments));
}
Login.prototype.process = function () {
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(facebook) {
var _props, scope, fields, returnScopes, rerequest, reauthorize, loginQpts, authType, response;
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_props = this.props, scope = _props.scope, fields = _props.fields, returnScopes = _props.returnScopes, rerequest = _props.rerequest, reauthorize = _props.reauthorize;
loginQpts = { scope: scope };
authType = [];
if (returnScopes) {
loginQpts.return_scopes = true;
}
if (rerequest) {
authType.push('rerequest');
}
if (reauthorize) {
authType.push('reauthenticate');
}
if (authType.length) {
loginQpts.auth_type = authType.join(',');
}
_context.next = 9;
return facebook.login(loginQpts);
case 9:
response = _context.sent;
if (!(response.status !== 'connected')) {
_context.next = 12;
break;
}
throw new Error('Unauthorized user');
case 12:
return _context.abrupt('return', facebook.getTokenDetailWithProfile({ fields: fields }));
case 13:
case 'end':
return _context.stop();
}
}
}, _callee, this);
}));
function process(_x) {
return _ref.apply(this, arguments);
}
return process;
}();
return Login;
}(Process), _class.propTypes = _extends({}, Process.propTypes, {
scope: PropTypes.string.isRequired,
fields: PropTypes.arrayOf(PropTypes.string),
returnScopes: PropTypes.bool,
rerequest: PropTypes.bool,
reauthorize: PropTypes.bool
}), _class.defaultProps = _extends({}, Process.defaultProps, {
scope: '',
fields: ['id', 'first_name', 'last_name', 'middle_name', 'name', 'email', 'locale', 'gender', 'timezone', 'verified', 'link'],
returnScopes: false,
rerequest: false,
reauthorize: false
}), _temp);
export { Login as default };
//# sourceMappingURL=Login.js.map