-
Notifications
You must be signed in to change notification settings - Fork 647
Description
I'm using @aws-sdk/client-cognito-identity and @aws-sdk/credential-provider-cognito-identity to retrieve credentials from a Cognito Identity Pool to access AWS recourses from a React Native app.
The relevant code is:
import { CognitoIdentityClient } from "@aws-sdk/client-cognito-identity";
import { fromCognitoIdentityPool } from "@aws-sdk/credential-provider-cognito-identity";
const cognitoIdentityClient = new CognitoIdentityClient({
region: AWS_REGION,
});
const credentials = fromCognitoIdentityPool({
client: cognitoIdentityClient,
identityPoolId: AWS_IDENTITY_POOL_ID,
logins: {
"appleid.apple.com": userToken,
},
});
Upon resolving the promise returned by fromCognitoIdentityPool, an error is thrown:
[Unhandled promise rejection: Error: not implemented]
- node_modules/react-native/Libraries/Blob/URL.js:169:10 in get__hostname
- node_modules/@aws-sdk/url-parser-node/dist/cjs/index.js:5:26 in parseUrl
- node_modules/@aws-sdk/config-resolver/dist/cjs/EndpointsConfig.js:26:30 in getEndPointFromRegion
This seems to be cause by the line
| const { hostname = "localhost", pathname = "/", port, protocol = "https:", search } = new URL(url); |
The problem is that React Native contains a homemade polyfill for URL (see also facebook/react-native#16434).
As a workaround, https://github.com/charpeni/react-native-url-polyfill can be used. If I include import "react-native-url-polyfill/auto"; in the file where the fromCognitoIdentityPool() function is located, it works. I think it would be good to solve this for React Native in @aws-sdk/url-parser-node, so that people don't need to deploy their own workarounds. I'd be happy to do pull request if pointed in the right direction, but right now I'm not sure how to solve this. I guess you probably don't want to include https://github.com/charpeni/react-native-url-polyfill in @aws-sdk/url-parser-node.