1 | import { Amplify, CookieStorage, defaultStorage } from '@aws-amplify/core';
|
2 | import { parseAWSExports } from '@aws-amplify/core/internals/utils';
|
3 | import { cognitoUserPoolsTokenProvider, cognitoCredentialsProvider } from '@aws-amplify/auth/cognito';
|
4 |
|
5 |
|
6 |
|
7 | const DefaultAmplify = {
|
8 | configure(resourceConfig, libraryOptions) {
|
9 | let resolvedResourceConfig;
|
10 | if (Object.keys(resourceConfig).some(key => key.startsWith('aws_'))) {
|
11 | resolvedResourceConfig = parseAWSExports(resourceConfig);
|
12 | }
|
13 | else {
|
14 | resolvedResourceConfig = resourceConfig;
|
15 | }
|
16 |
|
17 |
|
18 | if (!resolvedResourceConfig.Auth) {
|
19 | return Amplify.configure(resolvedResourceConfig, libraryOptions);
|
20 | }
|
21 |
|
22 |
|
23 | if (libraryOptions?.Auth) {
|
24 | return Amplify.configure(resolvedResourceConfig, libraryOptions);
|
25 | }
|
26 |
|
27 | if (!Amplify.libraryOptions.Auth) {
|
28 | cognitoUserPoolsTokenProvider.setAuthConfig(resolvedResourceConfig.Auth);
|
29 | cognitoUserPoolsTokenProvider.setKeyValueStorage(
|
30 |
|
31 | libraryOptions?.ssr
|
32 | ? new CookieStorage({ sameSite: 'lax' })
|
33 | : defaultStorage);
|
34 | return Amplify.configure(resolvedResourceConfig, {
|
35 | ...libraryOptions,
|
36 | Auth: {
|
37 | tokenProvider: cognitoUserPoolsTokenProvider,
|
38 | credentialsProvider: cognitoCredentialsProvider,
|
39 | },
|
40 | });
|
41 | }
|
42 |
|
43 |
|
44 | if (libraryOptions) {
|
45 |
|
46 | if (libraryOptions.ssr !== undefined) {
|
47 | cognitoUserPoolsTokenProvider.setKeyValueStorage(
|
48 |
|
49 | libraryOptions.ssr
|
50 | ? new CookieStorage({ sameSite: 'lax' })
|
51 | : defaultStorage);
|
52 | }
|
53 | return Amplify.configure(resolvedResourceConfig, {
|
54 | Auth: Amplify.libraryOptions.Auth,
|
55 | ...libraryOptions,
|
56 | });
|
57 | }
|
58 |
|
59 |
|
60 | Amplify.configure(resolvedResourceConfig);
|
61 | },
|
62 | getConfig() {
|
63 | return Amplify.getConfig();
|
64 | },
|
65 | };
|
66 |
|
67 | export { DefaultAmplify };
|
68 |
|