Background job to fetch user data and refreshing access tokens problem

Solution for Background job to fetch user data and refreshing access tokens problem
is Given Below:

  1. A user signs in using OAuth 2.0 to authenticate
  2. I get an access token and a refresh token
  3. I store the access token as a cookie for a month
  4. After an hour a background job starts in my API and I use those tokens to fetch data specific to that user
  5. The access token expired so I have to use the refresh token to get a new access token
  6. I fetched the data in the background and everything is fine
  7. After 2 hours the user opens the website and the stored access token in the cookie is now invalid

How do I have the user automatically sign in?