aws-sdk-react-native icon indicating copy to clipboard operation
aws-sdk-react-native copied to clipboard

NativeModules.AWSRNCognitoCredentials returns undefined

Open jamespearson opened this issue 8 years ago • 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;

jamespearson avatar Sep 02 '16 20:09 jamespearson

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

michaelcuneo avatar Sep 05 '16 07:09 michaelcuneo

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?

appwiz avatar Sep 12 '16 15:09 appwiz

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

mnichols avatar Sep 18 '16 21:09 mnichols

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.

ksegla avatar Oct 17 '16 15:10 ksegla

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à! :)]

ksegla avatar Oct 17 '16 19:10 ksegla

@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)

jeffbonasso avatar Dec 02 '16 20:12 jeffbonasso

Maybe my answer here can help : https://github.com/awslabs/aws-sdk-react-native/issues/24#issuecomment-267746814

mnichols avatar Dec 17 '16 06:12 mnichols