amplify-cli: User Does Not Exist Error Even Though User Exists in User Pool
Describe the bug The Auth.signIn method now returns a userNotFoundException even though the user exists in the cognito user pool.
I had an existing and fully functioning auth flow working through cognito for my react-native app. However, I, realized that I needed to create and use a new cognito user pool for my app, and delete the old user pool. I achieved this via the amplify-cli. All seemed well when I did a sign up test in the app. The user could create an account, receive a verification code in their email, and the cognito user pool responded appropriately. However, when that same user that was just created attempts to sign in, the Auth.signIn method throws a userNotFoundException error.
To Reproduce Assuming the app already as Auth added In the terminal run:
amplify remove authConfirm removalamplify pushConfirm pushamplify add authSelect default configuration with social providers and conduct a standard setup- Rebuild the App
- Create a new user via the Auth.signUp method (in app, this is just the standard auth flow)
- Attempt to sign in with the just-created user.
Expected behavior The Auth.signIn method should return a successful sign in.
Code Snippet
Error:
error signing in... {code: "UserNotFoundException", name: "UserNotFoundException", message: "User does not exist."}
Context of Auth.signIn method:
import React, { Component, useState, useContext } from 'react'
import {AuthContext} from '../../navigation/Screens';
import {ToggleContext} from './Auth';
import { View, TouchableWithoutFeedback, StyleSheet } from 'react-native'
import { Text } from 'galio-framework';
import { Auth } from 'aws-amplify'
import argonTheme from '../../constants/argonTheme';
import Input from '../../components/Auth/Input'
import ActionButton from '../../components/Auth/ActionButton'
import SocialButton from '../../components/Auth/SocialButton';
import GoogleButton from '../../components/Auth/GoogleButton';
// Sign in screen
function SignIn() {
// Assigns updateAuth function to a variable
// Assigns toggleAuthType function to a variable
const updateAuth = useContext(AuthContext);
const toggleAuthType = useContext(ToggleContext);
// Username and Password state management via useState hooks
const [username, setUsername] = useState('');
const [password, setPassword] = useState('');
// Sign In function
// Attempts to sign in with given username and password
// * Note that Auth.signIn returns a promise in the form of an object
// Sets current view to the main app if the Auth.signIn promise resolves to a success
// Logs error and alerts if the Auth.Sign promise resolves to a failure
async function signIn() {
try {
await Auth.signIn(username, password)
console.log('successfully signed in')
updateAuth('MainNav')
} catch (code) {
console.log('error signing in...', code)
alert(code.message)
}
}
function showForgotPassword() {
toggleAuthType('showForgotPassword')
}
return (
<View>
<Input
onChangeText={(text) => {setUsername(text)}}
type='username'
placeholder='Username'
/>
<Input
onChangeText={(text) => {setPassword(text)}}
type='password'
placeholder='Password'
secureTextEntry
/>
<ActionButton
title='Sign In'
onPress={signIn}
BGColor={argonTheme.COLORS.ACTIVE}
/>
<View style={styles.buttonContainer}>
<TouchableWithoutFeedback onPress={showForgotPassword}>
<Text style={{fontSize: 16, fontFamily: 'OpenSans-regular'}}>Forget your password?</Text>
</TouchableWithoutFeedback>
</View>
<View style={styles.buttonContainer}>
<Text style={{fontSize: 16, fontFamily: 'OpenSans-regular'}}>Or</Text>
</View>
<View style={styles.socialCont}>
<GoogleButton
title="Sign in with Google"
onPress={() => Auth.federatedSignIn({ provider: "Google" })}
/>
<SocialButton
title="Sign in with Facebook"
onPress={() => Auth.federatedSignIn({ provider: "Facebook" })}
BGColor={argonTheme.COLORS.FACEBOOK}
iconName='facebook'
iconColor='white'
textColor={argonTheme.COLORS.WHITE}
/>
<SocialButton
title="Sign in with Apple"
BGColor={argonTheme.COLORS.BLACK}
iconName='apple'
iconColor='white'
textColor={argonTheme.COLORS.WHITE}
/>
</View>
</View>
)
}
const styles = StyleSheet.create({
buttonContainer: {
paddingTop: '2%',
justifyContent: 'center',
flexDirection: 'row',
},
socialCont: {
marginTop: '5%'
},
})
export default SignIn
aws-exports.js
const awsmobile = {
"aws_project_region": "us-east-2",
"aws_cognito_identity_pool_id": "us-east-2:d15b3200-6cc2-4e28-9ef0-334cdfa3c389",
"aws_cognito_region": "us-east-2",
"aws_user_pools_id": "us-east-2_uZqiPEd19",
"aws_user_pools_web_client_id": "1npgiokobk2d10ofoerablv93t",
"oauth": {
"domain": "nerdhub-auth-dev.auth.us-east-2.amazoncognito.com",
"scope": [
"phone",
"email",
"openid",
"profile",
"aws.cognito.signin.user.admin"
],
"redirectSignIn": "http://localhost:3000/",
"redirectSignOut": "http://localhost:3000/",
"responseType": "code"
},
"federationTarget": "COGNITO_USER_POOLS"
};
parameters.json
{
"identityPoolName": "nerdhub39718c9f_identitypool_39718c9f",
"allowUnauthenticatedIdentities": false,
"resourceNameTruncated": "nerdhu39718c9f",
"userPoolName": "nerdhub39718c9f_userpool_39718c9f",
"autoVerifiedAttributes": [
"email"
],
"mfaConfiguration": "OFF",
"mfaTypes": [
"SMS Text Message"
],
"smsAuthenticationMessage": "Your authentication code is {####}",
"smsVerificationMessage": "Your verification code is {####}",
"emailVerificationSubject": "Your verification code",
"emailVerificationMessage": "Your verification code is {####}",
"defaultPasswordPolicy": false,
"passwordPolicyMinLength": 8,
"passwordPolicyCharacters": [],
"requiredAttributes": [
"email"
],
"userpoolClientGenerateSecret": true,
"userpoolClientRefreshTokenValidity": 30,
"userpoolClientWriteAttributes": [
"email"
],
"userpoolClientReadAttributes": [
"email"
],
"userpoolClientLambdaRole": "nerdhu39718c9f_userpoolclient_lambda_role",
"userpoolClientSetAttributes": false,
"sharedId": "39718c9f",
"resourceName": "nerdhub39718c9f",
"authSelections": "identityPoolAndUserPool",
"authRoleArn": {
"Fn::GetAtt": [
"AuthRole",
"Arn"
]
},
"unauthRoleArn": {
"Fn::GetAtt": [
"UnauthRole",
"Arn"
]
},
"useDefault": "defaultSocial",
"hostedUI": true,
"hostedUIDomainName": "nerdhub-auth",
"authProvidersUserPool": [
"Facebook",
"Google"
],
"hostedUIProviderMeta": "[{\"ProviderName\":\"Facebook\",\"authorize_scopes\":\"email,public_profile\",\"AttributeMapping\":{\"email\":\"email\",\"username\":\"id\"}},{\"ProviderName\":\"Google\",\"authorize_scopes\":\"openid email profile\",\"AttributeMapping\":{\"email\":\"email\",\"username\":\"sub\"}}]",
"oAuthMetadata": "{\"AllowedOAuthFlows\":[\"code\"],\"AllowedOAuthScopes\":[\"phone\",\"email\",\"openid\",\"profile\",\"aws.cognito.signin.user.admin\"],\"CallbackURLs\":[\"http://localhost:3000/\"],\"LogoutURLs\":[\"http://localhost:3000/\"]}",
"userPoolGroupList": [],
"dependsOn": []
}
Environment
System: OS: macOS 10.15.4 CPU: (8) x64 Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz Memory: 16.45 MB / 16.00 GB Shell: 5.7.1 - /bin/zsh Binaries: Node: 12.14.1 - /usr/local/bin/node Yarn: 1.22.4 - /usr/local/bin/yarn npm: 6.14.5 - /usr/local/bin/npm Browsers: Chrome: 84.0.4147.105 Safari: 13.1 npmPackages: @apollo/react-hooks: ^3.1.5 => 3.1.5 @aws-amplify/pubsub: ^2.1.9 => 2.1.9 @babel/core: ^7.9.0 => 7.9.0 @babel/runtime: ^7.9.2 => 7.9.2 @expo/vector-icons: ^10.0.6 => 10.0.6 @react-native-community/eslint-config: ^1.1.0 => 1.1.0 @react-native-community/google-signin: ^4.0.0 => 4.0.0 @react-native-community/masked-view: ^0.1.9 => 0.1.9 @react-native-community/netinfo: ^5.9.2 => 5.9.5 @react-navigation/bottom-tabs: ^5.2.7 => 5.2.7 @react-navigation/compat: ^5.1.9 => 5.1.9 @react-navigation/drawer: ^5.5.0 => 5.5.0 @react-navigation/material-top-tabs: ^5.2.2 => 5.2.8 @react-navigation/native: ^5.2.6 => 5.4.3 @react-navigation/stack: ^5.2.11 => 5.2.11 @unimodules/core: ^5.1.0 => 5.1.0 @unimodules/react-native-adapter: ^5.2.0 => 5.2.0 amazon-cognito-identity-js: ^4.3.1 => 4.3.3 apollo-boost: ^0.4.9 => 0.4.9 aws-amplify: ^2.3.0 => 2.3.0 aws-amplify-react-native: ^4.2.0 => 4.2.1 babel-jest: ^25.3.0 => 25.3.0 eslint: ^6.8.0 => 6.8.0 expo-asset: ^8.1.4 => 8.1.4 expo-constants: ^9.0.0 => 9.0.0 expo-file-system: ^8.1.0 => 8.1.0 expo-font: ^8.1.1 => 8.1.1 galio-framework: ^0.6.3 => 0.6.3 graphql: ^14.6.0 => 14.7.0 jest: ^25.3.0 => 25.3.0 metro-react-native-babel-preset: ^0.59.0 => 0.59.0 prop-types: ^15.7.2 => 15.7.2 react: ^16.11.0 => 16.13.1 react-native: 0.62.2 => 0.62.2 react-native-elements: ^1.2.7 => 1.2.7 react-native-gesture-handler: ^1.6.1 => 1.6.1 react-native-inappbrowser-reborn: ^3.4.0 => 3.4.0 react-native-material-dropdown: ^0.11.1 => 0.11.1 react-native-material-tabs: ^4.1.2 => 4.1.2 react-native-reanimated: ^1.8.0 => 1.8.0 react-native-safe-area-context: ^0.7.3 => 0.7.3 react-native-screens: ^2.5.0 => 2.5.0 react-native-snap-carousel: ^3.9.1 => 3.9.1 react-native-splash-screen: ^3.2.0 => 3.2.0 react-native-tab-view: ^2.14.0 => 2.14.2 react-native-vector-icons: ^6.6.0 => 6.6.0 react-native-view-more-text: ^2.1.0 => 2.1.0 react-test-renderer: 16.11.0 => 16.11.0 typescript: ^3.8.3 => 3.8.3 npmGlobalPackages: @aws-amplify/cli: 4.21.0 create-react-app: 3.4.0 expo-cli: 3.15.5 firebase-tools: 8.4.0 gatsby-cli: 2.12.17 gulp: 4.0.2 npm: 6.14.5 react-native-cli: 2.0.1Smartphone (please complete the following information):
- Device: iPhone 11
- OS: IOS 13.6
- Browser: safari
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 16 (2 by maintainers)
@rpsutton By ping me I just meant @ me here. I think some how the front end and backend resource ain’t connecting. Let me move this issue to CLI team, they can guide you better.