StasDoskalenko/react-native-google-fit

Authorization is not saving its state

Smokier opened this issue · 1 comments

Im using the auth fucntion provided by the library but i need to run it again everytime i exit the app to start using the request methods, otherwise the isAuthorized prop always returns false, i tried run it in a effect on the first render but it request the permissions if they arent allowed yet and i only want to show this screen when the user decides to do the connection.

const GoogleF = ()=>{
const options = {
scopes: [
Scopes.FITNESS_ACTIVITY_READ,
Scopes.FITNESS_ACTIVITY_WRITE,
Scopes.FITNESS_BODY_READ,
Scopes.FITNESS_BODY_WRITE,
Scopes.FITNESS_HEART_RATE_READ,
Scopes.FITNESS_HEART_RATE_WRITE,
],
};
GoogleFit.checkIsAuthorized().then(() => {
var authorized = GoogleFit.isAuthorized;
console.log(authorized);
if (authorized) {
setAuthor(true)
} else {
// Authentication if already not authorized for a particular device
GoogleFit.authorize(options)
.then(authResult => {
if (authResult.success) {
console.log('AUTH_SUCCESS');

             // if successfully authorized, fetch data
           } else {
             console.log('AUTH_DENIED ' + authResult.message);
           }
         })
         .catch(() => {
           dispatch('AUTH_ERROR');
         });
     }

});
}

This method works and allows me to obtain data but i find pretty incovinient having to run it every time i start the app, is there a way to change this so i dont have to run this every time and only once?

Hopefully this can answer your question: #240 (comment) . The state is not as reliable as you thought.

Feel free to suggest any solutions.