airlabsteam / react-native-aws-cognito-js Goto Github PK
View Code? Open in Web Editor NEWReact Native AWS Cognito JS SDK
License: Other
React Native AWS Cognito JS SDK
License: Other
This is a long shot, but I've taken over a project done in RN v .38 and I need to pull the auth to Cognito out of a native package an into a JS lib. I used your library to do this for Android, but unfortunately I'm getting the issue with not being able to find RCTBridgeModule.h in RNAWSCognito.h. And I'm hoping their might be a simple fix that won't require me to do a major upgrade refactor.
To reproduce my issue I did the following:
react-native init sample --version 0.38.0
npm install react-native-aws-cognito-js
react-native link react-native-aws-cognito-js
react-native run-ios
Which fails with:
/node_modules/react-native-aws-cognito-js/ios/RNAWSCognito.h:4:9: fatal error: 'React/RCTBridgeModule.h' file not found #import <React/RCTBridgeModule.h>
Mobile and RN development is not my wheelhouse, but I'm hoping there is some sort of xcode configuration or tricks I can do to get this working and avoid a major overhaul. Thanks in advance for any assistance.
The current release doesn't work in Android with RN 0.47+ because of these breaking changes:
facebook/react-native@ce6fb33
facebook/react-native@53d5504
I've temporarily fixed the problem by commenting out the first two @OverRide statements in ...\node_modules\react-native-aws-cognito-js\android\src\main\java\com\airlabsinc\RNAWSCognitoPackage.java
I'm not sure if this class is needed at all?
Getting this error when trying to sign in with a user with FORCE_CHANGE_PASSWORD
status.
Line: CognitoUser.js:287:50
I followed this example.
https://github.com/AirLabsTeam/react-native-aws-cognito-js/blob/master/example/app.js
I got this error in the console. "callback.newPasswordRequired is not a function"
How can I get around this?
Thanks
Does this announcement have any impact on your project?
https://aws.amazon.com/blogs/developer/react-native-support-in-the-aws-sdk-for-javascript/
Thanks for all of your hard work.
const userData = { Username: username, Pool: userPool };
const cognitoUser = new AWS.CognitoIdentityServiceProvider.CognitoUser(userData);
cognitoUser.getUserAttributes(function(err, result) {
if (err) {
alert(err);
return;
}
console.log(result)
for (i = 0; i < result.length; i++) {
console.log('attribute ' + result[i].getName() + ' has value ' + result[i].getValue());
}
});
I have a custom field userType. I have set the read, write permission for the custom attribute. But in the response of getUserAttributes i am getting only standard attributes(sub, email_verified, email). How can i retrieve both the standard and custom attributes?
This is my response -
Let's say we want users to sign in into our app. There are 2 ways:
1.) Signup, and login (this will create an account in User Pool)
2.) Facebook login (user will just login to his facebook account)
Now, 1.) works fine, I'm able to have users signup and login. I am having problem in 2.). I was able to get the token from facebook (I am able to integrate facebook login button in my react native app)... Now after we get the token,, I want my users to use this facebook login and just continue using the app.
How do we achieve this? Are we supposed to create a new user in UserPool programatically if users login via facebook? Or we dont have to create the account manually (I assume that once the user logins using his facebook account, the next time he will use the app, he will be remembered)?
My point of confusion is, there is no cognitoUser if we are using federated identities or facebook. Please help me clear this confusion and what would be the best thing to proceed for number 2.
Hi guys,
thanks a lot for your great job.
I am trying to integrate amazon login and facebook login using your module, but no luck yet.
Should I go through all the info.plist/AppDeligame and Android specific files?
Could you, please, be more specific about installation and integration steps?
Thanks
I am using authenticateUser
on iOS and Android.
iOS is working fine. I am running into TypeError: undefined is not an object (evaluating 'RNAWSCognito.computeModPow')
on android.
Anything I am missing here.
Breaking - remove unused registration of JS modules
Summary: It's now unnecessary to declare which JS modules you want to expose on your package. To upgrade, remove all overrides of createJSModules
and keeping calling your JS modules as before.
C:\Users\piust\Documents\terminal\node_modules\react-native-aws-cognito-js\android\src\main\java\com\airlabsinc\RNAWSCognitoPackage.java:18: error: method does not override or implement a method from a supertype
@OverRide
^
1 error
:react-native-aws-cognito-js:compileDebugJavaWithJavac FAILED
Let's say users can loggedin, and somewhere we are using the following code (when login is successful)
userPool.storage.sync((err, result) => {
// MemoryStorage is now updated with AsyncStorage values
});
or
cognitoUser.storage.sync((err, result) => {
// MemoryStorage is now updated with AsyncStorage values
});
Now, let's say we have a function that will check if user is actually logged in. (App restart)
export const checkIfLoggedIn = () => {
return (dispatch) => {
dispatch({ type: DO_NOTHING });
var userPool = new CognitoUserPool(appConfig);
var cognitoUser = userPool.getCurrentUser();
console.log(cognitoUser);
if (cognitoUser != null) {
cognitoUser.getSession(function(err, session) {
if (err) {
console.log(err);
return;
}
console.log('session validity: ' + session.isValid());
// NOTE: getSession must be called to authenticate user before calling getUserAttributes
cognitoUser.getUserAttributes(function(err, attributes) {
if (err) {
// Handle error
} else {
// Do something with attributes
console.log(attributes);
}
});
Actions.main({ type: 'reset' });
});
}
}
};
Why is that cognitoUser is being returned as null? Also why did we enable both userPool or cognitoUser to be sync, cant it be just one of them?
Hello guys,
I have use below mention version.
"react-native": "0.56.0",
"react-native-aws-cognito-js": "0.0.7",
"react": "16.4.1",
Please help me.
for React Native 0.54 and higher please use the AWS Amplify supported library and add the babel-preset-es2015 to your dev deps to transpile your builds correctly
Thanks for this great tool! It's really helpful!
Now I'm facing another problem, I'm attempting to follow this guide to access S3 resources
https://aws.amazon.com/blogs/developer/react-native-support-in-the-aws-sdk-for-javascript/
import {
AWS,
TransferUtility,
Config,
CognitoIdentityCredentials
} from "aws-sdk/dist/aws-sdk-react-native";
......
const s3 = new AWS.S3({
region: 'us-east-1',
credentials: Config.credentials
});
However it raised error message
undefined is not an object (evaluating 'new_awsSdkReactNative.AWS.S3')
Shall I use other method to import AWS resources?
Thank you!
I ran the app.js from the example locally. Cognito returns the access token. However, when console logging Config.credentials, I got the following:
CognitoIdentityCredentials {expired: true, expireTime: null, accessKeyId: undefined, sessionToken: undefined, params: Object…}
accessKeyId:undefined
data:null
expireTime:null
expired:true
params:Object
sessionToken:undefined
_clientConfig:Object
_identityId:null
identityId:(...)
secretAccessKey:undefined
get identityId:function get()
set identityId:function set(identityId)
proto:Credentials
How do I get a valid session when an user login ?
:react-native-aws-cognito-js:compileReleaseJavaWithJavac - is not incremental (e.g. outputs have changed, no previous execution, etc.). /app/node_modules/react-native-aws-cognito-js/android/src/main/java/com/airlabsinc/RNAWSCognitoPackage.java:18: error: method does not override or implement a method from a supertype @Override
Simple fix: remove createJSModules
method. More on the RN update: https://github.com/facebook/react-native/releases/tag/v0.47.0
First of all: Thanks for your great work!
I get a warning if I try to fetch the crendentials via Facebook as identity provider:
// Add the Facebook access token to the Cognito credentials login map.
Config.credentials = CognitoIdentityCredentials({
IdentityPoolId: appConfig.IdentityPoolId,
Logins: {
'graph.facebook.com': accessToken // accessToken from FB-SDK
}
});
// Obtain AWS credentials
Config.credentials.get(e=>console.log(e));
The warning:
Possible Unhandled Promise Rejection (id: 0):
TypeError: this.loadCachedId is not a function
TypeError: this.loadCachedId is not a function
at CognitoIdentityCredentials (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:203985:10)
at LoginMainScreen._onFBSuccess (/js/screens/login/LoginMainScreen.map?platform=android&runModule=false&entryModuleOnly=true&hot=true:147:103)
Did I something wrong? Is it a small issue? Otherwise it is not very important because it works via aws-sdk-react-native
From the README.md
I'm using:
userPool.storage.sync((err, result) => {
// MemoryStorage is now updated with AsyncStorage values
});
or
cognitoUser.storage.sync((err, result) => {
// MemoryStorage is now updated with AsyncStorage values
});
I played around with the example application without a crash, the result logs 'SUCCESS'
.
Here's an example snippet of where I've tried to use it:
const authenticationData = {
Username: username,
Password: password,
};
var authenticationDetails = new AuthenticationDetails(authenticationData);
var poolData = {
UserPoolId: appConfig.UserPoolId,
ClientId: appConfig.ClientId
};
var userPool = new CognitoUserPool(poolData);
var userData = {
Username: username,
Pool: userPool
};
var cognitoUser = new CognitoUser(userData);
cognitoUser.authenticateUser(authenticationDetails, {
onSuccess: (result) => {
console.log(`ID.JWT TOKEN =====> ${result.getIdToken().getJwtToken()}`);
AsyncStorage.setItem('token', result.getIdToken().getJwtToken());
AWS.config.credentials = new CognitoIdentityCredentials({
IdentityPoolId: appConfig.IdentityPoolId,
Logins: {
[`cognito-idp.${appConfig.region}.amazonaws.com/${appConfig.UserPoolId}`]: result.getIdToken().getJwtToken()
},
}, {
region: 'us-east-1'
});
Intercom.logEvent('success_login_user', { username });
AWS.config.credentials.refresh((error) => {
if (error) console.log(error);
});
cognitoUser.storage.sync((err, res) => {
if (err) console.log(err);
console.log(res);
});
Intercom.logEvent('success_login_user');
dispatch({
type: types.LOGIN_USER_SUCCESS,
payload: result
});
...
}
Hi there,
I am getting this error when trying to cognitoUser.authenticateUser with the basic Authentication example.
I am using the expo XDE and IOS simulator. I have linked the projects as shown in the instructions.
I am developing React Native Expo app and tried to use authenticate.
And I got the error as follow.
_awsSdkReactNative.util.crypto.lib.randomBytes is not a function. (In '_awsSdkReactNative.util.crypto.lib.randomBytes(128)', '_awsSdkReactNative.util.crypto.lib.randomBytes' is undefined)
Environment:
Packages: (wanted => installed)
When I try $ react-native run-android
on android emulator, I get this error:
:app:compileDebugJavaWithJavac
/home/user/app/android/app/src/main/java/com/package/MainApplication.java:8: error: a type with the same simple name is already defined by the single-type-import of RNAWSCognitoPackage
import com.airlabsinc.RNAWSCognitoPackage;
^
1 error
Incremental compilation of 1 classes completed in 0.448 secs.
:app:compileDebugJavaWithJavac FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 10.964 secs
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.html
Then I have 2 imports with the same name in my /home/user/app/android/app/src/main/java/com/package/MainApplication.java
May this cause the issue?
Is this the issue with RN?
package com.package;
import android.app.Application;
import com.facebook.react.ReactApplication;
import com.amazonaws.RNAWSCognitoPackage; // 1
import com.amazonaws.amplify.pushnotification.RNPushNotificationPackage;
import com.airlabsinc.RNAWSCognitoPackage; // 2
import com.horcrux.svg.SvgPackage;
import com.toast.ToastPackage;
import com.vdi.VDIPackage;
import com.BV.LinearGradient.LinearGradientPackage;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;
import java.util.Arrays;
import java.util.List;
// TO DO
Running app on android emulator
See error above
SO: https://stackoverflow.com/questions/50815811/execution-failed-for-task-appcompiledebugjavawithjavac
react-native: facebook/react-native#19656
I encountered undefined error when evaluating RNAWSCognito.computeModPow() in AuthenticationHelper.js, resolved by removing the {},
from
const { RNAWSCognito } = NativeModules;
to
const RNAWSCognito = NativeModules;
But now I encountered RNAWSCognito.computeModPow is not a function. Which dependency do I need for iOS?
Thanks for all the work you've done but am having an issue with mapping.
This part of the first example doesn't seem to work:
Config.credentials = new CognitoIdentityCredentials({ IdentityPoolId: appConfig.IdentityPoolId, Logins: { [
cognito-idp.${appConfig.region}.amazonaws.com/${appConfig.UserPoolId}]: result.getIdToken().getJwtToken() } });
On my online dashboard for that userpool I can't see that specific user being logged in.
Same happens when am trying to map back a facebook access token to generate a JWT token from the session.
Any Ideas?
I was wondering if using CognitoSync was possible with this module?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.