Extract a typed repository interface (adapters/repo.ts) from the scattered store/view -> api.* calls, backed by adapters/rest.ts (verbatim HTTP mapping) and selected through adapters/index.ts. Every store and the notes-facing views now depend on `repo`, never the HTTP client directly -- the seam the offline local source (M10.5, over Tauri invoke) plugs into next. Behavior-preserving for web: rest.ts maps each semantic method to the exact endpoint the code called before; query-string and multipart building moved out of the stores/views into rest.ts (the one place that knows the URL shape). Client-side logic (reconcile/sort/optimistic reorder/toasts) stays in the stores. GraphView + admin SettingsView keep direct api calls -- out of the offline-core scope (M10.5 is board/editor/capture/search/filter/labels/ checklists/reminders). Task 1992. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FRgehjoz7Yv8LkUfADxACm
43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
import { defineStore } from "pinia";
|
|
import { ref } from "vue";
|
|
import { repo } from "../adapters";
|
|
|
|
export interface User {
|
|
id: string;
|
|
email: string;
|
|
display_name: string;
|
|
email_verified: boolean;
|
|
is_admin: boolean;
|
|
}
|
|
|
|
export const useSessionStore = defineStore("session", () => {
|
|
const user = ref<User | null>(null);
|
|
// Whether we've resolved the initial /me check yet (guards against redirect flashes).
|
|
const loaded = ref(false);
|
|
|
|
async function fetchMe(): Promise<void> {
|
|
try {
|
|
user.value = await repo.auth.me();
|
|
} catch {
|
|
user.value = null;
|
|
} finally {
|
|
loaded.value = true;
|
|
}
|
|
}
|
|
|
|
async function login(email: string, password: string): Promise<void> {
|
|
user.value = await repo.auth.login(email, password);
|
|
}
|
|
|
|
async function register(email: string, password: string, displayName: string): Promise<void> {
|
|
user.value = await repo.auth.register(email, password, displayName);
|
|
}
|
|
|
|
async function logout(): Promise<void> {
|
|
await repo.auth.logout();
|
|
user.value = null;
|
|
}
|
|
|
|
return { user, loaded, fetchMe, login, register, logout };
|
|
});
|