Skip to content

Bind Session.authFetch so it's safe to pass by reference (drop-in fetch) #11

Description

@melvincarvalho

Problem

Session.authFetch is the authenticated drop-in for fetch, but it's an ordinary unbound class method, so passing it by reference loses this:

const f = session.authFetch
await f(url)   // TypeError: cannot read properties of undefined (reading '_isActive')

This bites any consumer that hands the authed fetch to a library expecting a bare fetch function (rdflib Fetcher / UpdateManager, rdf-dereference, solid-logic) or destructures it:

const { authFetch } = session

Since authFetch is intended as a drop-in for fetch, the public API should support that usage.

Status

Not urgent. Current consumers either call session.authFetch(...) directly or go through a wrapper, so nothing passes the raw method by reference today. This is hardening for external consumers, not a live regression.

Fix

One line in the Session constructor, plus a test that destructures and calls it:

// Bind so authFetch survives being passed by reference (drop-in fetch)
this.authFetch = this.authFetch.bind(this)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions