Skip to content

Interceptor Duplicates When Modifying and Saving _layout.tsx File in Expo Project Using client-fetch #1001

@goltra

Description

@goltra

Description

Hello, I have an issue when implementing the interceptor.

I am working on an Expo project and using client-fetch. I'm using these versions:
"@hey-api/client-fetch": "^0.2.4",
"@hey-api/openapi-ts": "^0.52.11",

In my main _layout.tsx file, I define the client configuration first:

client.setConfig({
    baseUrl: process.env.EXPO_PUBLIC_API_URL
})
const intercepUnauthorized = (response) => {
    if (response.status === 401 && response.url.indexOf('update-access-token') === -1) {
        console.log('intercepUnauthorized', response);
        //refreshToken();
    }
    return response;
}

client.interceptors.response.use(intercepUnauthorized);

After that, I do a console log to check that the interceptor has been correctly created:

console.log('interceptors =>', client.interceptors.response);

The problem occurs when I modify the _layout.tsx file. Each time I modify and save it, a new interceptor is added to the client, and this keeps happening every time I modify and save the file.

As you can see in the code, I add a function so that it is referenced within the interceptors, but it still keeps adding it.

Here you have a video about this issue

Grabacion.de.pantalla.2024-09-03.a.las.13.32.43.mov

Does anyone have any idea what the problem might be?

Reproducible example or configuration

No response

OpenAPI specification (optional)

No response

System information (optional)

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🔥Broken or incorrect behavior.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions