# Refresh token call fails with 401 in React Native app

**URL:** <https://community.auth0.com/t/refresh-token-call-fails-with-401-in-react-native-app/59378>\
**Category:** Get Help\
**Tags:** refresh\_token, refresh-tokens\
**Created:** [March 13, 2021, 7:20pm UTC](https://community.auth0.com/t/refresh-token-call-fails-with-401-in-react-native-app/59378 "2021-03-13T19:20:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![imsam67](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/imsam67/32/12846_2.png) [@imsam67](https://community.auth0.com/u/imsam67)\
**Post date:** [March 13, 2021, 7:20pm UTC](https://community.auth0.com/t/refresh-token-call-fails-with-401-in-react-native-app/59378/1 "2021-03-13T19:20:28Z")

</div>

In my React Native app – init app not Expo – I’m trying to refresh the `access_token` but my `POST` call is failing with `401` . I’m testing this functionality so I make the `POST` call some 30 seconds after I login so not sure if this plays a role or not.

In my initial login, I do get a `refresh_token` along with a valid `access_token` . I then tell my app to wait 30 seconds and make a `POST` call that looks like this:

```auto
const url = 'https://mydomain.auth0.com/oauth/token';
const postOptions = {
   method: 'POST',
   url: url,
   headers: {
      "content-type": 'application/x-www-form-urlencoded'
   },
   form: {
      grant_type: 'refresh_token',
      client_id: 'MY_CLIENT_ID',
      refresh_token: 'REFRESH_TOKEN_RECEIVED_DURING_LOG_IN'
   }
};

fetch(url, postOptions)
   .then((response) => {
       debugger;
       // this is where I get response.status 401
   })

```

Any idea what the issue is here?

Also want to mention that under my application settings, `Refresh Token` is checked under “Grant Types” but refresh token rotation or expiration are NOT enabled.

P.S. Also posted my question on StackOverflow. You can respond there if you prefer:

> <https://stackoverflow.com/questions/66617589/auth0-refresh-token-in-react-native-fails-with-401>

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [March 16, 2021, 2:06pm UTC](https://community.auth0.com/t/refresh-token-call-fails-with-401-in-react-native-app/59378/3 "2021-03-16T14:06:13Z")

</div>

Hi @imsam67,

Just to clarify, are you using the React Native SDK? [Auth0 React Native SDK Quickstarts: Login](https://auth0.com/docs/quickstart/native/react-native/00-login)

Also, to help troubleshoot, when you look at your tenant logs, do you see an error for the failed token refresh request? There might be helpful information in the log.

---

<div class="post-metadata">

**Author:** ![imsam67](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/imsam67/32/12846_2.png) [@imsam67](https://community.auth0.com/u/imsam67)\
**Post date:** [March 16, 2021, 3:29pm UTC](https://community.auth0.com/t/refresh-token-call-fails-with-401-in-react-native-app/59378/4 "2021-03-16T15:29:46Z")

</div>

Stephanie,

I was able to get it to work using the library – `react-native-auth0`. All your documentation is pointing to a regular `POST` call though and there’s no mention of using the library. I had to do a lot of digging to figure out how to use the `refreshToken()` method in the library. I strongly suggest you guys address this in your documentation.

As a future reference for those who may need this solution, here’s what I did.

The `react-native-auth0` library offers a `refreshToken` method that is used like below. The only parameter it needs is the current `refresh_token` that you got when you made the initial authentication call for the user. It’s important to mention that in the initial authentication call, you must include `offline_access` in the `scope`. Otherwise you won’t get a refresh token. Another important point is to save that refresh token in a safe place – and not just AsyncStorage – because unless you set it otherwise, your refresh token doesn’t expire and can be used again and again.

With that said, here’s what my refresh token call looks like. At start up, I initialize my `Auth0` instance as a global variable so that I can access it in different parts of my app.

```
global.auth0.auth.refreshToken({ refreshToken: 'MY_CURRENT_REFRESH_TOKEN' })
   .then(result => {
       // If you're doing it right, you'll receive a new access_token and an id_token
})

```

Here’s a slightly more detailed version of my solution:

> <https://stackoverflow.com/questions/66617589/auth0-refresh-token-in-react-native-fails-with-401>

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [March 16, 2021, 3:37pm UTC](https://community.auth0.com/t/refresh-token-call-fails-with-401-in-react-native-app/59378/5 "2021-03-16T15:37:01Z")

</div>

Thank you for the docs feedback and for sharing the solution, @imsam67!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [March 31, 2021, 3:37pm UTC](https://community.auth0.com/t/refresh-token-call-fails-with-401-in-react-native-app/59378/6 "2021-03-31T15:37:55Z")

</div>

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.
