Skip to content

Commit 65d1171

Browse files
authored
Merge pull request #14284 from aws-amplify/otaviom/empty-auth-providers
fix: cli throws an error when `thirdPartyAuth` is enabled, but `authProvider` is not included
2 parents dbd2c53 + 762f2f2 commit 65d1171

2 files changed

Lines changed: 40 additions & 6 deletions

File tree

  • packages/amplify-category-auth/src

packages/amplify-category-auth/src/__tests__/provider-utils/awscloudformation/index.test.ts

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,41 @@ jest.mock('@aws-amplify/amplify-cli-core', () => ({
1919
// mock fns
2020
const pluginInstanceMock = jest.fn();
2121
const loadResourceParametersMock = jest.fn().mockReturnValue({
22-
hostedUIProviderMeta:
23-
'[{"ProviderName":"Facebook","authorize_scopes":"email,public_profile","AttributeMapping":{"email":"email","username":"id"}},{"ProviderName":"LoginWithAmazon","authorize_scopes":"profile profile:user_id","AttributeMapping":{"email":"email","username":"user_id"}},{"ProviderName":"Google","authorize_scopes":"openid email profile","AttributeMapping":{"email":"email","username":"sub"}},{"ProviderName":"SignInWithApple","authorize_scopes":"openid email profile","AttributeMapping":{"email":"email","username":"sub"}}]',
22+
thirdPartyAuth: true, // enable third party auth, but do not include any authProviders. Should not fail.
23+
hostedUIProviderMeta: JSON.stringify([
24+
{
25+
ProviderName: 'Facebook',
26+
authorize_scopes: 'email,public_profile',
27+
AttributeMapping: {
28+
email: 'email',
29+
username: 'id',
30+
},
31+
},
32+
{
33+
ProviderName: 'LoginWithAmazon',
34+
authorize_scopes: 'profile profile:user_id',
35+
AttributeMapping: {
36+
email: 'email',
37+
username: 'user_id',
38+
},
39+
},
40+
{
41+
ProviderName: 'Google',
42+
authorize_scopes: 'openid email profile',
43+
AttributeMapping: {
44+
email: 'email',
45+
username: 'sub',
46+
},
47+
},
48+
{
49+
ProviderName: 'SignInWithApple',
50+
authorize_scopes: 'openid email profile',
51+
AttributeMapping: {
52+
email: 'email',
53+
username: 'sub',
54+
},
55+
},
56+
]),
2457
});
2558
const pluginInstance = {
2659
loadResourceParameters: loadResourceParametersMock,

packages/amplify-category-auth/src/provider-utils/awscloudformation/index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,8 @@ const getRequiredParamsForHeadlessInit = (projectType: any, previousValues: any)
326326
const requiredParams: string[] = [];
327327

328328
if (previousValues.thirdPartyAuth) {
329-
if (previousValues.authProviders.includes('accounts.google.com')) {
329+
const authProviders = previousValues.authProviders ?? [];
330+
if (authProviders.includes('accounts.google.com')) {
330331
requiredParams.push('googleClientId');
331332
if (projectType === 'ios') {
332333
requiredParams.push('googleIos');
@@ -335,14 +336,14 @@ const getRequiredParamsForHeadlessInit = (projectType: any, previousValues: any)
335336
requiredParams.push('googleAndroid');
336337
}
337338
}
338-
if (previousValues.authProviders.includes('graph.facebook.com')) {
339+
if (authProviders.includes('graph.facebook.com')) {
339340
requiredParams.push('facebookAppId');
340341
}
341-
if (previousValues.authProviders.includes('www.amazon.com')) {
342+
if (authProviders.includes('www.amazon.com')) {
342343
requiredParams.push('amazonAppId');
343344
}
344345
// eslint-disable-next-line spellcheck/spell-checker
345-
if (previousValues.authProviders.includes('appleid.apple.com')) {
346+
if (authProviders.includes('appleid.apple.com')) {
346347
requiredParams.push('appleAppId');
347348
}
348349
}

0 commit comments

Comments
 (0)