amazon-archives/aws-sdk-react-native

NativeModules.AWSRNCognitoCredentials returns undefined

Opened this issue · 7 comments

Trying to use Cognito, and following the example code, I end up with:

import React, {Component} from "react";
import View} from "react-native";

import {AWSCognitoCredentials} from 'aws-sdk-react-native-core';
import {AWSS3TransferUtility} from 'aws-sdk-react-native-transfer-utility';


class Sample extends Component {

    constructor(props) {
        super(props)


        ASCognitoCredentials.initWithOptions({"region": "XXX", "identity_pool_id": "YYY"})
    }

    render() {
        return (<View></View>)
    }
}

XCode produces the following error:

[fatal][tid:com.facebook.react.RCTExceptionsManagerQueue] Unhandled JS Exception: Cannot read property 'initWithOptions' of undefined

A little debugging, and it appears that in AWSCogniteCredentials.js the following returned: undefined.

var cognitoClient = NativeModules.AWSRNCognitoCredentials;

I have the same issue. I responded originally thinking I had fixed it, but I didn't. :(

Hi @fearmediocrity @michaelcuneo,

  1. Which version of Xcode are you using?
  2. Did you download the respective framework from the AWS iOS SDK?
  3. What does your header search path look like?

@fearmediocrity you are importing AWSCognitoCredentials but are calling ASCognitoCredential which is undefined. (note the missing W)?

I have the same issue. Android. Real device (Samsung S6).
Are there things missing from the README. Do we need to add external libraries (the Android AWS SDK) to make this work? They are mentinoned for iOS but not Android.

This fixed the issue (a bad installation more likely) for Android.
Add this line
compile 'com.amazonaws:aws-android-sdk-core:2.2.+'
in the dependencies of android/app/build.gradle if it's not there.

[How I got there:
I went to my node_modules/aws-sdk-react-native-core/android/build.gradle
saw this:
dependencies {
compile 'com.facebook.react:react-native:+'
compile 'com.amazonaws:aws-android-sdk-core:+'
}
From there, I got to this
http://docs.aws.amazon.com/mobile/sdkforandroid/developerguide/setup.html

used option 1 (my IDE is not Android Studio but I do use it) and voilà! :)]

@appwiz I am having same issue on iOS...
cognitoClient.initWithOptions(options) in AWSCognitoCredentials.js is undefined. Obviously native code not being found. When you say...
Did you download the respective framework from the AWS iOS SDK?
What does your header search path look like?

...can you give a little more detail on how to set those up properly.

I copied appropriate frameworks in iOS/Frameworks in my node_modules and then did xcode build which it said succeeded, but still having this issue. I would assume if build succeeded the header paths are good.

I also found an initial issue in AWSCognitoCredentials.js
it had async {callbackId}, I changed to async (callbackId)

Maybe my answer here can help : #24 (comment)