# Agent-JS 0.14.0 - AssetManager & Retry logic

**URL:** <https://forum.dfinity.org/t/agent-js-0-14-0-assetmanager-retry-logic/15782>\
**Category:** JavaScript\
**Created:** [October 6, 2022, 11:35pm UTC](https://forum.dfinity.org/t/agent-js-0-14-0-assetmanager-retry-logic/15782 "2022-10-06T23:35:05Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon74414410](https://avatars.discourse-cdn.com/v4/letter/a/85f322/32.png) [@anon74414410](https://forum.dfinity.org/u/anon74414410)\
**Post date:** [October 6, 2022, 11:35pm UTC](https://forum.dfinity.org/t/agent-js-0-14-0-assetmanager-retry-logic/15782/1 "2022-10-06T23:35:05Z")

</div>

Agent-JS 0.14.0 is released today. Prominent features include a new package, [@dfinity/assets](https://www.npmjs.com/package/@dfinity/assets), automatic retries for failed calls, a new `Agent.fetchCandid()` interface, and a `Agent.syncTime()` interface in case a device is out of sync with the replica.

- feat: expose storage constant keys by [@peterpeterparker](https://github.com/peterpeterparker) in [#616](https://github.com/dfinity/agent-js/pull/616)
- fix: return after resolve to avoid idb to be recreated by [@peterpeterparker](https://github.com/peterpeterparker) in [#617](https://github.com/dfinity/agent-js/pull/617)
- fix: optional fields not populated if wire type has additional fields by [@hpeebles](https://github.com/hpeebles) in [#627](https://github.com/dfinity/agent-js/pull/627)
- feat: http-agent retries calls by [@krpeacock](https://github.com/krpeacock) in [#632](https://github.com/dfinity/agent-js/pull/632)
- feat: Add fetchCandid() function to @dfinity/agent by [@rvanasa](https://github.com/rvanasa) in [#630](https://github.com/dfinity/agent-js/pull/630)
- fix: time tests only use faketimers once by [@krpeacock](https://github.com/krpeacock) in [#634](https://github.com/dfinity/agent-js/pull/634)
- feat: AgentJs Candid Pinpointed Type Errors upgrade - PR by [@infu](https://github.com/infu) in [#633](https://github.com/dfinity/agent-js/pull/633)
- feat: add AssetManager by [@sea-snake](https://github.com/sea-snake) in [#603](https://github.com/dfinity/agent-js/pull/603)
- fix: retry times by [@sea-snake](https://github.com/sea-snake) in [#638](https://github.com/dfinity/agent-js/pull/638)
- feat: Asset manager performance by [@sea-snake](https://github.com/sea-snake) in [#639](https://github.com/dfinity/agent-js/pull/639)
- chore: release v0.14.0 by [@krpeacock](https://github.com/krpeacock) in [#640](https://github.com/dfinity/agent-js/pull/640)

Release is visible here: [Release v0.14.0 · dfinity/agent-js · GitHub](https://github.com/dfinity/agent-js/releases/tag/v0.14.0)  
Changelog is available at [https://agent-js.icp.xyz/changelog.html](https://agent-js.icp.xyz/changelog.html)

---

<div class="post-metadata">

**Author:** ![infu](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/infu/32/11321_2.png) [@infu](https://forum.dfinity.org/u/infu)\
**Post date:** [February 10, 2023, 2:24pm UTC](https://forum.dfinity.org/t/agent-js-0-14-0-assetmanager-retry-logic/15782/2 "2023-02-10T14:24:17Z")

</div>

For anyone upgrading from auth-client@0.12, there is a breaking change.

@0.12 this worked and opened Internet Identity popup window on mobile browsers:

```auto
// onClick triggered function
let client = await AuthClient.create(...)
client.login(...)

```

After @0.12 you have to create the AuthClient prior/outside of the function calling `client.login`  
I suppose the new `create` function loses the `user initiated event flag` and gets your popups blocked.

Just leaving this so others can find the solution faster.

---

<div class="post-metadata">

**Author:** ![icme](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/icme/32/4327_2.png) [@icme](https://forum.dfinity.org/u/icme)\
**Post date:** [February 11, 2023, 9:37am UTC](https://forum.dfinity.org/t/agent-js-0-14-0-assetmanager-retry-logic/15782/3 "2023-02-11T09:37:43Z")

</div>

@anon74414410 Just ran into this same issue. Confirming that @infu’s fix solves the problem (but it’s not pretty).

As a temporary workaround/hack I’m pre-initializing the `AuthClient` before any login attempt, and then reinitializing it on logout/disconnect.

---

<div class="post-metadata">

**Author:** ![anon74414410](https://avatars.discourse-cdn.com/v4/letter/a/85f322/32.png) [@anon74414410](https://forum.dfinity.org/u/anon74414410)\
**Post date:** [February 13, 2023, 5:31pm UTC](https://forum.dfinity.org/t/agent-js-0-14-0-assetmanager-retry-logic/15782/4 "2023-02-13T17:31:58Z")

</div>

The authClient is designed to load any stored identity from storage automatically, so it was designed with the pattern in mind where you just spin it up at page load. It’s not so much a hack as the intended design.

The issue with the added asynchronicity (which was always accounted for in the design) came when we started using IndexedDb in order to securely store ECDSAKeyIdentities using the CryptoKey built-in, which allows your base key to be non-exportable.

It would be possible to offer a more functional approach though - a `import {login} from @dfinity/auth-client` method that doesn’t worry about loading stored identities, and you could just handle storage / persistence on your own

---

<div class="post-metadata">

**Author:** ![jorgenbuilder](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/jorgenbuilder/32/22166_2.png) [@jorgenbuilder](https://forum.dfinity.org/u/jorgenbuilder)\
**Post date:** [February 20, 2023, 7:44pm UTC](https://forum.dfinity.org/t/agent-js-0-14-0-assetmanager-retry-logic/15782/5 "2023-02-20T19:44:50Z")

</div>

> [@anon74414410](#):
>
> The authClient is designed to load any stored identity from storage automatically, so it was designed with the pattern in mind where you just spin it up at page load. It’s not so much a hack as the intended design.

I bumped into this today and I have to disagree with @icme, I think the pattern feels very good!

Though I am wondering if there’s a baked-in pattern for catching a `400: delegation expired` and kicking off an event from then `AuthClient` so that this case can be gracefully handled in a UI. 🤔

---

<div class="post-metadata">

**Author:** ![anon74414410](https://avatars.discourse-cdn.com/v4/letter/a/85f322/32.png) [@anon74414410](https://forum.dfinity.org/u/anon74414410)\
**Post date:** [February 21, 2023, 5:44pm UTC](https://forum.dfinity.org/t/agent-js-0-14-0-assetmanager-retry-logic/15782/6 "2023-02-21T17:44:35Z")

</div>

The current mechanism is that we check during `create` to check if the delegation is expired during start up. If we get it wrong locally, or if the delegation expires during the lifecycle of the page, we don’t have that logic baked in.

We could probably offer an `onExpiration` callback, and trigger it at the point we’d expect the delegation to expire. Unfortunately, the AuthClient doesn’t have access to the calls, since it passes an Identity that is used by an Agent, used by an Actor.

I had a design at one point where you could register actors with the AuthClient, so they could be invalidated by the IdleManager, and that would support this kind of flow, but I wasn’t happy with the interface or the complexity it added

I think it would be better to expose some new specialized error handling API’s to the HTTPAgent and encourage people to register them
