Migrate CollabTable's AuthGuard proxy onto shared/backend/auth
Lint / Lint (push) Successful in 38s
Tests / Go backend (push) Successful in 1m9s
Tests / Dashboard checks (push) Successful in 1m25s
Docker / Docker Build & Push (push) Successful in 4m32s

Replaces the ~1044-line bespoke session/login/TOTP/admin-user proxy
(backend/auth.go, built directly on authclient) with
sharedauth.NewWithStore, the same shared engine GameStream and
OmniLogger already migrated onto. A tiny collabTableAuthStore adapter
delegates the local one-time setup-claim flag to the existing
collabtable_setup_state table/queries; CollabTable never had a
"require login" toggle, so LoginRequired always reports true and
SetLoginRequired is a no-op.

The local authguard_totp_cache (GetCachedTOTPEnabled/
SetCachedTOTPEnabled) is retired: the shared engine reads TOTP status
live from AuthGuard's GET /api/me. Its table is left in place, same as
the already-dormant auth_users/auth_sessions tables.

URL paths and HTTP methods are unchanged; only response shapes
changed to the shared engine's standardized ones (nested `user: {...}`,
`data: {...}` for TOTP setup/enable/disable). Updated
frontend/src/lib/api.js to translate these back into the shapes the
rest of the frontend already expects, and AppShell.svelte's
saveProfile to always send the current username/email (UpdateMe
requires a non-empty email on every call).

Known behavior differences: POST /api/auth/setup now returns 201
instead of 200; PUT/PATCH /api/auth/users/{id} now returns the updated
user instead of {"ok":true}; POST /api/auth/credentials no longer
forces re-login after a successful change (no bulk session-invalidation
call exists in the shared engine, only single-session Logout).

The separate device/sync API bearer-token scheme (requireAPIToken,
handleTokenStatus/handleTokenRegenerate) is untouched other than
resolving the caller's identity via sharedauth.UserFromContext instead
of local session lookups.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Gabriel20xxandClaude Sonnet 5 committed 2026-09-13 21:11:53 +02:00
1 parent aae8d3807d
commit 6e13364ebd
7 files changed
+300 -1230

No files matched your search

+60 -7
View File
@@ -37,42 +37,95 @@ export async function fetchHealth() {
return { up: res.ok };
}
// flattenAuthStatus adapts sharedauth.Service's Status/Signup/Login response
// shape (a nested `user: {id, email, username, role, canManageUsers,
// mfaEnabled}`, since CollabTable's AuthGuard migration onto
// shared/backend/auth) back into the flat shape this frontend already
// expects (AppShell.svelte reads status.username/.email/.setupRequired/
// .authenticated directly) - keeping the rest of the frontend from needing to
// change shape, the same translation GameStream/OmniLogger's frontends made
// for the same migration.
function flattenAuthStatus(payload) {
return {
setupRequired: payload?.setupRequired ?? false,
authenticated: payload?.authenticated ?? false,
authRequired: payload?.authRequired ?? true,
id: payload?.user?.id,
username: payload?.user?.username,
email: payload?.user?.email,
role: payload?.user?.role,
canManageUsers: payload?.user?.canManageUsers,
totpEnabled: payload?.user?.mfaEnabled,
};
}
export async function fetchAuthStatus() {
return getJson('/api/auth/status');
return flattenAuthStatus(await getJson('/api/auth/status'));
}
export async function setupAccount(username, email, password) {
return request('/api/auth/setup', { method: 'POST', body: JSON.stringify({ username, email, password }) });
const { user } = await request('/api/auth/setup', {
method: 'POST',
body: JSON.stringify({ username, email, password }),
});
return user;
}
export async function login(identifier, password, totpToken = '') {
return request('/api/auth/login', { method: 'POST', body: JSON.stringify({ identifier, password, totpToken }) });
const { user } = await request('/api/auth/login', {
method: 'POST',
body: JSON.stringify({ identifier, password, totpToken }),
});
return user;
}
export async function fetchTotpStatus() {
return request('/api/auth/totp/status');
}
// setupTotp/enableTotp/disableTotp proxy to sharedauth.Service's
// TOTPInitiate/TOTPVerify/TOTPDisable, whose response bodies nest their
// payload under a `data` key (`{"data": {...}}`) instead of the pre-migration
// flat shape - unwrapped here so TotpSettings.svelte (@gabriel20xx/web-ui),
// which reads setup.secret/setup.otpauthUrl directly, needs no changes.
export async function setupTotp() {
return request('/api/auth/totp/setup', { method: 'POST' });
const { data } = await request('/api/auth/totp/setup', { method: 'POST' });
return { secret: data.secret, otpauthUrl: data.otpauthUrl, enabled: data.enabled };
}
export async function enableTotp(token) {
return request('/api/auth/totp/enable', { method: 'POST', body: JSON.stringify({ token }) });
const { data } = await request('/api/auth/totp/enable', {
method: 'POST',
body: JSON.stringify({ token }),
});
return { enabled: data.enabled };
}
export async function disableTotp(token) {
return request('/api/auth/totp/disable', { method: 'POST', body: JSON.stringify({ token }) });
const { data } = await request('/api/auth/totp/disable', {
method: 'POST',
body: JSON.stringify({ token }),
});
return { enabled: data.enabled };
}
export async function logout() {
return request('/api/auth/logout', { method: 'POST' });
}
// updateCredentials proxies to sharedauth.Service's UpdateMe
// (POST /api/auth/credentials), which requires a valid, non-empty email on
// every call (it has no concept of "leave this field unchanged" for email the
// way CollabTable's pre-migration handler did) - newUsername/newEmail must
// always be the account's current values when the caller isn't actually
// changing them. ProfileDialog's form (@gabriel20xx/web-ui) always pre-fills
// and requires both fields, so AppShell.svelte's saveProfile always has them
// on hand. newPassword remains genuinely optional (omitted/blank leaves the
// password unchanged).
export async function updateCredentials({ newUsername, newEmail, newPassword }) {
return request('/api/auth/credentials', {
method: 'POST',
body: JSON.stringify({ newUsername, newEmail, newPassword }),
body: JSON.stringify({ username: newUsername, email: newEmail, password: newPassword }),
});
}
@@ -20,9 +20,15 @@
let credentialsOpen = $state(false);
async function saveProfile(input) {
// The backend's UpdateMe (POST /api/auth/credentials) requires a valid,
// non-empty email on every call - it has no concept of "leave this field
// unchanged" for email - so both username and email are always sent
// as-is; ProfileDialog's form always pre-fills and requires both fields,
// so they're never empty here. Only password is genuinely optional
// (blank means unchanged).
await auth.updateCredentials({
newUsername: input.username.trim() || undefined,
newEmail: input.email.trim() || undefined,
newUsername: input.username.trim(),
newEmail: input.email.trim(),
newPassword: input.password || undefined,
});
}