通常情况下,AWSCognitoAuthPlugin 的解码配置问题是由于在使用 Amplify 配置时,未将 AWS 配置密钥正确添加到项目中所致。解决此问题的方法是确保在 Amplify 配置中正确添加 AWS 密钥。下面是一个示例代码片段,说明了正确配置 AWS 密钥的方法:
import Amplify, { Auth } from 'aws-amplify';
Amplify.configure({
Auth: {
identityPoolId: 'YOUR_IDENTITY_POOL_ID',
region: 'YOUR_REGION',
userPoolId: 'YOUR_USER_POOL_ID',
userPoolWebClientId: 'YOUR_USER_POOL_CLIENT_ID',
mandatorySignIn: true,
authenticationFlowType: 'USER_PASSWORD_AUTH',
oauth: {
domain: 'YOUR_AUTH_DOMAIN',
scope: ['phone', 'email', 'profile', 'openid', 'aws.cognito.signin.user.admin'],
redirectSignIn: 'YOUR_REDIRECT_SIGNIN_URI',
redirectSignOut: 'YOUR_REDIRECT_SIGNOUT_URI',
responseType: 'code',
},
},
aws_appsync_graphqlEndpoint: 'YOUR_APPSYNC_GRAPHQL_ENDPOINT',
aws_appsync_region: 'YOUR_APPSYNC_REGION',
aws_appsync_authenticationType: 'AMAZON_COGNITO_USER_POOLS',
aws_appsync_apiKey: 'YOUR_APPSYNC_API_KEY',
});
Auth.configure({
identityPoolId: 'YOUR_IDENTITY_POOL_ID',
region: 'YOUR_REGION',
userPoolId: 'YOUR_USER_POOL_ID',
userPoolWebClientId: 'YOUR_USER_POOL_CLIENT_ID',
mandatorySignIn: true,
});
确保你的 AWS 密钥已正确添加到代码中,并使用自己的值替换每个占位符。