Fix token UI to use SDK rest client (sw.api.get/post/del)
All checks were successful
CI/CD / detect-changes (pull_request) Successful in 4s
CI/CD / test-runners (pull_request) Has been skipped
CI/CD / e2e-smoke (pull_request) Has been skipped
CI/CD / test-frontend (pull_request) Successful in 6s
CI/CD / test-go-pg (pull_request) Successful in 2m42s
CI/CD / test-sqlite (pull_request) Successful in 3m5s
CI/CD / build-and-deploy (pull_request) Successful in 1m10s

The frontend SDK doesn't expose sw.api.fetch — use sw.api.get(),
sw.api.post(), sw.api.del() with full /api/v1/ paths instead.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-02 18:25:59 +00:00
parent f32eefab14
commit a441f206e3
2 changed files with 6 additions and 6 deletions

View File

@@ -91,7 +91,7 @@ export default function UsersSection() {
const name = await sw.prompt(`Token name for "${username}":`, ''); const name = await sw.prompt(`Token name for "${username}":`, '');
if (!name) return; if (!name) return;
try { try {
const resp = await sw.api.fetch('POST', '/admin/tokens', { const resp = await sw.api.post('/api/v1/admin/tokens', {
user_id: userId, name, permissions: [], user_id: userId, name, permissions: [],
}); });
await sw.alert(`Token created for ${username}. Copy it now — it won't be shown again:\n\n${resp.token}`); await sw.alert(`Token created for ${username}. Copy it now — it won't be shown again:\n\n${resp.token}`);

View File

@@ -20,8 +20,8 @@ export function TokensSection() {
const load = useCallback(async () => { const load = useCallback(async () => {
try { try {
const resp = await sw.api.fetch('GET', '/auth/tokens'); const resp = await sw.api.get('/api/v1/auth/tokens');
setTokens(resp?.data || []); setTokens(resp || []);
} catch (e) { } catch (e) {
setTokens([]); setTokens([]);
} }
@@ -29,7 +29,7 @@ export function TokensSection() {
const loadPerms = useCallback(async () => { const loadPerms = useCallback(async () => {
try { try {
const resp = await sw.api.fetch('GET', '/profile/permissions'); const resp = await sw.api.get('/api/v1/profile/permissions');
setAvailablePerms(resp?.permissions || []); setAvailablePerms(resp?.permissions || []);
} catch (_) {} } catch (_) {}
}, []); }, []);
@@ -65,7 +65,7 @@ export function TokensSection() {
try { try {
const body = { name: form.name, permissions: form.permissions }; const body = { name: form.name, permissions: form.permissions };
if (form.expires_at) body.expires_at = new Date(form.expires_at).toISOString(); if (form.expires_at) body.expires_at = new Date(form.expires_at).toISOString();
const resp = await sw.api.fetch('POST', '/auth/tokens', body); const resp = await sw.api.post('/api/v1/auth/tokens', body);
setCreatedToken(resp.token); setCreatedToken(resp.token);
setShowForm(false); setShowForm(false);
load(); load();
@@ -80,7 +80,7 @@ export function TokensSection() {
const revoke = useCallback(async (id, name) => { const revoke = useCallback(async (id, name) => {
if (!await sw.confirm(`Revoke token "${esc(name)}"? This action cannot be undone.`)) return; if (!await sw.confirm(`Revoke token "${esc(name)}"? This action cannot be undone.`)) return;
try { try {
await sw.api.fetch('DELETE', `/auth/tokens/${id}`); await sw.api.del(`/api/v1/auth/tokens/${id}`);
sw.emit('toast', { message: 'Token revoked', variant: 'success' }); sw.emit('toast', { message: 'Token revoked', variant: 'success' });
load(); load();
} catch (e) { } catch (e) {