Skip to content

Commit

Permalink
chore(datastore): run eslint --fix
Browse files Browse the repository at this point in the history
  • Loading branch information
HuiSF committed Nov 22, 2023
1 parent 48a2595 commit 7d944fa
Show file tree
Hide file tree
Showing 29 changed files with 1,853 additions and 1,602 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { AuthModeStrategy } from '../types';
import { AuthModeStrategy } from '~/types';

// Default behavior is to use the primary auth mode for an API,
// so we are returning an empty array so that DataStore will default
Expand Down
19 changes: 11 additions & 8 deletions packages/datastore/src/authModeStrategies/multiAuthStrategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
// SPDX-License-Identifier: Apache-2.0
import { fetchAuthSession } from '@aws-amplify/core';
import {
AmplifyContext,
AuthModeStrategy,
ModelAttributeAuthAllow,
ModelAttributeAuthProperty,
ModelAttributeAuthProvider,
ModelAttributeAuthAllow,
AmplifyContext,
} from '../types';
} from '~/types';
import { GraphQLAuthMode } from '@aws-amplify/core/internals/utils';

function getProviderFromRule(
rule: ModelAttributeAuthProperty
rule: ModelAttributeAuthProperty,
): ModelAttributeAuthProvider {
// private with no provider means userPools
if (rule.allow === 'private' && !rule.provider) {
Expand All @@ -21,6 +21,7 @@ function getProviderFromRule(
if (rule.allow === 'public' && !rule.provider) {
return ModelAttributeAuthProvider.API_KEY;
}

return rule.provider!;
}

Expand Down Expand Up @@ -48,10 +49,11 @@ function sortAuthRulesWithPriority(rules: ModelAttributeAuthProperty[]) {
providerSortPriority.indexOf(getProviderFromRule(b))
);
}

return (
allowSortPriority.indexOf(a.allow) - allowSortPriority.indexOf(b.allow)
);
}
},
);
}

Expand Down Expand Up @@ -136,9 +138,9 @@ function getAuthRules({
* @returns A sorted array of auth modes to attempt.
*/
export const multiAuthStrategy: (
amplifyContext: AmplifyContext
amplifyContext: AmplifyContext,
) => AuthModeStrategy =
(amplifyContext: AmplifyContext) =>
() =>
async ({ schema, modelName }) => {
let currentUser;
try {
Expand All @@ -158,11 +160,12 @@ export const multiAuthStrategy: (

if (authAttribute?.properties?.rules) {
const sortedRules = sortAuthRulesWithPriority(
authAttribute.properties.rules
authAttribute.properties.rules,
);

return getAuthRules({ currentUser, rules: sortedRules });
}
}

return [];
};
Loading

0 comments on commit 7d944fa

Please sign in to comment.