e621 credentials: user fields, API endpoint, Account screen

Backend:
- User model gains e621_username / e621_api_key / e621_base_url
- GET/PUT /api/auth/e621/ for the owner's credentials; /me exposes only
  the username and a configured flag, never the key

Frontend:
- e621 client core: Basic auth, _client param (browsers cannot set a
  User-Agent), serialized queue throttled to 1 request/second, readable
  error mapping
- Account screen (/account): username, API key with reveal toggle,
  base URL (e621 / e926 / custom), Save + Test connection
- Credentials are fetched from the backend and held in memory only,
  cleared on logout
This commit is contained in:
2026-09-17 08:49:00 -05:00
parent a09ab8a160
commit b6409523e6
12 changed files with 555 additions and 6 deletions
+2
View File
@@ -2,6 +2,7 @@ import { create } from "zustand";
import { api, getToken, setToken } from "@/lib/api";
import type { User } from "@/lib/types";
import { useE621 } from "@/store/e621";
interface AuthState {
user: User | null;
@@ -42,6 +43,7 @@ export const useAuth = create<AuthState>((set) => ({
// The token may already be invalid; clearing it locally is enough.
}
setToken(null);
useE621.getState().clear();
set({ user: null, ready: true });
},
+42
View File
@@ -0,0 +1,42 @@
import { create } from "zustand";
import { api } from "@/lib/api";
import type { E621Credentials } from "@/lib/e621";
interface E621State {
credentials: E621Credentials | null;
loading: boolean;
load: () => Promise<void>;
save: (values: {
username: string;
api_key: string;
base_url: string;
}) => Promise<E621Credentials>;
clear: () => void;
}
export const useE621 = create<E621State>((set) => ({
credentials: null,
loading: false,
load: async () => {
set({ loading: true });
try {
const credentials = await api<E621Credentials>("/api/auth/e621/");
set({ credentials, loading: false });
} catch {
set({ credentials: null, loading: false });
}
},
save: async (values) => {
const credentials = await api<E621Credentials>("/api/auth/e621/", {
method: "PUT",
json: values,
});
set({ credentials });
return credentials;
},
clear: () => set({ credentials: null }),
}));