tiagob / create-full-stack

Set up a TypeScript full stack with one command.
https://create-full-stack.com
MIT License
97 stars 9 forks source link

react native setTimeout Android warning #173

Open bojidaryovchev opened 3 years ago

bojidaryovchev commented 3 years ago

Hello there, I saw the discussion here https://github.com/expo/examples/issues/209 and that the implementation around handling refresh tokens with Expo is still foggy so I turned to your library. I successfully plugged it in my react native project however I am getting the following warning:

Setting a timer for a long period of time, i.e. multiple minutes, is a performance and correctness issue on Android as it keeps the timer module awake, and timers can only be called when the app is in the foreground. See https://github.com/facebook/react-native/issues/12981 for more info.

which comes from this piece of code:

  setTimeout(() => {
      let refreshTokenData = data;
      if (token.refresh_token) {
          refreshTokenData = {
              ...data,
              refresh_token: token.refresh_token,
              grant_type: "refresh_token",
          };
      }
      fetchAccessToken(refreshTokenData, domain, setAccessToken, setUser, onTokenRequestFailure);
  }, token.expires_in * 1000 - requestNewAccessTokenBuffer);

I found out that I can suppress the warning using LogBox.ignoreLogs(['Setting a timer for a long period of time']); however I am not sure that would be the right way to go so I wanted to ask for your expertise on the matter as to what would the best approach be. Regards!