'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.SignInMessage = undefined;

var _extends2 = require('babel-runtime/helpers/extends');

var _extends3 = _interopRequireDefault(_extends2);

var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');

var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);

var _regenerator = require('babel-runtime/regenerator');

var _regenerator2 = _interopRequireDefault(_regenerator);

var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');

var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');

var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);

var _createClass2 = require('babel-runtime/helpers/createClass');

var _createClass3 = _interopRequireDefault(_createClass2);

var _inherits2 = require('babel-runtime/helpers/inherits');

var _inherits3 = _interopRequireDefault(_inherits2);

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _head = require('next/dist/lib/head.js');

var _head2 = _interopRequireDefault(_head);

var _index = require('next/dist/lib/router/index.js');

var _index2 = _interopRequireDefault(_index);

var _link = require('next/dist/lib/link.js');

var _link2 = _interopRequireDefault(_link);

var _universalCookie = require('universal-cookie');

var _universalCookie2 = _interopRequireDefault(_universalCookie);

var _nextAuthClient = require('next-auth-client');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var _jsxFileName = '/Users/iain/Development/next-auth/example/pages/index.js?entry';


var _class = function (_React$Component) {
  (0, _inherits3.default)(_class, _React$Component);

  (0, _createClass3.default)(_class, null, [{
    key: 'getInitialProps',
    value: function () {
      var _ref2 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(_ref) {
        var req = _ref.req;
        return _regenerator2.default.wrap(function _callee$(_context) {
          while (1) {
            switch (_context.prev = _context.next) {
              case 0:
                _context.next = 2;
                return _nextAuthClient.NextAuth.init({ req: req });

              case 2:
                _context.t0 = _context.sent;
                return _context.abrupt('return', {
                  session: _context.t0
                });

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

      function getInitialProps(_x) {
        return _ref2.apply(this, arguments);
      }

      return getInitialProps;
    }()
  }]);

  function _class(props) {
    (0, _classCallCheck3.default)(this, _class);

    var _this = (0, _possibleConstructorReturn3.default)(this, (_class.__proto__ || (0, _getPrototypeOf2.default)(_class)).call(this, props));

    _this.handleSignOutSubmit = _this.handleSignOutSubmit.bind(_this);
    return _this;
  }

  (0, _createClass3.default)(_class, [{
    key: 'handleSignOutSubmit',
    value: function handleSignOutSubmit(event) {
      event.preventDefault();

      // Save current URL so user is redirected back here after signing out
      var cookies = new _universalCookie2.default();
      cookies.set('redirect_url', window.location.pathname);

      _nextAuthClient.NextAuth.signout().then(function () {
        _index2.default.push('/auth/callback');
      }).catch(function (err) {
        _index2.default.push('/auth/error?action=signout');
      });
    }
  }, {
    key: 'render',
    value: function render() {
      return _react2.default.createElement('div', { className: 'container', __source: {
          fileName: _jsxFileName,
          lineNumber: 38
        }
      }, _react2.default.createElement(_head2.default, {
        __source: {
          fileName: _jsxFileName,
          lineNumber: 39
        }
      }, _react2.default.createElement('link', { rel: 'stylesheet', href: 'https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css', integrity: 'sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm', crossOrigin: 'anonymous', __source: {
          fileName: _jsxFileName,
          lineNumber: 40
        }
      }), _react2.default.createElement('script', { src: 'https://cdn.polyfill.io/v2/polyfill.min.js', __source: {
          fileName: _jsxFileName,
          lineNumber: 41
        }
      })), _react2.default.createElement('div', { className: 'text-center', __source: {
          fileName: _jsxFileName,
          lineNumber: 43
        }
      }, _react2.default.createElement('h1', { className: 'display-4 mt-3 mb-3', __source: {
          fileName: _jsxFileName,
          lineNumber: 44
        }
      }, 'NextAuth Example'), _react2.default.createElement('p', { className: 'lead mt-3 mb-3', __source: {
          fileName: _jsxFileName,
          lineNumber: 45
        }
      }, 'An example of how to use the ', _react2.default.createElement('a', { href: 'https://www.npmjs.com/package/next-auth', __source: {
          fileName: _jsxFileName,
          lineNumber: 45
        }
      }, 'NextAuth'), ' module.'), _react2.default.createElement(SignInMessage, (0, _extends3.default)({}, this.props, {
        __source: {
          fileName: _jsxFileName,
          lineNumber: 46
        }
      }))));
    }
  }]);

  return _class;
}(_react2.default.Component);

exports.default = _class;
var SignInMessage = exports.SignInMessage = function (_React$Component2) {
  (0, _inherits3.default)(SignInMessage, _React$Component2);

  function SignInMessage() {
    (0, _classCallCheck3.default)(this, SignInMessage);

    return (0, _possibleConstructorReturn3.default)(this, (SignInMessage.__proto__ || (0, _getPrototypeOf2.default)(SignInMessage)).apply(this, arguments));
  }

  (0, _createClass3.default)(SignInMessage, [{
    key: 'render',
    value: function render() {
      if (this.props.session.user) {
        return _react2.default.createElement(_react2.default.Fragment, {
          __source: {
            fileName: _jsxFileName,
            lineNumber: 57
          }
        }, _react2.default.createElement('p', {
          __source: {
            fileName: _jsxFileName,
            lineNumber: 58
          }
        }, _react2.default.createElement(_link2.default, { href: '/auth', __source: {
            fileName: _jsxFileName,
            lineNumber: 58
          }
        }, _react2.default.createElement('a', { className: 'btn btn-secondary', __source: {
            fileName: _jsxFileName,
            lineNumber: 58
          }
        }, 'Manage Account'))), _react2.default.createElement('form', { id: 'signout', method: 'post', action: '/auth/signout', onSubmit: this.handleSignOutSubmit, __source: {
            fileName: _jsxFileName,
            lineNumber: 59
          }
        }, _react2.default.createElement('input', { name: '_csrf', type: 'hidden', value: this.props.session.csrfToken, __source: {
            fileName: _jsxFileName,
            lineNumber: 60
          }
        }), _react2.default.createElement('button', { type: 'submit', className: 'btn btn-outline-secondary', __source: {
            fileName: _jsxFileName,
            lineNumber: 61
          }
        }, 'Sign out')));
      } else {
        return _react2.default.createElement(_react2.default.Fragment, {
          __source: {
            fileName: _jsxFileName,
            lineNumber: 67
          }
        }, _react2.default.createElement('p', {
          __source: {
            fileName: _jsxFileName,
            lineNumber: 68
          }
        }, _react2.default.createElement(_link2.default, { href: '/auth', __source: {
            fileName: _jsxFileName,
            lineNumber: 68
          }
        }, _react2.default.createElement('a', { className: 'btn btn-primary', __source: {
            fileName: _jsxFileName,
            lineNumber: 68
          }
        }, 'Sign in'))));
      }
    }
  }]);

  return SignInMessage;
}(_react2.default.Component);
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInBhZ2VzL2luZGV4LmpzIl0sIm5hbWVzIjpbIlJlYWN0IiwiSGVhZCIsIlJvdXRlciIsIkxpbmsiLCJDb29raWVzIiwiTmV4dEF1dGgiLCJyZXEiLCJpbml0Iiwic2Vzc2lvbiIsInByb3BzIiwiaGFuZGxlU2lnbk91dFN1Ym1pdCIsImJpbmQiLCJldmVudCIsInByZXZlbnREZWZhdWx0IiwiY29va2llcyIsInNldCIsIndpbmRvdyIsImxvY2F0aW9uIiwicGF0aG5hbWUiLCJzaWdub3V0IiwidGhlbiIsInB1c2giLCJjYXRjaCIsIkNvbXBvbmVudCIsIlNpZ25Jbk1lc3NhZ2UiLCJ1c2VyIiwiY3NyZlRva2VuIl0sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7QUFBQSxBQUFPOzs7O0FBQ1AsQUFBTzs7OztBQUNQLEFBQU87Ozs7QUFDUCxBQUFPOzs7O0FBQ1AsQUFBTzs7OztBQUNQLEFBQVM7Ozs7Ozs7Ozs7Ozs7O1lBR3VCLEEsVyxBQUFBOzs7Ozs7dUJBRVgseUJBQUEsQUFBUyxLQUFLLEVBQUMsSyxBQUFmLEFBQWM7Ozs7O0E7QUFBN0I7Ozs7Ozs7Ozs7Ozs7OztBQUlKOzs7a0JBQU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