fix(getPod): support path-based pod servers#652
fix(getPod): support path-based pod servers#652melvincarvalho wants to merge 1 commit intoSolidOS:mainfrom
Conversation
The getPod() function previously assumed subdomain-based pods by using document.location.origin. This broke path-based pod servers like JSS and CSS in path mode. Now getPod() first checks if a user is logged in and looks up their pim:storage from their profile. Falls back to origin-based detection for backwards compatibility with subdomain-based servers. Fixes: SolidOS#651
There was a problem hiding this comment.
Pull request overview
This PR fixes the getPod() function to support path-based pod servers (like JSS and CSS in path mode) by checking the logged-in user's pim:storage from their profile before falling back to origin-based detection.
Key Changes:
- Updated
getPod()to first attempt retrieving pod location from user'spim:storageproperty - Added fallback to original origin-based detection for backwards compatibility with subdomain-based servers
- Imported
authnandstorefromsolid-logicto access user profile data
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Try to get pod from logged-in user's pim:storage | ||
| const user = authn.currentUser() | ||
| if (user) { | ||
| // Look up pim:storage from user's profile | ||
| const storages = store.each(user, ns.space('storage'), null, user.doc()) | ||
| if (storages.length > 0) { | ||
| return storages[0] as NamedNode | ||
| } | ||
| } |
There was a problem hiding this comment.
The new logic for retrieving the pod from the logged-in user's pim:storage lacks test coverage. This is a critical change that introduces different behavior for path-based pod servers versus subdomain-based pod servers. Consider adding unit tests to verify:
- When a user is logged in and has pim:storage in their profile, the function returns the storage value
- When a user is logged in but has no pim:storage, the function falls back to origin-based detection
- When no user is logged in, the function falls back to origin-based detection
- When multiple storages exist, the function returns the first one
This is especially important since the function is already exported for testing (as noted in the comment on line 16).
|
@melvincarvalho
rel="type": If you perform a HEAD or GET request on a folder and see Link: http://www.w3.org/ns/pim/space#Storage; rel="type", the server is explicitly stating that this URI is the Root Storage (the top level of your Pod). rel="http://www.w3.org/ns/solid/terms#owner": This header is often found at the storage root to identify the WebID of the person who owns that storage space. |
|
Thanks for the pointer Alain! You're right that header-based discovery is also in the spec. This PR uses |
Summary
The
getPod()function previously assumed subdomain-based pods by usingdocument.location.origin. This broke path-based pod servers like JSS and CSS in path mode.Changes
Now
getPod()first checks if a user is logged in and looks up theirpim:storagefrom their profile. Falls back to origin-based detection for backwards compatibility with subdomain-based servers.The Problem
For a path-based pod server:
http://server.com/alice/profile/card#mehttp://server.com/alice/getPod()returned:http://server.com/❌getPod()returns:http://server.com/alice/✓ (from pim:storage)Testing
Tested with JSS (JavaScript Solid Server) which uses path-based pods.
Fixes: #651