amazon-archives / aws-sdk-react-native

AWS SDK for React Native (developer preview)
Apache License 2.0
631 stars 68 forks source link

NativeModules.AWSRNCognitoCredentials returns undefined #4

Open jamespearson opened 7 years ago

jamespearson commented 7 years ago

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;

michaelcuneo commented 7 years ago

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

appwiz commented 7 years ago

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?
mnichols commented 7 years ago

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

ksegla commented 7 years ago

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 commented 7 years ago

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

jeffbonasso commented 7 years ago

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

mnichols commented 7 years ago

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