amplify-js: Mobile SignIn function failure from @aws-amplify/auth but WebVersion works (using Expo)
Before opening, please confirm:
- I have searched for duplicate or closed issues and discussions.
- I have read the guide for submitting bug reports.
- I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
JavaScript Framework
React Native
Amplify APIs
Authentication
Amplify Version
v6
Amplify Categories
auth
Backend
Amplify CLI
Environment information
# Put output below this line
System:
OS: macOS 14.4
CPU: (14) arm64 Apple M3 Max
Memory: 2.73 GB / 36.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 22.9.0 - /opt/homebrew/bin/node
npm: 10.9.0 - /opt/homebrew/bin/npm
Browsers:
Chrome: 130.0.6723.70
Safari: 17.4
npmPackages:
@aws-amplify/api: ^6.0.54 => 6.0.55
@aws-amplify/api/internals: undefined ()
@aws-amplify/api/server: undefined ()
@aws-amplify/auth: ^6.5.0 => 6.5.0 (6.5.3)
@aws-amplify/auth/cognito: undefined ()
@aws-amplify/auth/cognito/server: undefined ()
@aws-amplify/auth/enable-oauth-listener: undefined ()
@aws-amplify/auth/server: undefined ()
@aws-amplify/core: ^6.4.5 => 6.4.6
@aws-amplify/core/internals/adapter-core: undefined ()
@aws-amplify/core/internals/aws-client-utils: undefined ()
@aws-amplify/core/internals/aws-client-utils/composers: undefined ()
@aws-amplify/core/internals/aws-clients/cognitoIdentity: undefined ()
@aws-amplify/core/internals/aws-clients/pinpoint: undefined ()
@aws-amplify/core/internals/providers/pinpoint: undefined ()
@aws-amplify/core/internals/utils: undefined ()
@aws-amplify/core/server: undefined ()
@aws-amplify/react-native: ^1.1.6 => 1.1.6
@aws-amplify/ui-react-native: ^2.2.16 => 2.2.16
@babel/core: ^7.20.0 => 7.25.8
@react-native-async-storage/async-storage: ^2.0.0 => 2.0.0
@react-native-community/masked-view: ^0.1.11 => 0.1.11
@react-native-community/netinfo: ^11.4.1 => 11.4.1
@react-native-picker/picker: ^2.8.1 => 2.8.1
@react-navigation/native: ^6.1.18 => 6.1.18
HelloWorld: 0.0.1
aws-amplify: ^6.6.6 => 6.6.6
aws-amplify/adapter-core: undefined ()
aws-amplify/analytics: undefined ()
aws-amplify/analytics/kinesis: undefined ()
aws-amplify/analytics/kinesis-firehose: undefined ()
aws-amplify/analytics/personalize: undefined ()
aws-amplify/analytics/pinpoint: undefined ()
aws-amplify/api: undefined ()
aws-amplify/api/server: undefined ()
aws-amplify/auth: undefined ()
aws-amplify/auth/cognito: undefined ()
aws-amplify/auth/cognito/server: undefined ()
aws-amplify/auth/enable-oauth-listener: undefined ()
aws-amplify/auth/server: undefined ()
aws-amplify/data: undefined ()
aws-amplify/data/server: undefined ()
aws-amplify/datastore: undefined ()
aws-amplify/in-app-messaging: undefined ()
aws-amplify/in-app-messaging/pinpoint: undefined ()
aws-amplify/push-notifications: undefined ()
aws-amplify/push-notifications/pinpoint: undefined ()
aws-amplify/storage: undefined ()
aws-amplify/storage/s3: undefined ()
aws-amplify/storage/s3/server: undefined ()
aws-amplify/storage/server: undefined ()
aws-amplify/utils: undefined ()
axios: ^1.7.7 => 1.7.7
expo: ~51.0.38 => 51.0.38
expo-constants: ~16.0.1 => 16.0.2
expo-font: ^12.0.10 => 12.0.10
expo-linking: ~6.3.1 => 6.3.1
expo-router: ~3.5.9 => 3.5.23
expo-splash-screen: ~0.27.4 => 0.27.6 (0.27.5)
expo-status-bar: ~1.12.1 => 1.12.1
nativewind: ^2.0.11 => 2.0.11
react: 18.2.0 => 18.2.0
react-dom: 18.2.0 => 18.2.0
react-native: 0.74.5 => 0.74.5 (0.73.10)
react-native-appwrite: ^0.5.0 => 0.5.0
react-native-dotenv: ^3.4.11 => 3.4.11
react-native-dropdown-select-list: ^2.0.5 => 2.0.5
react-native-gesture-handler: ~2.16.1 => 2.16.2
react-native-get-random-values: ^1.11.0 => 1.11.0
react-native-picker-select: ^9.3.1 => 9.3.1
react-native-reanimated: ~3.10.1 => 3.10.1
react-native-safe-area-context: ^4.11.1 => 4.11.1
react-native-screens: 3.31.1 => 3.31.1
react-native-url-polyfill: ^2.0.0 => 2.0.0
react-native-web: ~0.19.6 => 0.19.12
tailwindcss: ^3.3.2 => 3.3.2
npmGlobalPackages:
@aws-amplify/cli: 12.13.0
npm: 10.9.0
Describe the bug
I am integrating all the “aws-amplify/auth” functions into my custom UI. I’ve already successfully integrated the {signUp, signOut, confirmSignUp, resendSignUp } functions and they work great. No errors and my account I create (using email as username) goes right into my Cognito Pool smoothly which was set up through AWS Amplify Studio. Logout button works great when I get to my “Home” screen after Signing Up and Confirming my 6-digit Code. This is the return value I get by overlaying my ‘confirmSignUp’ and ‘signUp’ responses and storing them in a global app variable called “user”: ‘newSetUser’: {“isSignUpComplete”: true, “nextStep”: {“codeDeliveryDetails”: {“attributeName”: “email”, “deliveryMedium”: “EMAIL”, “destination”: “a***@g***”}, “signUpStep”: “DONE”}, “userId”: “c14b75c0-70b1-7048-9c0b-07ba8df12052”}
The problem is after I log out… I try to Sign In using my custom Sign In UI screen that is connected to the {signIn} function from “aws-amplify/auth”. When clicking “Sign In”, I get this bizarre error that I cannot figure out what is going on. I can clearly see my username (email) and password get passed into the ‘signIn’ function correctly and they are the same creds I used upon set up (I’ve validated this over and over again). This is the error message: “Error during sign in: [Unknown: An unknown error has occurred.]”
Expected behavior
For me to simply sign in with the correct credentials with no errors. I’ve watched and followed several YouTube videos and thread approaches to this simply “signIn” function within “aws-amplify/auth” but I always come back to get this unknown error message…
Reproduction steps
- I go to my Sign In Screen (after logging out of a verified account)
- Enter in credentials (email + password) I just used for creating my account (but logged out once I entered the app’s protected path)
- Click “Sign In”
- The TextInputs (email and password) are passed correctly via props into my custom “aws_signIn” function which is show below in the Code Snippet
Code Snippet
// Put your code below this line.
`import { Auth, API, Storage, Amplify } from 'aws-amplify';
import config from '../src/aws-exports'; // Ensure this path points to your aws-exports.js file
import { signIn, signUp, autoSignIn, signOut, confirmSignUp, resendSignUp } from 'aws-amplify/auth';
// Enable detailed logging for AWS Amplify
Amplify.configure(config); // Correctly configure Amplify with the config file
// ========================== //
// === User Authentication == //
// ========================== //
// Sign in a user
export const aws_signIn = async ({ email, password }) => {
try {
console.log("'Amplify.js' Email: ", email.trim().toLowerCase());
console.log("'Amplify.js' Password: ", password.trim());
let clean_email = email.trim().toLowerCase();
let clean_password = password.trim();
const signInResult = await signIn({
'username': clean_email,
'password': clean_password
});
console.log('signInResult: ', signInResult);
return signInResult;
} catch (e) {
console.error('Error during sign in:', e); // Log the entire error object
throw new Error(e.message || 'An unknown error occurred during sign in.');
}
};`
**====== The code that is executed once the "Sign Up" button is clicked below ======**
`import { aws_signIn } from '../../lib/amplify'
import { useGlobalContext } from "../../context/GlobalProvider";
const SignIn = () => {
const { setUser, setIsLoggedIn } = useGlobalContext();
const [isSubmitting, setIsSubmitting] = useState(false);
const [error, setError] = useState('');
let onlyShowOneAlert = false;
const [form, setForm] = useState({
email: '',
password: ''
});
const onSignInPressed = async () => {
setError('');
if(!form.email || !form.password) {
Alert.alert('Sign In Error', 'Email & Password required to sign in.');
onlyShowOneAlert = true;
}
setIsSubmitting(true);
try {
const signInResult = await aws_signIn(form);
setUser(signInResult);
setIsLoggedIn(true);
router.replace('/home'); // Redirect the user to the home page
} catch (err) {
setError(err.message)
console.log('Catch Error: ', error);
} finally{
setIsSubmitting(false);
console.log('Finally Error: ', error);
}
};`
**### TERMINAL LOG UPON PASSING IN TextInput Props:**
LOG: 'Amplify.js' Email: a************@gmail.com
LOG: 'Amplify.js' Password: TestPassword123
ERROR Error during sign in: [Unknown: An unknown error has occurred.]
LOG Catch Error: An unknown error has occurred.
LOG Finally Error: An unknown error has occurred.
Log output
// Put your logs below this line
aws-exports.js
/* eslint-disable */ // WARNING: DO NOT EDIT. This file is automatically generated by AWS Amplify. It will be overwritten.
const awsmobile = { “aws_project_region”: “us-east-2”, “aws_cognito_identity_pool_id”: “us-east-2:#########-####-####-####-###########”, “aws_cognito_region”: “us-east-2”, “aws_user_pools_id”: “us-east-2_##########”, “aws_user_pools_web_client_id”: “#########################”, “oauth”: {}, “aws_cognito_username_attributes”: [ “EMAIL” ], “aws_cognito_social_providers”: [], “aws_cognito_signup_attributes”: [ “EMAIL” ], “aws_cognito_mfa_configuration”: “OFF”, “aws_cognito_mfa_types”: [ “SMS” ], “aws_cognito_password_protection_settings”: { “passwordPolicyMinLength”: 6, “passwordPolicyCharacters”: [] }, “aws_cognito_verification_mechanisms”: [ “EMAIL” ] };
export default awsmobile;
Manual configuration
No response
Additional configuration
No response
Mobile Device
iPhone 15 Pro
Mobile Operating System
iOS18.0.1
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
Using Expo
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 24 (14 by maintainers)
@ashika112 - thank you for sharing your findings and glad to hear you got it working. I am performing a deeper analysis on my code base. I’ve been able to implement both Appwrite and Supabase Auth (used in different app files but same code base) perfectly with the same unplug/plugin approach in my code base. I’ll need to dig deeper why my codebase isn’t working with AWS Auth. Thanks again
Sounds good and will do. Thanks @cwomack !
@cwomack - I wonder if it has something to do with CORS. I am not an expert at CORS but watched a couple videos and may be thinking it is correlated with my AWS Auth workflow failing to auto sign in and sign in as well.
Edited: Never mind, CORS only affects web browsing and not Mobile Apps