Skip to content

Bind Session.authFetch so it's safe to pass by reference#12

Merged
melvincarvalho merged 1 commit into
gh-pagesfrom
issue-11-bind-authfetch
Jun 18, 2026
Merged

Bind Session.authFetch so it's safe to pass by reference#12
melvincarvalho merged 1 commit into
gh-pagesfrom
issue-11-bind-authfetch

Conversation

@melvincarvalho

Copy link
Copy Markdown
Contributor

Fixes #11.

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

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

That breaks any consumer handing the authed fetch to a library expecting a bare fetch (rdflib Fetcher / UpdateManager, rdf-dereference, solid-logic) or destructuring it.

Change

One line in the Session constructor:

this.authFetch = this.authFetch.bind(this)

Plus a test in test.html that destructures authFetch and calls it with a mocked fetch, which throws pre-bind and passes post-bind.

Notes

Not a live regression for current consumers (they call session.authFetch(...) directly or go through a wrapper); this is hardening so the public API meets its drop-in-fetch contract.

authFetch is the authenticated drop-in for fetch but was an unbound class method, so passing it by reference (rdflib Fetcher, solid-logic, rdf-dereference, or destructuring) lost the this binding and threw on this._isActive. Bind it in the constructor; add a test that destructures and calls it.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens the Session public API so Session.authFetch behaves as a true drop-in fetch function even when passed by reference (e.g., via destructuring or when handed to libraries expecting a bare fetch).

Changes:

  • Bind Session.authFetch in the Session constructor to preserve this when the method is referenced standalone.
  • Add a browser test that destructures { authFetch } and verifies it can be called successfully with a mocked globalThis.fetch.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
solid-oidc.js Binds authFetch in the constructor so it remains usable when passed by reference.
test.html Adds a regression test covering destructured/by-reference usage of Session.authFetch.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@melvincarvalho melvincarvalho merged commit bc1ff75 into gh-pages Jun 18, 2026
1 check passed
@melvincarvalho melvincarvalho deleted the issue-11-bind-authfetch branch June 18, 2026 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants