react-native-aws-cognito-js
This is an adaptation of Amazon Cognito Identity SDK for JavaScript in combination with AWS SDK for JavaScript for React Native.
This project uses Native Modules to handle intensive math operations on the device using the React Native bridge.
Installation
Install in your application directory:
npm install --save react-native-aws-cognito-js
or
yarn add react-native-aws-cognito-js
Link project:
react-native link react-native-aws-cognito-js
MemoryStorage
The local MemoryStorage can handle everything on the authentication side, but the data is lost when the app is reopened. The storage sync method will grab only the MemoryStorage data from AsyncStorage and update the local MemoryStage with the values.
The new sync method can be used from either the userPool or cognitoUser:
userPoolstorage;
or
cognitoUserstorage;
Usage
Refer to the Amazon Cognito Identity SDK for JavaScript usage examples.
Example
This is a user authentication sample:
//imports; ; const appConfig = region: '' IdentityPoolId: '' UserPoolId: '' ClientId: '' //setting configConfigregion = appConfigregion; //component:state = username: '' password: '' { const username password = thisstate; const authenticationData = Username: username Password: password ; const authenticationDetails = authenticationData; const poolData = UserPoolId: appConfigUserPoolId ClientId: appConfigClientId ; const userPool = poolData; const userData = Username: username Pool: userPool ; const cognitoUser = userData; cognitoUser;}
Advanced Example
//- AWS.js//create AWS with userPool using dotenv to hold environment variables;;; Object; AWSconfig; const poolData = UserPoolId: AWS_POOL_ID ClientId: AWS_POOL_CLIENT_ID; const userPool = poolData; ;
//import AWS and userPool; //component:state = username: '' password: '' { const username password = thisstate; const authenticationData = Username: username Password: password ; const authenticationDetails = authenticationData; const userData = Username: username Pool: userPool ; const cognitoUser = userData; cognitoUser;}