Bind Session.authFetch so it's safe to pass by reference#12
Merged
Conversation
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.
There was a problem hiding this comment.
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.authFetchin theSessionconstructor to preservethiswhen the method is referenced standalone. - Add a browser test that destructures
{ authFetch }and verifies it can be called successfully with a mockedglobalThis.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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #11.
Session.authFetchis the authenticated drop-in forfetch, but it was an ordinary unbound class method, so passing it by reference lostthis:That breaks any consumer handing the authed fetch to a library expecting a bare
fetch(rdflibFetcher/UpdateManager, rdf-dereference, solid-logic) or destructuring it.Change
One line in the
Sessionconstructor:Plus a test in
test.htmlthat destructuresauthFetchand calls it with a mockedfetch, 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-fetchcontract.