aws-amplify-react
Version:
AWS Amplify is a JavaScript library for Frontend and mobile developers building cloud-enabled applications.
138 lines • 6.84 kB
JavaScript
;
/*
* Copyright 2017-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
* the License. A copy of the License is located at
*
* http://aws.amazon.com/apache2.0/
*
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
var React = require("react");
var react_1 = require("react");
var Authenticator_1 = require("./Authenticator");
var Authenticator_2 = require("./Authenticator");
exports.Authenticator = Authenticator_2.default;
var AuthPiece_1 = require("./AuthPiece");
exports.AuthPiece = AuthPiece_1.default;
var SignIn_1 = require("./SignIn");
exports.SignIn = SignIn_1.default;
var ConfirmSignIn_1 = require("./ConfirmSignIn");
exports.ConfirmSignIn = ConfirmSignIn_1.default;
var SignOut_1 = require("./SignOut");
exports.SignOut = SignOut_1.default;
var RequireNewPassword_1 = require("./RequireNewPassword");
exports.RequireNewPassword = RequireNewPassword_1.default;
var SignUp_1 = require("./SignUp");
exports.SignUp = SignUp_1.default;
var ConfirmSignUp_1 = require("./ConfirmSignUp");
exports.ConfirmSignUp = ConfirmSignUp_1.default;
var VerifyContact_1 = require("./VerifyContact");
exports.VerifyContact = VerifyContact_1.default;
var ForgotPassword_1 = require("./ForgotPassword");
exports.ForgotPassword = ForgotPassword_1.default;
var Greetings_1 = require("./Greetings");
exports.Greetings = Greetings_1.default;
var FederatedSignIn_1 = require("./FederatedSignIn");
exports.FederatedSignIn = FederatedSignIn_1.default;
exports.FederatedButtons = FederatedSignIn_1.FederatedButtons;
var TOTPSetup_1 = require("./TOTPSetup");
exports.TOTPSetup = TOTPSetup_1.default;
var Loading_1 = require("./Loading");
exports.Loading = Loading_1.default;
__export(require("./Provider"));
var Greetings_2 = require("./Greetings");
function withAuthenticator(Comp, includeGreetings, authenticatorComponents, federated, theme, signUpConfig) {
if (includeGreetings === void 0) { includeGreetings = false; }
if (authenticatorComponents === void 0) { authenticatorComponents = []; }
if (federated === void 0) { federated = null; }
if (theme === void 0) { theme = null; }
if (signUpConfig === void 0) { signUpConfig = {}; }
return /** @class */ (function (_super) {
__extends(class_1, _super);
function class_1(props) {
var _this = _super.call(this, props) || this;
_this.handleAuthStateChange = _this.handleAuthStateChange.bind(_this);
_this.state = {
authState: props.authState || null,
authData: props.authData || null
};
_this.authConfig = {};
if (typeof includeGreetings === 'object' && includeGreetings !== null) {
_this.authConfig = Object.assign(_this.authConfig, includeGreetings);
}
else {
_this.authConfig = {
includeGreetings: includeGreetings,
authenticatorComponents: authenticatorComponents,
federated: federated,
theme: theme,
signUpConfig: signUpConfig
};
}
return _this;
}
class_1.prototype.handleAuthStateChange = function (state, data) {
this.setState({ authState: state, authData: data });
};
class_1.prototype.render = function () {
var _a = this.state, authState = _a.authState, authData = _a.authData;
var signedIn = (authState === 'signedIn');
if (signedIn) {
return (React.createElement(React.Fragment, null,
this.authConfig.includeGreetings ?
React.createElement(Greetings_2.default, { authState: authState, authData: authData, federated: this.authConfig.federated || this.props.federated || {}, onStateChange: this.handleAuthStateChange, theme: theme })
: null,
React.createElement(Comp, __assign({}, this.props, { authState: authState, authData: authData, onStateChange: this.handleAuthStateChange }))));
}
return React.createElement(Authenticator_1.default, __assign({}, this.props, { theme: this.authConfig.theme, federated: this.authConfig.federated || this.props.federated, hideDefault: this.authConfig.authenticatorComponents && this.authConfig.authenticatorComponents.length > 0, signUpConfig: this.authConfig.signUpConfig, onStateChange: this.handleAuthStateChange, children: this.authConfig.authenticatorComponents || [] }));
};
return class_1;
}(react_1.Component));
}
exports.withAuthenticator = withAuthenticator;
var AuthenticatorWrapper = /** @class */ (function (_super) {
__extends(AuthenticatorWrapper, _super);
function AuthenticatorWrapper(props) {
var _this = _super.call(this, props) || this;
_this.state = { auth: 'init' };
_this.handleAuthState = _this.handleAuthState.bind(_this);
return _this;
}
AuthenticatorWrapper.prototype.handleAuthState = function (state, data) {
this.setState({ auth: state, authData: data });
};
AuthenticatorWrapper.prototype.render = function () {
return (React.createElement("div", null,
React.createElement(Authenticator_1.default, __assign({}, this.props, { onStateChange: this.handleAuthState })),
this.props.children(this.state.auth)));
};
return AuthenticatorWrapper;
}(react_1.Component));
exports.AuthenticatorWrapper = AuthenticatorWrapper;
//# sourceMappingURL=index.js.map