feat: add alsoKnownAs field to federation settings

This commit is contained in:
2026-05-28 02:01:56 +02:00
parent 2445cad1c9
commit 84c66dd461
3 changed files with 67 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
import { cookies } from "next/headers";
import { redirect } from "next/navigation";
import { FederationPanel } from "@/components/federation/federation-panel";
import { MigrationSettings } from "@/components/federation/migration-settings";
export default async function FederationSettingsPage() {
const token = (await cookies()).get("auth_token")?.value;
@@ -18,6 +19,7 @@ export default async function FederationSettingsPage() {
</p>
</div>
<FederationPanel />
<MigrationSettings />
</div>
);
}

View File

@@ -0,0 +1,57 @@
"use client";
import { useState } from "react";
import { setAlsoKnownAs } from "@/lib/api";
import { useAuth } from "@/hooks/use-auth";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { toast } from "sonner";
export function MigrationSettings() {
const { token } = useAuth();
const [value, setValue] = useState("");
const [saving, setSaving] = useState(false);
const handleSave = async () => {
if (!token) return;
setSaving(true);
try {
await setAlsoKnownAs(value.trim() || null, token);
toast.success(value.trim() ? "Also known as saved." : "Also known as cleared.");
} catch {
toast.error("Failed to save.");
} finally {
setSaving(false);
}
};
return (
<div className="glass-effect glossy-effect bottom rounded-md shadow-fa-lg p-4 space-y-3">
<div>
<h3 className="text-lg font-medium">Account migration</h3>
<p className="text-sm text-muted-foreground">
Set your new actor URL before broadcasting a Move. This lets remote
servers verify the migration is legitimate.
</p>
</div>
<div className="space-y-1">
<label className="text-sm font-medium">Also known as</label>
<p className="text-xs text-muted-foreground">
The full actor URL on your new server, e.g.{" "}
<code className="font-mono">https://newdomain.com/users/&lt;uuid&gt;</code>
</p>
<div className="flex gap-2">
<Input
value={value}
onChange={(e) => setValue(e.target.value)}
placeholder="https://newdomain.com/users/…"
className="font-mono text-sm"
/>
<Button onClick={handleSave} disabled={saving} size="sm">
{saving ? "Saving…" : "Save"}
</Button>
</div>
</div>
</div>
);
}

View File

@@ -487,3 +487,11 @@ export const unfollowRemoteActor = (handle: string, token: string) =>
z.null(),
token
);
export const setAlsoKnownAs = (value: string | null, token: string) =>
apiFetch(
"/federation/me/also-known-as",
{ method: "PATCH", body: JSON.stringify({ also_known_as: value || null }) },
z.null(),
token
);