# React Native "An error occurred when trying to authenticate with the server"

**URL:** <https://community.auth0.com/t/react-native-an-error-occurred-when-trying-to-authenticate-with-the-server/115820>\
**Category:** Get Help\
**Tags:** users, management-api\
**Created:** [September 9, 2023, 4:01am UTC](https://community.auth0.com/t/react-native-an-error-occurred-when-trying-to-authenticate-with-the-server/115820 "2023-09-09T04:01:11Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![taboobat](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/taboobat/32/50704_2.png) [@taboobat](https://community.auth0.com/u/taboobat)\
**Post date:** [September 9, 2023, 4:01am UTC](https://community.auth0.com/t/react-native-an-error-occurred-when-trying-to-authenticate-with-the-server/115820/1 "2023-09-09T04:01:11Z")

</div>

I’m trying to add a Patreon login to my React Native app and I have it almost working – I set up a custom social connection using [this post](https://community.auth0.com/t/patreon-custom-social-connection-sample-basics/110784) and installed the Auth0 react native library, so far so good.

When I call `authorize({}, {})` I get the vague error “An error occurred when trying to authenticate with the server.” although it _seems_ like the OAuth works, I get redirected to the Auth0 page, click the button to go to Patreon, then on Patreon click Allow to grant access. But when I get redirected back to my app `user` is null and I have the aforementioned error message.

My code’s pretty straightforward:

```auto
const Patreon = (props) => {
    const {authorize, clearSession, user, getCredentials, error, isLoading} = useAuth0();

    const login = async () => {
        try {
            await authorize({}, {});
            const credentials = await getCredentials();
            // console.warn(credentials);
        } catch (e) {
            console.warn(e);
        }
    }

    const logout = async () => {
        try {
            await clearSession();
        } catch (e) {
            console.log(e);
        }
    }

    console.warn(error);

    return <View>
        <Button title="Patreon Login" onPress={login} />
        <Button title="Logout" onPress={logout} />
    </View>
}

```

Package wise I have

- react-native: 0.72.3
- react-native-auth0: 3.0.1

Is there any way to get more logging out of the login process? Everything seems to be set up correctly so I have no idea what this error means.

---

<div class="post-metadata">

**Author:** ![nick.wade](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nick.wade/32/20885_2.png) [@nick.wade](https://community.auth0.com/u/nick.wade)\
**Post date:** [September 11, 2023, 5:24pm UTC](https://community.auth0.com/t/react-native-an-error-occurred-when-trying-to-authenticate-with-the-server/115820/2 "2023-09-11T17:24:28Z")

</div>

qq to start @taboobat, is your Patreon Social Connection working outside of your react-native app, e.g., if you test the connection, etc?

---

<div class="post-metadata">

**Author:** ![taboobat](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/taboobat/32/50704_2.png) [@taboobat](https://community.auth0.com/u/taboobat)\
**Post date:** [September 11, 2023, 5:36pm UTC](https://community.auth0.com/t/react-native-an-error-occurred-when-trying-to-authenticate-with-the-server/115820/3 "2023-09-11T17:36:28Z")

</div>

Yes it is, when I test the connection on the Auth0 dashboard I get the “It works!” screen with an example payload that the app should receive (if it wasn’t currently erroring in app).

---

<div class="post-metadata">

**Author:** ![taboobat](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/taboobat/32/50704_2.png) [@taboobat](https://community.auth0.com/u/taboobat)\
**Post date:** [September 11, 2023, 5:54pm UTC](https://community.auth0.com/t/react-native-an-error-occurred-when-trying-to-authenticate-with-the-server/115820/4 "2023-09-11T17:54:27Z")

</div>

Here’s a redacted screenshot of what I get when I go through “Try Connection”

 ![image](https://global.discourse-cdn.com/auth0/original/3X/5/f/5fded4f74943f4b6a3489c315613214c43d77961.png)

Is there any logging I can enable anywhere? The error message “An error occurred when trying to authenticate with the server.” doesn’t appear in the React Native lib’s codebase ([GitHub - auth0/react-native-auth0: React Native toolkit for Auth0 API](https://github.com/auth0/react-native-auth0)) so I don’t know how to even tell which server it’s trying to contact.

---

<div class="post-metadata">

**Author:** ![nick.wade](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nick.wade/32/20885_2.png) [@nick.wade](https://community.auth0.com/u/nick.wade)\
**Post date:** [September 11, 2023, 8:02pm UTC](https://community.auth0.com/t/react-native-an-error-occurred-when-trying-to-authenticate-with-the-server/115820/5 "2023-09-11T20:02:18Z")

</div>

Logging: yes first part is already there under **Monitoring** ➔ **Logs** in your Manage dashboard. Check for both `s` (Success Login) and `seacft` (Success Exchange) type entries there.

Any Rules or Actions enabled in your flow?

---

<div class="post-metadata">

**Author:** ![taboobat](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/taboobat/32/50704_2.png) [@taboobat](https://community.auth0.com/u/taboobat)\
**Post date:** [September 11, 2023, 10:08pm UTC](https://community.auth0.com/t/react-native-an-error-occurred-when-trying-to-authenticate-with-the-server/115820/6 "2023-09-11T22:08:29Z")

</div>

Firstly (and a bit late) thank you for your help! In case it’s not clear I’m very very new to Auth0, I hadn’t heard of it before this weekend. My only goal is get an access token from Patreon in order to check for active subscriptions, etc, so that’s all I’ve set up. Brand new account, created the custom Social Connection for Patreon from the post in the OP, and created a single application that uses that connection. No rules, no actions, no other connections.

Thanks for pointing me to the logs page, with that I can see the success when I use the test on the Auth0 dashboard and an error when I try to connect in the app (progress!). The error is a failed exchange with the error “Unauthorized”, and there’s also a Success Login log generated:

 ![image](https://global.discourse-cdn.com/auth0/original/3X/d/b/db405aa6cc050416b01c9e8126b111301a382128.png)

In the details of the error it has (some redactions):

```auto
  "date": "2023-09-11T21:58:08.186Z",
  "type": "feacft",
  "description": "Unauthorized",
  "connection_id": "",
  "client_id": "<my id copied from the application dashboard>",
  "client_name": null,
  "ip": "96.235.24.53",
  "user_agent": "okhttp 4.10.0 / Other 0.0.0",
  "details": {
    "code": " ****************************************** u0R"
  },
  "hostname": "dev-<redacted, but correct>.us.auth0.com",
  "user_id": "",
  "user_name": "",
  "auth0_client": {
    "name": "Auth0.Android",
    "env": {
      "android": "30"
    },
    "version": "2.10.0"
  },
  "log_id": "90020230911215809051061000000000000001223372040005784503",
  "_id": "90020230911215809051061000000000000001223372040005784503",
  "isMobile": false,
  "id": "90020230911215809051061000000000000001223372040005784503"
}

```

So this looks to me like it’s an error communicating with the Auth0 server, though I’m not sure why – I did just now double check my tenant and client id that get passed into the library. I don’t think those could be wrong because like I said in the OP the OAuth almost works, when I click login I get to the Auth0 page at my tenant with the login with Patreon button (and it has my tenant and app name on that page so those are getting read correctly), when I click that it takes me to Patreon where I click Allow, and then it drops me back in my app with the error.

It must be something with the redirect from Patreon back to the Auth0 servers? I’m glad there’s a concrete error but I’m not sure how to dig deeper.

---

<div class="post-metadata">

**Author:** ![nick.wade](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nick.wade/32/20885_2.png) [@nick.wade](https://community.auth0.com/u/nick.wade)\
**Post date:** [September 11, 2023, 11:27pm UTC](https://community.auth0.com/t/react-native-an-error-occurred-when-trying-to-authenticate-with-the-server/115820/7 "2023-09-11T23:27:19Z")

</div>

Thanks, got your tenant from the log\_id and took a look. We’ll try to dig something else up internally here and come back to you soon.

---

<div class="post-metadata">

**Author:** ![nick.wade](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nick.wade/32/20885_2.png) [@nick.wade](https://community.auth0.com/u/nick.wade)\
**Post date:** [September 12, 2023, 12:01am UTC](https://community.auth0.com/t/react-native-an-error-occurred-when-trying-to-authenticate-with-the-server/115820/8 "2023-09-12T00:01:28Z")

</div>

OK, so the Failed Login was my test call on your Application settings in Auth0 Server. You can ignore it.

Right now you have Application Type Credential settings that are breaking your token flow. From another thread:

> [@Failed Exchange: Unauthorized (feacft)](https://community.auth0.com/t/failed-exchange-unauthorized-feacft/44537/2):
>
> The solution is to enable `OIDC Conformant` and set the refresh token behavior to `Rotating`.

And you’ve also helped us find a UI bug that might confuse the issue further. Here’s how to turn these off in order to restore… uh… order.

First, in your **Application ➔ Settings** in Manage, if you do NOT have the Credentials tab visible, then scroll to the Application Type and change it to `Regular Web Application`. The following **Note:** dialog will appear beneath . You can click `View Credentials` there OR scroll up and the **Credentials** tab will now be visible.

![Screenshot 2023-09-11 at 4.55.18 PM](https://global.discourse-cdn.com/auth0/original/3X/c/4/c441fe7475d69751936abf447084be8d2762c837.png)

Ok.

Second, in the **Credentials** settings there, you’ll find your **Authentication Methods** is set to `Client Secret (Post)`. Change this by setting it back to the default of `None`.

![Screenshot 2023-09-11 at 5.00.44 PM](https://global.discourse-cdn.com/auth0/original/3X/7/4/7415d5608a967baff731476551dcad3ec08bf13b.png)

Lastly, you can return to **Application ➔ Settings** tab and return the Application Type back to `Native`, and you should be good to go.

LMK how you get on. We’ll address the settings bug that allows Credentials changes like **Client Secret (Post)** to accidentially remain hidden and on in the background.

---

<div class="post-metadata">

**Author:** ![taboobat](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/taboobat/32/50704_2.png) [@taboobat](https://community.auth0.com/u/taboobat)\
**Post date:** [September 12, 2023, 2:23am UTC](https://community.auth0.com/t/react-native-an-error-occurred-when-trying-to-authenticate-with-the-server/115820/9 "2023-09-12T02:23:23Z")

</div>

That did it, thank you! I’m getting the access token now and should be good to work on my integration!

I’m curious, is this something that I accidentally did, or is it a default value that got set? I don’t recall ever changing my app type to web (I’m pretty sure I made it Native from the start) or messing with credentials settings, although it’s definitely possible that I did something while I was trying to figure it out initially.

---

<div class="post-metadata">

**Author:** ![taboobat](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/taboobat/32/50704_2.png) [@taboobat](https://community.auth0.com/u/taboobat)\
**Post date:** [September 12, 2023, 3:28am UTC](https://community.auth0.com/t/react-native-an-error-occurred-when-trying-to-authenticate-with-the-server/115820/10 "2023-09-12T03:28:34Z")

</div>

Actually I seem to be running into another issue which may be just me not being familiar with how Auth0 works, or possibly I’m doing something wrong with the Patreon API.

Still with the same code as in the OP, I’m now getting a `user` back and I’m getting some credentials from the call to `getCredentials`, but I’m not sure if the credentials are correct or not.

The credentials object is of the shape

```auto
{
    "accessToken": "<jwt>",
    "expiresAt": 1694574871,
    "idToken": "<jwt>",
    "refreshToken": null,
    "scope": "openid profile email",
    "tokenType": "Bearer"
}

```

But I can’t seem to use the tokens, when I try to hit the Patreon API with the token from `accessToken` is says that I’m unauthorized because my token is wrong and I’m quite sure that I’m attaching the token correctly:

```auto
        try {
            const response = await fetch('https://www.patreon.com/api/oauth2/v2/identity', {
                method: 'GET',
                headers: {
                    'Authorization': `Bearer ${token}`,
                    'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
                }
            });
            const data = await response.json();
            console.warn(data);
        } catch (e) {
            console.warn(e);
        }

```

The thing that’s confusing to me is that [the Patreon docs](https://docs.patreon.com/#step-4-validating-receipt-of-the-oauth-token) say that I should get tokens back in an object like

```auto
{
    "access_token": <single use token>,
    "refresh_token": <single use token>,
    "expires_in": <token lifetime duration>,
    "scope": <token scopes>,
    "token_type": "Bearer"
}

```

which doesn’t match up with the fields that I’m getting back – I’m getting camelCase instead of snake\_case which overall is fine, but I’m not getting a refresh token at all which seems odd, and not great since I’ll want to be able to refresh my tokens. I’m also getting an expire time for my `accessToken` of 24 hours, and their docs say that it should be for a month.

I tried to decode the `accessToken` to check its contents and it seems that it has an empty payload – there’s a part that looks like `jb20vIn0..6Dq` and I think there should be a payload of some kind in between those `..`

Are these the right tokens forwarded from Patreon, or are these separate tokens issued by Auth0? I’m just kind of confused.

---

<div class="post-metadata">

**Author:** ![nick.wade](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nick.wade/32/20885_2.png) [@nick.wade](https://community.auth0.com/u/nick.wade)\
**Post date:** [September 12, 2023, 8:51pm UTC](https://community.auth0.com/t/react-native-an-error-occurred-when-trying-to-authenticate-with-the-server/115820/11 "2023-09-12T20:51:07Z")

</div>

> [@taboobat](#):
>
> is this something that I accidentally did, or is it a default value that got set?

These settings are normally not available by default when one creates a Native application, but will be available and set this way if creating a Regular Web app type. Easily changed though, aside from said UX bug 😕

> [@taboobat](#):
>
> I can’t seem to use the tokens, when I try to hit the Patreon API with the token from `accessToken` is says that I’m unauthorized

Yes, you’ve been issued a token from Auth0 to authenticate your user into your application and if I understand correctly you may be trying the Patreon API with _that_, however calling their API requires authentication with them. This doc may help: [Call an Identity Provider API](https://auth0.com/docs/authenticate/identity-providers/calling-an-external-idp-api#:~:text=Once%20you%20successfully%20authenticate%20a,to%20call%20the%20IdP's%20API)

---

<div class="post-metadata">

**Author:** ![nick.wade](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nick.wade/32/20885_2.png) [@nick.wade](https://community.auth0.com/u/nick.wade)\
**Post date:** [September 12, 2023, 8:57pm UTC](https://community.auth0.com/t/react-native-an-error-occurred-when-trying-to-authenticate-with-the-server/115820/12 "2023-09-12T20:57:08Z")

</div>

I might be wrong btw, but hopefully that doc will set you right.

---

<div class="post-metadata">

**Author:** ![taboobat](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/taboobat/32/50704_2.png) [@taboobat](https://community.auth0.com/u/taboobat)\
**Post date:** [September 13, 2023, 3:57pm UTC](https://community.auth0.com/t/react-native-an-error-occurred-when-trying-to-authenticate-with-the-server/115820/13 "2023-09-13T15:57:54Z")

</div>

I think you’re right, I need to go through those steps to get an access token for Patreon itself. I was poking around with that a bit and ran into more errors but I’ll see if I can figure those out from other docs and posts. And even if I can’t we’ll have strayed pretty far from the original question of this post so if needed I’ll make a new one. Thanks for all your help!

---

<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:** [September 27, 2023, 3:58pm UTC](https://community.auth0.com/t/react-native-an-error-occurred-when-trying-to-authenticate-with-the-server/115820/14 "2023-09-27T15:58:13Z")

</div>

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