amplify-js: AWSS3Provider - get signed url error [TypeError: Cannot read property 'byteLength' of undefined]
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, Storage
Amplify Categories
auth, storage
Environment information
System:
OS: macOS 13.3.1
CPU: (8) arm64 Apple M2
Memory: 2.91 GB / 24.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 18.13.0 - /opt/homebrew/opt/node@18/bin/node
Yarn: 1.22.19 - /opt/homebrew/bin/yarn
npm: 8.19.3 - /opt/homebrew/opt/node@18/bin/npm
Watchman: 2023.01.30.00 - /opt/homebrew/bin/watchman
Browsers:
Chrome: 112.0.5615.49
Safari: 16.4
npmPackages:
@babel/core: ^7.20.0 => 7.20.12
@babel/preset-env: ^7.20.0 => 7.20.2
@babel/runtime: ^7.20.0 => 7.20.13
@hookform/resolvers: ^2.9.11 => 2.9.11
@hookform/resolvers/ajv: 1.0.0
@hookform/resolvers/class-validator: 1.0.0
@hookform/resolvers/computed-types: 1.0.0
@hookform/resolvers/io-ts: 1.0.0
@hookform/resolvers/joi: 1.0.0
@hookform/resolvers/nope: 1.0.0
@hookform/resolvers/superstruct: 1.0.0
@hookform/resolvers/typanion: 1.0.0
@hookform/resolvers/vest: 1.0.0
@hookform/resolvers/yup: 1.0.0
@hookform/resolvers/zod: 1.0.0
@react-native-async-storage/async-storage: ^1.17.11 => 1.18.1
@react-native-community/eslint-config: ^3.2.0 => 3.2.0
@react-native-community/netinfo: ^9.3.7 => 9.3.9
@react-navigation/native: ^6.1.4 => 6.1.4
@react-navigation/native-stack: ^6.9.10 => 6.9.10
@tsconfig/react-native: ^2.0.2 => 2.0.3
@types/jest: ^29.4.0 => 29.4.0
@types/react: ^18.0.28 => 18.0.35 (18.0.28)
@types/react-native: ^0.71.3 => 0.71.5
@types/react-test-renderer: ^18.0.0 => 18.0.0
@types/uuid: ^9.0.1 => 9.0.1
@typescript-eslint/eslint-plugin: ^5.57.1 => 5.57.1 (5.52.0)
@typescript-eslint/parser: ^5.57.1 => 5.57.1 (5.52.0)
HelloWorld: 0.0.1
amazon-cognito-identity-js: ^6.1.2 => 6.2.0
aws-amplify: ^5.0.15 => 5.1.1
aws-sdk: ^2.1082.0 => 2.1357.0
babel-jest: ^29.2.1 => 29.4.3
constate: ^3.3.2 => 3.3.2
eslint: ^8.38.0 => 8.38.0
eslint-plugin-import: ^2.27.5 => 2.27.5
eslint-plugin-jest: ^27.2.1 => 27.2.1 (26.9.0)
eslint-plugin-prettier: ^4.2.1 => 4.2.1
eslint-plugin-react: ^7.32.2 => 7.32.2
eslint-plugin-react-native: ^4.0.0 => 4.0.0
eslint-plugin-unused-imports: ^2.0.0 => 2.0.0
jest: ^29.2.1 => 29.4.3
metro-react-native-babel-preset: 0.73.7 => 0.73.7 (0.73.9, 0.73.5)
native-base: ^3.4.25 => 3.4.25
prettier: ^2.8.7 => 2.8.7
react: 18.2.0 => 18.2.0
react-hook-form: ^7.43.1 => 7.43.1
react-native: 0.71.0 => 0.71.0
react-native-image-picker: ^4.9.0 => 4.10.3
react-native-inappbrowser-reborn: ^3.7.0 => 3.7.0
react-native-safe-area-context: 3.3.2 => 3.3.2
react-native-screens: ^3.20.0 => 3.20.0
react-native-svg: 12.1.1 => 12.1.1
react-query: ^3.39.3 => 3.39.3
react-test-renderer: 18.2.0 => 18.2.0
typescript: 4.8.4 => 4.8.4
uuid: ^9.0.0 => 9.0.0 (3.4.0, 8.3.2, 8.0.0)
zod: ^3.20.6 => 3.20.6
npmGlobalPackages:
@aws-amplify/cli: 10.4.0
expo-cli: 6.3.2
ios-deploy: 1.11.4
yarn: 1.22.19
Describe the bug
Using the Auth class call the Auth.signIn method and successfully sign in. Call the Storage.get() method after successful sign in. Storage.get() API fails and produces the following output. This issue occurs when starting the React Native app normally but does not occur in debug mode. The behavior is the same on both iPhone and Android.
await Auth.signIn({
username,
password,
});
const currentCredentials = await Auth.currentCredentials();
console.log({currentCredentials});
const result = await Storage.get(fileName, {
level: 'private',
});
console.log(result);
LOG Running "flik" with {"rootTag":11}
LOG {"currentCredentials": [Error: Native module not found]}
WARN [WARN] 26:22.503 AWSS3Provider - get signed url error [TypeError: Cannot read property 'byteLength' of undefined]
WARN Possible Unhandled Promise Rejection (id: 0):
TypeError: Cannot read property 'byteLength' of undefined
TypeError: Cannot read property 'byteLength' of undefined
at isEmptyData (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.flik&modulesOnly=false&runModule=true:105523:16)
at anonymous (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.flik&modulesOnly=false&runModule=true:105214:78)
at hmac (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.flik&modulesOnly=false&runModule=true:346790:16)
at ?anon_0_ (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.flik&modulesOnly=false&runModule=true:346761:33)
at next (native)
at asyncGeneratorStep (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.flik&modulesOnly=false&runModule=true:1195:26)
at _next (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.flik&modulesOnly=false&runModule=true:1214:29)
at anonymous (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.flik&modulesOnly=false&runModule=true:1219:14)
at tryCallTwo (/root/react-native/ReactAndroid/hermes-engine/.cxx/Release/4b1t586k/arm64-v8a/lib/InternalBytecode/InternalBytecode.js:61:9)
at doResolve (/root/react-native/ReactAndroid/hermes-engine/.cxx/Release/4b1t586k/arm64-v8a/lib/InternalBytecode/InternalBytecode.js:216:25)
at Promise (/root/react-native/ReactAndroid/hermes-engine/.cxx/Release/4b1t586k/arm64-v8a/lib/InternalBytecode/InternalBytecode.js:82:14)
at anonymous (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.flik&modulesOnly=false&runModule=true:1211:25)
at apply (native)
at getSigningKey (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.flik&modulesOnly=false&runModule=true:346777:24)
at getSigningKey (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.flik&modulesOnly=false&runModule=true:347069:86)
at ?anon_0_ (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.flik&modulesOnly=false&runModule=true:346902:155)
at next (native)
at asyncGeneratorStep (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.flik&modulesOnly=false&runModule=true:1195:26)
at _next (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.flik&modulesOnly=false&runModule=true:1214:29)
at tryCallOne (/root/react-native/ReactAndroid/hermes-engine/.cxx/Release/4b1t586k/arm64-v8a/lib/InternalBytecode/InternalBytecode.js:53:16)
at anonymous (/root/react-native/ReactAndroid/hermes-engine/.cxx/Release/4b1t586k/arm64-v8a/lib/InternalBytecode/InternalBytecode.js:139:27)
at apply (native)
at anonymous (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.flik&modulesOnly=false&runModule=true:26322:26)
at _callTimer (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.flik&modulesOnly=false&runModule=true:26241:17)
at _callReactNativeMicrotasksPass (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.flik&modulesOnly=false&runModule=true:26271:17)
at callReactNativeMicrotasks (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.flik&modulesOnly=false&runModule=true:26434:44)
at __callReactNativeMicrotasks (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.flik&modulesOnly=false&runModule=true:2591:46)
at anonymous (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.flik&modulesOnly=false&runModule=true:2403:45)
at __guard (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.flik&modulesOnly=false&runModule=true:2575:15)
at flushedQueue (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.flik&modulesOnly=false&runModule=true:2402:21)
at callFunctionReturnFlushedQueue (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.flik&modulesOnly=false&runModule=true:2387:33)
Expected behavior
Should return a pre-signed URL.
Reproduction steps
- Start a new React-Native project
- Install everything according to the Amplify React-Native tutorial https://docs.amplify.aws/start/getting-started/setup/q/integration/react-native#create-a-new-react-native-app including running npx pod-install
- Run amplify add auth and use the default setup.
- Run amplify add storage
- Run amplify push
- Use the Auth module to add sign up/sign up verify and sign in a user.
- Make a call to Auth.currentCredentials or another class requiring auth such as Storage.get()
Code Snippet
Amplify.configure({
Auth: {
identityPoolId: awsExports.aws_cognito_identity_pool_id,
region: awsExports.aws_cognito_region,
userPoolId: awsExports.aws_user_pools_id,
userPoolWebClientId: awsExports.aws_user_pools_web_client_id,
},
oauth: {
...awsExports.oauth,
urlOpener,
},
Storage: {
AWSS3: {
bucket: awsExports.aws_user_files_s3_bucket,
region: awsExports.aws_user_files_s3_bucket_region,
},
},
API: {
aws_appsync_graphqlEndpoint: awsExports.aws_appsync_graphqlEndpoint,
aws_appsync_region: awsExports.aws_appsync_region,
aws_appsync_authenticationType: awsExports.aws_appsync_authenticationType,
}
});
await Auth.signIn({
username,
password,
});
const currentCredentials = await Auth.currentCredentials();
console.log({currentCredentials});
const result = await Storage.get(fileName, {
level: 'private',
});
console.log(result);
Log output
LOG Running "flik" with {"rootTag":11}
LOG {"currentCredentials": [Error: Native module not found]}
WARN [WARN] 26:22.503 AWSS3Provider - get signed url error [TypeError: Cannot read property 'byteLength' of undefined]
WARN Possible Unhandled Promise Rejection (id: 0):
TypeError: Cannot read property 'byteLength' of undefined
TypeError: Cannot read property 'byteLength' of undefined
at isEmptyData (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.flik&modulesOnly=false&runModule=true:105523:16)
at anonymous (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.flik&modulesOnly=false&runModule=true:105214:78)
at hmac (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.flik&modulesOnly=false&runModule=true:346790:16)
at ?anon_0_ (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.flik&modulesOnly=false&runModule=true:346761:33)
at next (native)
at asyncGeneratorStep (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.flik&modulesOnly=false&runModule=true:1195:26)
at _next (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.flik&modulesOnly=false&runModule=true:1214:29)
at anonymous (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.flik&modulesOnly=false&runModule=true:1219:14)
at tryCallTwo (/root/react-native/ReactAndroid/hermes-engine/.cxx/Release/4b1t586k/arm64-v8a/lib/InternalBytecode/InternalBytecode.js:61:9)
at doResolve (/root/react-native/ReactAndroid/hermes-engine/.cxx/Release/4b1t586k/arm64-v8a/lib/InternalBytecode/InternalBytecode.js:216:25)
at Promise (/root/react-native/ReactAndroid/hermes-engine/.cxx/Release/4b1t586k/arm64-v8a/lib/InternalBytecode/InternalBytecode.js:82:14)
at anonymous (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.flik&modulesOnly=false&runModule=true:1211:25)
at apply (native)
at getSigningKey (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.flik&modulesOnly=false&runModule=true:346777:24)
at getSigningKey (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.flik&modulesOnly=false&runModule=true:347069:86)
at ?anon_0_ (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.flik&modulesOnly=false&runModule=true:346902:155)
at next (native)
at asyncGeneratorStep (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.flik&modulesOnly=false&runModule=true:1195:26)
at _next (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.flik&modulesOnly=false&runModule=true:1214:29)
at tryCallOne (/root/react-native/ReactAndroid/hermes-engine/.cxx/Release/4b1t586k/arm64-v8a/lib/InternalBytecode/InternalBytecode.js:53:16)
at anonymous (/root/react-native/ReactAndroid/hermes-engine/.cxx/Release/4b1t586k/arm64-v8a/lib/InternalBytecode/InternalBytecode.js:139:27)
at apply (native)
at anonymous (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.flik&modulesOnly=false&runModule=true:26322:26)
at _callTimer (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.flik&modulesOnly=false&runModule=true:26241:17)
at _callReactNativeMicrotasksPass (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.flik&modulesOnly=false&runModule=true:26271:17)
at callReactNativeMicrotasks (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.flik&modulesOnly=false&runModule=true:26434:44)
at __callReactNativeMicrotasks (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.flik&modulesOnly=false&runModule=true:2591:46)
at anonymous (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.flik&modulesOnly=false&runModule=true:2403:45)
at __guard (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.flik&modulesOnly=false&runModule=true:2575:15)
at flushedQueue (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.flik&modulesOnly=false&runModule=true:2402:21)
at callFunctionReturnFlushedQueue (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.flik&modulesOnly=false&runModule=true:2387:33)
aws-exports.js
const awsmobile = {
"aws_project_region": "ap-northeast-1",
"aws_cloud_logic_custom": [
{
"name": "AdminQueries",
"endpoint": "xxx",
"region": "ap-northeast-1"
}
],
"aws_appsync_graphqlEndpoint": "xxx",
"aws_appsync_region": "ap-northeast-1",
"aws_appsync_authenticationType": "AMAZON_COGNITO_USER_POOLS",
"aws_cognito_identity_pool_id": "xxx",
"aws_cognito_region": "ap-northeast-1",
"aws_user_pools_id": "xxx",
"aws_user_pools_web_client_id": "xxx",
"oauth": {
"domain": "xxx",
"scope": [
"email",
"openid",
"profile"
],
"redirectSignIn": "flik://",
"redirectSignOut": "flik://",
"responseType": "code"
},
"federationTarget": "COGNITO_USER_POOLS",
"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": 8,
"passwordPolicyCharacters": []
},
"aws_cognito_verification_mechanisms": [
"EMAIL"
],
"aws_user_files_s3_bucket": "xxx",
"aws_user_files_s3_bucket_region": "ap-northeast-1"
};
export default awsmobile;
Manual configuration
{
Auth: {
identityPoolId: awsExports.aws_cognito_identity_pool_id,
region: awsExports.aws_cognito_region,
userPoolId: awsExports.aws_user_pools_id,
userPoolWebClientId: awsExports.aws_user_pools_web_client_id,
},
oauth: {
...awsExports.oauth,
urlOpener,
},
Storage: {
AWSS3: {
bucket: awsExports.aws_user_files_s3_bucket,
region: awsExports.aws_user_files_s3_bucket_region,
},
},
API: {
aws_appsync_graphqlEndpoint: awsExports.aws_appsync_graphqlEndpoint,
aws_appsync_region: awsExports.aws_appsync_region,
aws_appsync_authenticationType: awsExports.aws_appsync_authenticationType,
},
}
Additional configuration
No response
Mobile Device
iPhone 13 Simulator
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
"dependencies": {
"@hookform/resolvers": "^2.9.11",
"@react-native-async-storage/async-storage": "^1.17.11",
"@react-native-community/netinfo": "^9.3.7",
"@react-navigation/native": "^6.1.4",
"@react-navigation/native-stack": "^6.9.10",
"@types/uuid": "^9.0.1",
"amazon-cognito-identity-js": "^6.1.2",
"aws-amplify": "^5.0.15",
"constate": "^3.3.2",
"native-base": "^3.4.25",
"react": "18.2.0",
"react-hook-form": "^7.43.1",
"react-native": "0.71.3",
"react-native-inappbrowser-reborn": "^3.7.0",
"react-native-safe-area-context": "3.3.2",
"react-native-screens": "^3.20.0",
"react-native-svg": "12.1.1",
"react-query": "^3.39.3",
"uuid": "^9.0.0",
"zod": "^3.20.6"
},
"devDependencies": {
"@babel/core": "^7.20.0",
"@babel/preset-env": "^7.20.0",
"@babel/runtime": "^7.20.0",
"@react-native-community/eslint-config": "^3.2.0",
"@tsconfig/react-native": "^2.0.2",
"@types/jest": "^29.4.0",
"@types/react": "^18.0.28",
"@types/react-native": "^0.71.3",
"@types/react-test-renderer": "^18.0.0",
"@typescript-eslint/eslint-plugin": "^5.57.1",
"@typescript-eslint/parser": "^5.57.1",
"babel-jest": "^29.2.1",
"eslint": "^8.38.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-jest": "^27.2.1",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-react": "^7.32.2",
"eslint-plugin-react-native": "^4.0.0",
"eslint-plugin-unused-imports": "^2.0.0",
"jest": "^29.2.1",
"metro-react-native-babel-preset": "0.73.7",
"prettier": "^2.8.7",
"react-test-renderer": "18.2.0",
"typescript": "4.8.4"
},
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 18 (10 by maintainers)
Hi @akihisa-sumi after a bit more investigation, I was able to get an error message
Native Module not foundwhen callingAuth.currentCredentials(). To resolve this issue, I update my dependencies to the following listed below - then rannpx pod-installand I am now able to get the Storage and Credentials successfully. Additionally, i was also getting npm warnings and rannpm audit fix --forceto resolve them as well.Could you try doing the same and see if it resolve the issue?
Hi, @nadetastic -san
Yes, the setup for Amplify’s Auth and Storage is complete. Our project supports both Mobile (React Native) and Web (React) and we use the same Amplify app for the backend. On the Web (React) side, Amplify’s Auth, Storage, and Api functionalities are working properly. Recently, we tried to implement the same functionalities on Mobile (React Native) using the same Amplify app for development. It appears that Auth.Signup, Auth.Signin, and Api functionalities are working properly on Mobile, but Storage and Auth.currentCredentials are not functioning. At first, we suspected that we were using the wrong setting for Amplify’s multi-frontend configuration, but Auth.SignIn and Auth.SignUp are working. Storage is also working in debug mode. Therefore, we think that there may be an issue with obtaining authentication information due to the version of Amplify, React Native, and other factors.
@nadetastic Thank you very much. By updating the dependencies you provided, I was able to resolve the error. The issue has been resolved!!
@akihisa-sumi thanks for the response. I was able to get your app running and I have been able to consistently reproduce the errors with it running in debug mode on the emulator.
A bit of info on what I experience:
Auth.currentUserCredentials()orAuth.currentCredentials()returns an empty response and doesn’t seem to throw an errorStorage.get()at public level throws thebyteLengtherror.Auth.currentAuthenticatedUser()andAuth.currentSession()returns the logged in user info, so it appears the issue here is somewhere with the Credentials.Im still working to determine the root cause of this, but it looks like its specific to credentials. As mentioned earlier this is more of an Auth issue since the byteLength error is usually specific to authentication problems.
Will follow up soon as I continue to investigate.
@nadetastic
It seems that there may be some misunderstanding based on the previous discussion, so let me explain from the beginning again.
We developed an app called Flik with React JS and Amplify, and released v1.0.0. From this year, we are planning to release this Flik app on iOS and Android as well. Therefore, we are utilizing the same Amplify App and developing the frontend with React Native.
The problem we are discussing arose in this React Native. It has not occurred with React JS. Despite using the same Amplify App, we are unsure why this is happening. Furthermore, we do not understand why this problem does not occur when we launch React Native in debug mode.
The API.graphql you need can be found in the React JS repository because it’s the same one we’re using in both our React JS and React Native apps, as they both utilize the same Amplify App.
I hope this clarifies things.
Thanks for confirming @akihisa-sumi - I’ve been working to reproduce this but haven’t been able to so far. I ran my test app on iOS simulator with both
"react-native run-ios"and"react-native run-ios --mode Release"however I get the expected outcome from the Auth and Storage APIs.If there’s any additional context you can share that can help in reproducing this issue, please let me know as I continue to investigate.
These are my dependencies: