Repository URL to install this package:
|
Version:
0.4.16 ▾
|
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 { withAuth } from '@okta/okta-react';
import { Button } from 'react-bootstrap';
export default withAuth(
/*#__PURE__*/
function (_Component) {
_inherits(LogInOutButton, _Component);
function LogInOutButton(props) {
var _this;
_classCallCheck(this, LogInOutButton);
_this = _possibleConstructorReturn(this, _getPrototypeOf(LogInOutButton).call(this, props));
_this.state = {
authenticated: null
};
_this.checkAuthentication = _this.checkAuthentication.bind(_assertThisInitialized(_this));
_this.login = _this.login.bind(_assertThisInitialized(_this));
_this.logout = _this.logout.bind(_assertThisInitialized(_this));
return _this;
}
_createClass(LogInOutButton, [{
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: "componentDidMount",
value: function () {
var _componentDidMount = _asyncToGenerator(
/*#__PURE__*/
_regeneratorRuntime.mark(function _callee2() {
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
this.checkAuthentication();
case 1:
case "end":
return _context2.stop();
}
}
}, _callee2, this);
}));
function componentDidMount() {
return _componentDidMount.apply(this, arguments);
}
return componentDidMount;
}()
}, {
key: "componentDidUpdate",
value: function () {
var _componentDidUpdate = _asyncToGenerator(
/*#__PURE__*/
_regeneratorRuntime.mark(function _callee3() {
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
this.checkAuthentication();
case 1:
case "end":
return _context3.stop();
}
}
}, _callee3, this);
}));
function componentDidUpdate() {
return _componentDidUpdate.apply(this, arguments);
}
return componentDidUpdate;
}()
}, {
key: "login",
value: function () {
var _login = _asyncToGenerator(
/*#__PURE__*/
_regeneratorRuntime.mark(function _callee4() {
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
while (1) {
switch (_context4.prev = _context4.next) {
case 0:
this.props.auth.login('/');
case 1:
case "end":
return _context4.stop();
}
}
}, _callee4, this);
}));
function login() {
return _login.apply(this, arguments);
}
return login;
}()
}, {
key: "logout",
value: function () {
var _logout = _asyncToGenerator(
/*#__PURE__*/
_regeneratorRuntime.mark(function _callee5() {
return _regeneratorRuntime.wrap(function _callee5$(_context5) {
while (1) {
switch (_context5.prev = _context5.next) {
case 0:
localStorage.removeItem("secureLoginReferrerPath");
this.props.auth.logout('/');
case 2:
case "end":
return _context5.stop();
}
}
}, _callee5, this);
}));
function logout() {
return _logout.apply(this, arguments);
}
return logout;
}()
}, {
key: "render",
value: function render() {
var isAuthenticated = this.state.authenticated;
if (isAuthenticated === null) return null;
return React.createElement("span", null, isAuthenticated ? React.createElement(Button, {
onClick: this.logout
}, "Logout") : React.createElement(Button, {
onClick: this.login
}, "Login"));
}
}]);
return LogInOutButton;
}(Component));
//# sourceMappingURL=LogInOutButton.js.map