aws-amplify
Version:
AWS Amplify is a JavaScript library for Frontend and mobile developers building cloud-enabled applications.
70 lines (68 loc) • 3.39 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.DefaultAmplify = void 0;
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
const core_1 = require("@aws-amplify/core");
const utils_1 = require("@aws-amplify/core/internals/utils");
const cognito_1 = require("./auth/cognito");
exports.DefaultAmplify = {
configure(resourceConfig, libraryOptions) {
let resolvedResourceConfig;
if (Object.keys(resourceConfig).some(key => key.startsWith('aws_'))) {
resolvedResourceConfig = (0, utils_1.parseAWSExports)(resourceConfig);
}
else {
resolvedResourceConfig = resourceConfig;
}
// If no Auth config is provided, no special handling will be required, configure as is.
// Otherwise, we can assume an Auth config is provided from here on.
if (!resolvedResourceConfig.Auth) {
return core_1.Amplify.configure(resolvedResourceConfig, libraryOptions);
}
// If Auth options are provided, always just configure as is.
// Otherwise, we can assume no Auth libraryOptions were provided from here on.
if (libraryOptions?.Auth) {
return core_1.Amplify.configure(resolvedResourceConfig, libraryOptions);
}
// If no Auth libraryOptions were previously configured, then always add default providers.
if (!core_1.Amplify.libraryOptions.Auth) {
cognito_1.cognitoUserPoolsTokenProvider.setAuthConfig(resolvedResourceConfig.Auth);
cognito_1.cognitoUserPoolsTokenProvider.setKeyValueStorage(
// TODO: allow configure with a public interface
libraryOptions?.ssr
? new core_1.CookieStorage({ sameSite: 'lax' })
: core_1.defaultStorage);
return core_1.Amplify.configure(resolvedResourceConfig, {
...libraryOptions,
Auth: {
tokenProvider: cognito_1.cognitoUserPoolsTokenProvider,
credentialsProvider: cognito_1.cognitoCredentialsProvider,
},
});
}
// At this point, Auth libraryOptions would have been previously configured and no overriding
// Auth options were given, so we should preserve the currently configured Auth libraryOptions.
if (libraryOptions) {
// If ssr is provided through libraryOptions, we should respect the intentional reconfiguration.
if (libraryOptions.ssr !== undefined) {
cognito_1.cognitoUserPoolsTokenProvider.setKeyValueStorage(
// TODO: allow configure with a public interface
libraryOptions.ssr
? new core_1.CookieStorage({ sameSite: 'lax' })
: core_1.defaultStorage);
}
return core_1.Amplify.configure(resolvedResourceConfig, {
Auth: core_1.Amplify.libraryOptions.Auth,
...libraryOptions,
});
}
// Finally, if there were no libraryOptions given at all, we should simply not touch the currently
// configured libraryOptions.
core_1.Amplify.configure(resolvedResourceConfig);
},
getConfig() {
return core_1.Amplify.getConfig();
},
};
//# sourceMappingURL=initSingleton.js.map
;