Add multi-user auth, background generation, and chat UX improvements
Phase 5: Multi-user authentication with session cookies, bcrypt passwords, first-user-is-admin pattern, per-user data isolation, backup/restore, Docker Swarm production stack with secrets and network isolation. Phase 5.1: Chat UX improvements: - Background generation architecture (GenerationBuffer + asyncio task) with SSE fan-out, reconnect support, and periodic DB flushes - LLM-generated conversation titles (first exchange + every 10th message) - Stop generation button with cancel_event and partial content preservation - Relative timestamps in sidebar (5m ago, 3h ago, then dates) - Empty chat auto-cleanup on navigation away - Save-as-note uses LLM for title generation, tags notes with "chat" - Summarize-as-note also tags with "chat" Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
import { ref, computed } from "vue";
|
||||
import { defineStore } from "pinia";
|
||||
import { apiGet, apiPost } from "@/api/client";
|
||||
import type { User, AuthStatus } from "@/types/auth";
|
||||
|
||||
export const useAuthStore = defineStore("auth", () => {
|
||||
const user = ref<User | null>(null);
|
||||
const loading = ref(true);
|
||||
const hasUsers = ref(true);
|
||||
|
||||
const isAuthenticated = computed(() => user.value !== null);
|
||||
const isAdmin = computed(() => user.value?.role === "admin");
|
||||
|
||||
async function checkAuth() {
|
||||
loading.value = true;
|
||||
try {
|
||||
user.value = await apiGet<User>("/api/auth/me");
|
||||
} catch {
|
||||
user.value = null;
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function checkHasUsers() {
|
||||
try {
|
||||
const data = await apiGet<AuthStatus>("/api/auth/status");
|
||||
hasUsers.value = data.has_users;
|
||||
} catch {
|
||||
hasUsers.value = true;
|
||||
}
|
||||
}
|
||||
|
||||
async function login(username: string, password: string) {
|
||||
user.value = await apiPost<User>("/api/auth/login", { username, password });
|
||||
}
|
||||
|
||||
async function register(username: string, password: string, email?: string) {
|
||||
user.value = await apiPost<User>("/api/auth/register", {
|
||||
username,
|
||||
password,
|
||||
email: email || undefined,
|
||||
});
|
||||
}
|
||||
|
||||
async function logout() {
|
||||
await apiPost("/api/auth/logout", {});
|
||||
user.value = null;
|
||||
}
|
||||
|
||||
return {
|
||||
user,
|
||||
loading,
|
||||
hasUsers,
|
||||
isAuthenticated,
|
||||
isAdmin,
|
||||
checkAuth,
|
||||
checkHasUsers,
|
||||
login,
|
||||
register,
|
||||
logout,
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user