You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Oct 12, 2018. It is now read-only.
Using AWSCognitoCredentials I'm finding that the method isAuthenticated returns true only the first time. Subsequent logins return false.
I'm using sample code I found in an Amazon GitHub repo, however have since been unable to locate the repo that has it.
//// Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.//// Licensed under the Apache License, Version 2.0 (the "License").// You may not use this file except in compliance with the License.// A copy of the License is located at//// http://aws.amazon.com/apache2.0//// or in the "license" file accompanying this file. This file is distributed// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either// express or implied. See the License for the specific language governing// permissions and limitations under the License.//constFBSDK=require('react-native-fbsdk');const{
LoginButton,
AccessToken
}=FBSDK;importReact,{Component}from'react';import{AWSCognitoCredentials}from'aws-sdk-react-native-core';import{AppRegistry,StyleSheet,Text,View,NativeModules,NativeAppEventEmitter}from'react-native';varfbookToken=''varsupplyLogins=false;conststyles=StyleSheet.create({container: {flex: 1,justifyContent: 'center',alignItems: 'center',backgroundColor: '#F5FCFF',},welcome: {fontSize: 20,textAlign: 'center',margin: 10,},instructions: {textAlign: 'center',color: '#333333',marginBottom: 5,},fbButton: {borderColor: '#2d5073',backgroundColor: '#3b5998',},attribute: {fontSize: 5}});varregion=YOUR_REGION_HERE;varidentity_pool_id=YOUR_ID_HEREexportdefaultclassexampleextendsComponent{constructor(props){super(props);this.state={loginMessage: 'Log Into Facebook',Authenticated:'False',identityID: '',AccessKey:'',SecretKey:'',SessionKey:'',Expiration:'',isLoggedIn: false};AWSCognitoCredentials.identityChanged=function(Previous,Current){console.log("PreviousID: "+Previous);console.log("CurrentID: "+Current);}AWSCognitoCredentials.getLogins=function(){if(supplyLogins){varmap={};map[AWSCognitoCredentials.RNC_FACEBOOK_PROVIDER]=fbookToken;returnmap;}else{return"";}};}Refresh(){varthat=this;asyncfunctiongetCredAndID(){try{varvariable=awaitAWSCognitoCredentials.getCredentialsAsync();that.setState({AccessKey:variable["AccessKey"],SecretKey:variable["SecretKey"],SessionKey:variable["SessionKey"],Expiration:variable["Expiration"].toString()});variable=awaitAWSCognitoCredentials.getIdentityIDAsync();that.setState({identityID:variable.identityid});}catch(e){console.log("Error: "+e)return;}}getCredAndID();AWSCognitoCredentials.isAuthenticated(function(error,variable){if(error){console.log("Error: "+error)}else{if(variable){that.setState({Authenticated:"True"});}else{that.setState({Authenticated:"False"});}}});}ClearCred(){AWSCognitoCredentials.clearCredentials();}ClearKeychain(){AWSCognitoCredentials.clear();}onLoginInvoked(isLoggingIn,Accesstoken){that=this;if(isLoggingIn){fbookToken=Accesstoken;supplyLogins=true;AWSCognitoCredentials.initWithOptions({"region":region,"identity_pool_id":identity_pool_id})varmap={};map[AWSCognitoCredentials.RNC_FACEBOOK_PROVIDER]=fbookToken;AWSCognitoCredentials.setLogins(map);//ignored for iOSreturn;}else{supplyLogins=false;}}render(){return(<Viewstyle={styles.container}><Text>is User Authenticated?: {this.state.Authenticated}</Text><Text>Identity Id: {this.state.identityID}</Text><Text>AccessKey: {this.state.AccessKey}</Text><Text>SecretKey: {this.state.SecretKey}</Text><Text>SessionKey: </Text><Textstyle={styles.attribute}>{this.state.SessionKey}</Text><Text>Expiration: {this.state.Expiration}</Text><View><LoginButtononLoginFinished={(error,result)=>{if(error){alert("login has error: "+result.error);}elseif(result.isCancelled){alert("login is cancelled.");}else{AccessToken.getCurrentAccessToken().then((data)=>{this.onLoginInvoked(true,data.accessToken.toString());})}}}onLogoutFinished={()=>this.onLoginInvoked(false,"")}/></View><TextonPress={this.Refresh.bind(this)}>
Click Me To Refresh The View!!!
</Text><TextonPress={this.ClearCred.bind(this)}>
Click Me To Clear Credentials!!
</Text><TextonPress={this.ClearKeychain.bind(this)}>
Click Me To Clear Keychain!
</Text></View>);}}
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
RN version 0.37
Using AWSCognitoCredentials I'm finding that the method
isAuthenticated
returnstrue
only the first time. Subsequent logins returnfalse
.I'm using sample code I found in an Amazon GitHub repo, however have since been unable to locate the repo that has it.
The text was updated successfully, but these errors were encountered: