08-20-2019 19:59
08-20-2019 19:59
I make two Oauth calls in the same class, one to my server (when a new user registers) then one to the fitbit server to authorize the new user, for some reason, no matter what, the second <Oauth function is using the data result from the first Oauth call that is in a completely different function (in the same class).
How is this possible? I cant figure this out at all, is it something to do with multiple <Oauth class in succession that the threads get mixed up or something? the data1 is from the previous <Oauth call that happens before this but should never be in this function.
fitbitSectionContents(){
var message = this.getSetting("fitbitAuthorizationMessage");
if(message){
return (
<Text bold>{message}</Text>
);
}
return [
<Text>You must connect your Fitbit.</Text>,
<Text>We will not have access to your Fitbit account password.</Text>,
<Oauth
settingsKey="AuthorizeApp"
label={<Text align="center" bold>Tap here to connect your Fitbit account</Text>}
status=""
authorizeUrl="https://www.fitbit.com/oauth2/authorize"
requestTokenUrl="https://api.fitbit.com/oauth2/token"
clientId="1111"
clientSecret="111111111111111111111"
scope="activity nutrition heartrate location nutrition profile settings sleep social weight"
onReturn={async (data1) => {
console.log("Data from oauth: " + JSON.stringify(data1, undefined, 4));
this.setSetting("fitbitAuthorizationMessage", "Logging in to Fitbit...");
this.getFitbitTokenFromExchangeCode(data1.code).then((function(result) {
console.log("Data from code exchange: " + JSON.stringify(result, undefined, 4));
this.setSetting("fitbitAuthorizationObject", JSON.stringify(result));
})).catch(function(error){
console.log("Error getting Fitbit token: " + error);
})
}}
/>
];
}
Best Answer