Remove local admin reset now that AuthGuard owns that recovery flow
This project's own "break glass" admin reset never actually touched the centralized AuthGuard account - it only printed a local one-time code and, on confirm, wiped this project's local "setup completed" flag so its own setup screen reappeared, leaving the real AuthGuard account untouched and orphaned from this project's perspective. AuthGuard now has its own proper superadmin reset in its web UI, which is where this recovery path belongs going forward - having every integrated project also show a "Reset admin account" link that does something different and doesn't actually solve "I forgot my AuthGuard password" was confusing and redundant. Removes the backend reset handlers, their routes, the local ResetManager field/init, any local cleanup method that only existed to serve them, and the frontend API calls plus the onRequestReset/onConfirmReset wiring that made the shared AuthPage component's reset link appear. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ec4bdd6ac7
commit
4e39b5ac67
6 files changed
+97
-199
No files matched your search
+45
-58
@@ -1,46 +1,46 @@
|
||||
async function request(url, options) {
|
||||
const res = await fetch(url, {
|
||||
...options,
|
||||
headers: options?.body ? { 'Content-Type': 'application/json', ...options?.headers } : options?.headers,
|
||||
});
|
||||
if (!res.ok) {
|
||||
let message = `HTTP ${res.status}`;
|
||||
try {
|
||||
const body = await res.json();
|
||||
// This backend's error responses are { error: "<category>", message: "<human text>" } -
|
||||
// message is the human-readable text; error is just a category label (e.g. "Unauthorized").
|
||||
if (body?.message) message = body.message;
|
||||
else if (body?.error) message = body.error;
|
||||
} catch {
|
||||
// Response body wasn't JSON (or was empty) - keep the generic status message.
|
||||
}
|
||||
throw new Error(message);
|
||||
}
|
||||
if (res.status === 204) return undefined;
|
||||
return res.json();
|
||||
}
|
||||
|
||||
async function getJson(url) {
|
||||
return request(url);
|
||||
}
|
||||
|
||||
export async function fetchOverview() {
|
||||
return getJson('/web/data');
|
||||
}
|
||||
|
||||
export async function fetchTechStack() {
|
||||
return getJson('/api/tech-stack');
|
||||
}
|
||||
|
||||
export async function fetchHealth() {
|
||||
const res = await fetch('/health');
|
||||
return { up: res.ok };
|
||||
}
|
||||
|
||||
export async function fetchAuthStatus() {
|
||||
return getJson('/api/auth/status');
|
||||
}
|
||||
|
||||
async function request(url, options) {
|
||||
const res = await fetch(url, {
|
||||
...options,
|
||||
headers: options?.body ? { 'Content-Type': 'application/json', ...options?.headers } : options?.headers,
|
||||
});
|
||||
if (!res.ok) {
|
||||
let message = `HTTP ${res.status}`;
|
||||
try {
|
||||
const body = await res.json();
|
||||
// This backend's error responses are { error: "<category>", message: "<human text>" } -
|
||||
// message is the human-readable text; error is just a category label (e.g. "Unauthorized").
|
||||
if (body?.message) message = body.message;
|
||||
else if (body?.error) message = body.error;
|
||||
} catch {
|
||||
// Response body wasn't JSON (or was empty) - keep the generic status message.
|
||||
}
|
||||
throw new Error(message);
|
||||
}
|
||||
if (res.status === 204) return undefined;
|
||||
return res.json();
|
||||
}
|
||||
|
||||
async function getJson(url) {
|
||||
return request(url);
|
||||
}
|
||||
|
||||
export async function fetchOverview() {
|
||||
return getJson('/web/data');
|
||||
}
|
||||
|
||||
export async function fetchTechStack() {
|
||||
return getJson('/api/tech-stack');
|
||||
}
|
||||
|
||||
export async function fetchHealth() {
|
||||
const res = await fetch('/health');
|
||||
return { up: res.ok };
|
||||
}
|
||||
|
||||
export async function fetchAuthStatus() {
|
||||
return getJson('/api/auth/status');
|
||||
}
|
||||
|
||||
export async function setupAccount(username, email, password) {
|
||||
return request('/api/auth/setup', { method: 'POST', body: JSON.stringify({ username, email, password }) });
|
||||
}
|
||||
@@ -65,23 +65,10 @@ export async function disableTotp(token) {
|
||||
return request('/api/auth/totp/disable', { method: 'POST', body: JSON.stringify({ token }) });
|
||||
}
|
||||
|
||||
export async function requestAdminReset() {
|
||||
return request('/api/auth/reset/request', { method: 'POST' });
|
||||
export async function logout() {
|
||||
return request('/api/auth/logout', { method: 'POST' });
|
||||
}
|
||||
|
||||
export async function confirmAdminReset(code) {
|
||||
const result = await request('/api/auth/reset/confirm', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ code }),
|
||||
});
|
||||
window.location.reload();
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function logout() {
|
||||
return request('/api/auth/logout', { method: 'POST' });
|
||||
}
|
||||
|
||||
export async function updateCredentials({ newUsername, newEmail, newPassword }) {
|
||||
return request('/api/auth/credentials', {
|
||||
method: 'POST',
|
||||
|
||||
@@ -7,8 +7,6 @@
|
||||
|
||||
const onLogin = (input) => auth.login(input.identifier, input.password, input.totpToken);
|
||||
const onSetup = (input) => auth.setup(input.username, input.email, input.password);
|
||||
const onRequestReset = () => auth.requestAdminReset();
|
||||
const onConfirmReset = (code) => auth.confirmAdminReset(code);
|
||||
</script>
|
||||
|
||||
<SharedAuthPage
|
||||
@@ -19,6 +17,4 @@
|
||||
{error}
|
||||
{onLogin}
|
||||
{onSetup}
|
||||
{onRequestReset}
|
||||
{onConfirmReset}
|
||||
/>
|
||||
@@ -1,7 +1,6 @@
|
||||
import { createMutation, createQuery, useQueryClient } from '@tanstack/svelte-query';
|
||||
import { getContext, setContext } from 'svelte';
|
||||
import { createMutation, createQuery, useQueryClient } from '@tanstack/svelte-query';
|
||||
import { getContext, setContext } from 'svelte';
|
||||
import {
|
||||
confirmAdminReset,
|
||||
createUser,
|
||||
deleteUser,
|
||||
disableTotp,
|
||||
@@ -11,52 +10,51 @@ import {
|
||||
login,
|
||||
listUsers,
|
||||
logout,
|
||||
requestAdminReset,
|
||||
setupTotp,
|
||||
setupAccount,
|
||||
updateCredentials,
|
||||
updateUser,
|
||||
} from '$lib/api.js';
|
||||
|
||||
const AUTH_STATUS_KEY = ['AuthStatus'];
|
||||
const AUTH_CONTEXT_KEY = Symbol('auth');
|
||||
|
||||
export function createAuthStore() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
const statusQuery = createQuery(() => ({
|
||||
queryKey: AUTH_STATUS_KEY,
|
||||
queryFn: fetchAuthStatus,
|
||||
}));
|
||||
|
||||
const AUTH_STATUS_KEY = ['AuthStatus'];
|
||||
const AUTH_CONTEXT_KEY = Symbol('auth');
|
||||
|
||||
export function createAuthStore() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
const statusQuery = createQuery(() => ({
|
||||
queryKey: AUTH_STATUS_KEY,
|
||||
queryFn: fetchAuthStatus,
|
||||
}));
|
||||
const setupMutation = createMutation(() => ({
|
||||
mutationFn: ({ username, email, password }) => setupAccount(username, email, password),
|
||||
}));
|
||||
const loginMutation = createMutation(() => ({
|
||||
mutationFn: ({ identifier, password, totpToken }) => login(identifier, password, totpToken),
|
||||
}));
|
||||
const logoutMutation = createMutation(() => ({
|
||||
mutationFn: () => logout(),
|
||||
}));
|
||||
const updateCredentialsMutation = createMutation(() => ({
|
||||
mutationFn: (input) => updateCredentials(input),
|
||||
}));
|
||||
|
||||
const refresh = () => queryClient.invalidateQueries({ queryKey: AUTH_STATUS_KEY });
|
||||
|
||||
const store = {
|
||||
get status() {
|
||||
return statusQuery.data;
|
||||
},
|
||||
get loading() {
|
||||
return statusQuery.isLoading;
|
||||
},
|
||||
get error() {
|
||||
return statusQuery.error;
|
||||
},
|
||||
}));
|
||||
const logoutMutation = createMutation(() => ({
|
||||
mutationFn: () => logout(),
|
||||
}));
|
||||
const updateCredentialsMutation = createMutation(() => ({
|
||||
mutationFn: (input) => updateCredentials(input),
|
||||
}));
|
||||
|
||||
const refresh = () => queryClient.invalidateQueries({ queryKey: AUTH_STATUS_KEY });
|
||||
|
||||
const store = {
|
||||
get status() {
|
||||
return statusQuery.data;
|
||||
},
|
||||
get loading() {
|
||||
return statusQuery.isLoading;
|
||||
},
|
||||
get error() {
|
||||
return statusQuery.error;
|
||||
},
|
||||
async setup(username, email, password) {
|
||||
await setupMutation.mutateAsync({ username, email, password });
|
||||
await refresh();
|
||||
},
|
||||
await refresh();
|
||||
},
|
||||
async login(identifier, password, totpToken = '') {
|
||||
await loginMutation.mutateAsync({ identifier, password, totpToken });
|
||||
await refresh();
|
||||
@@ -76,16 +74,10 @@ export function createAuthStore() {
|
||||
await disableTotp(token);
|
||||
await refresh();
|
||||
},
|
||||
async requestAdminReset() {
|
||||
await requestAdminReset();
|
||||
async logout() {
|
||||
await logoutMutation.mutateAsync();
|
||||
await refresh();
|
||||
},
|
||||
async confirmAdminReset(code) {
|
||||
await confirmAdminReset(code);
|
||||
},
|
||||
async logout() {
|
||||
await logoutMutation.mutateAsync();
|
||||
await refresh();
|
||||
},
|
||||
async updateCredentials(input) {
|
||||
await updateCredentialsMutation.mutateAsync(input);
|
||||
await refresh();
|
||||
@@ -102,16 +94,16 @@ export function createAuthStore() {
|
||||
async deleteUser(id) {
|
||||
await deleteUser(id);
|
||||
},
|
||||
};
|
||||
|
||||
setContext(AUTH_CONTEXT_KEY, store);
|
||||
return store;
|
||||
}
|
||||
|
||||
export function useAuth() {
|
||||
const ctx = getContext(AUTH_CONTEXT_KEY);
|
||||
if (!ctx) {
|
||||
throw new Error('useAuth() must be called within the root layout that calls createAuthStore()');
|
||||
}
|
||||
return ctx;
|
||||
}
|
||||
};
|
||||
|
||||
setContext(AUTH_CONTEXT_KEY, store);
|
||||
return store;
|
||||
}
|
||||
|
||||
export function useAuth() {
|
||||
const ctx = getContext(AUTH_CONTEXT_KEY);
|
||||
if (!ctx) {
|
||||
throw new Error('useAuth() must be called within the root layout that calls createAuthStore()');
|
||||
}
|
||||
return ctx;
|
||||
}
|
||||
Reference in new issue
Block a user