v4: a remote account's links to its home lead to the home's pages — the settings' "Change it on <host>" button and the profile's "Account on <host>" link went to the host in the handle, which is the home's issuer, its API, not necessarily where its pages are: in development musique's button led to localhost:8000/settings, gerbeur's API, which served a stale build, instead of localhost:3000/settings. GET /api/users/:key/home?path= now redirects to a page of a remote user's home, their profile there by default, at the origin of the home's authorization_endpoint, which its metadata gives (homePageUrl in federation-service.ts), the issuer standing in while the home doesn't answer; a local user 404s, and a path that isn't one 400s. homeUrl links to it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
khannurien
2026-10-09 21:06:14 +00:00
parent 5f2fb4479a
commit 8bcc005140
5 changed files with 90 additions and 9 deletions

View File

@@ -7,8 +7,8 @@
* @module
*/
import { API_URL } from "../../config/api.ts";
import { splitHandle } from "../../../shared/validation.ts";
import { userPath } from "../../../shared/paths.ts";
/**
* Returns the host of `handle`'s home instance, or undefined for a local
@@ -19,12 +19,13 @@ export function homeHost(handle: string): string | undefined {
}
/**
* Returns the URL of `path` on `handle`'s home instance, their profile there
* by default, or null for a local user. Instances speak the same protocol as
* this page, https outside development.
* Returns a link to `path` on `handle`'s home instance, their profile there
* by default, or null for a local user. The host in a handle is the home's
* API, not necessarily its pages, so the link goes through
* `GET /api/users/:key/home`, which redirects to them.
*/
export function homeUrl(handle: string, path?: string): string | null {
const { name, host } = splitHandle(handle);
if (!host) return null;
return `${globalThis.location.protocol}//${host}${path ?? userPath(name)}`;
if (!homeHost(handle)) return null;
const query = path ? `?path=${encodeURIComponent(path)}` : "";
return `${API_URL}/api/users/@${encodeURIComponent(handle)}/home${query}`;
}