team-monite / monite-sdk

Monite SDK: Embed invoicing and payables into your app
https://docs.monite.com
MIT License
15 stars 8 forks source link

fix(proposal): duplicated `/auth/token` requests on Supercomponents mounts 🪢 #246

Closed radist2s closed 2 months ago

radist2s commented 2 months ago

Issue When the <MoniteAPIProvider/> is included within <MoniteScopedProviders/>, a new instance of QueryClient is created each time, leading to the execution of an authorization request (/auth/token). This occurs because <MoniteScopedProviders/> directly wraps Super Components, which are unmounted and remounted whenever menu items change. As a result, multiple redundant /auth/token requests are made, causing unnecessary API calls.

Solution The <MoniteAPIProvider/> has been moved into the <MoniteContext/>. By doing so, the same QueryClient instance is reused across the application, preventing the creation of new instances and thus avoiding redundant /auth/token requests.

Additionally, for the SDK Demo, the API provider now utilizes it's own <QraftSecureRequestFn/> provider, which generates a securedRequestFn. This replaces the previous approach of using the <MoniteAPIProvider/> from the SDK React package, ensuring more tailored and secure request handling specific to the SDK Demo context.

In the current implementation, more than one request is still executed in the first mount. This is due to the simplification of authorization for SDK Demo. This problem will be fixed in the next major versions of the SDK React.

changeset-bot[bot] commented 2 months ago

🦋 Changeset detected

Latest commit: e5a612ceb31b8a3c18ec3b7efbbb0df237bdaeb9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 0 packages When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR