Add user-scoped Hermes profile access
This commit is contained in:
@@ -8,19 +8,11 @@ import { fetchAuthStatus, loginWithPassword } from "@/api/auth";
|
||||
const { t } = useI18n();
|
||||
const router = useRouter();
|
||||
|
||||
// Read token saved by main.ts (before router strips URL params)
|
||||
const urlToken = (window as any).__LOGIN_TOKEN__ || "";
|
||||
|
||||
const token = ref(urlToken);
|
||||
const username = ref("");
|
||||
const password = ref("");
|
||||
const loading = ref(false);
|
||||
const errorMsg = ref("");
|
||||
|
||||
// Login method: 'token' or 'password'
|
||||
const loginMethod = ref<"token" | "password">("token");
|
||||
const hasPasswordLogin = ref(false);
|
||||
|
||||
// If already has a key, try to go to main page
|
||||
if (hasApiKey()) {
|
||||
router.replace("/hermes/chat");
|
||||
@@ -28,58 +20,14 @@ if (hasApiKey()) {
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
const status = await fetchAuthStatus();
|
||||
hasPasswordLogin.value = status.hasPasswordLogin;
|
||||
if (status.hasPasswordLogin && !urlToken) {
|
||||
loginMethod.value = "password";
|
||||
}
|
||||
await fetchAuthStatus();
|
||||
} catch {
|
||||
// Fallback to token-only
|
||||
// Login remains available; the submit request will surface connection errors.
|
||||
}
|
||||
});
|
||||
|
||||
async function handleLogin() {
|
||||
if (loginMethod.value === "token") {
|
||||
await handleTokenLogin();
|
||||
} else {
|
||||
await handlePasswordLogin();
|
||||
}
|
||||
}
|
||||
|
||||
async function handleTokenLogin() {
|
||||
const key = token.value.trim();
|
||||
if (!key) {
|
||||
errorMsg.value = t("login.tokenRequired");
|
||||
return;
|
||||
}
|
||||
|
||||
loading.value = true;
|
||||
errorMsg.value = "";
|
||||
|
||||
try {
|
||||
const res = await fetch("/api/hermes/sessions", {
|
||||
headers: { Authorization: `Bearer ${key}` },
|
||||
});
|
||||
|
||||
if (res.status === 401) {
|
||||
errorMsg.value = t("login.invalidToken");
|
||||
loading.value = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (res.status === 429 || res.status === 503) {
|
||||
errorMsg.value = t("login.tooManyAttempts");
|
||||
loading.value = false;
|
||||
return;
|
||||
}
|
||||
|
||||
setApiKey(key);
|
||||
router.replace("/hermes/chat");
|
||||
} catch {
|
||||
errorMsg.value = t("login.connectionFailed");
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
await handlePasswordLogin();
|
||||
}
|
||||
|
||||
async function handlePasswordLogin() {
|
||||
@@ -116,49 +64,21 @@ async function handlePasswordLogin() {
|
||||
<h1 class="login-title">{{ t("login.title") }}</h1>
|
||||
<p class="login-desc">{{ t("login.description") }}</p>
|
||||
|
||||
<!-- Method toggle -->
|
||||
<div v-if="hasPasswordLogin" class="login-method-toggle">
|
||||
<button
|
||||
class="toggle-btn"
|
||||
:class="{ active: loginMethod === 'password' }"
|
||||
@click="loginMethod = 'password'"
|
||||
>{{ t("login.passwordLogin") }}</button>
|
||||
<button
|
||||
class="toggle-btn"
|
||||
:class="{ active: loginMethod === 'token' }"
|
||||
@click="loginMethod = 'token'"
|
||||
>{{ t("login.tokenLogin") }}</button>
|
||||
</div>
|
||||
|
||||
<form class="login-form" @submit.prevent="handleLogin">
|
||||
<!-- Token login -->
|
||||
<template v-if="loginMethod === 'token'">
|
||||
<input
|
||||
v-model="token"
|
||||
type="password"
|
||||
class="login-input"
|
||||
:placeholder="t('login.placeholder')"
|
||||
autofocus
|
||||
/>
|
||||
</template>
|
||||
|
||||
<!-- Password login -->
|
||||
<template v-if="loginMethod === 'password'">
|
||||
<input
|
||||
v-model="username"
|
||||
type="text"
|
||||
class="login-input"
|
||||
:placeholder="t('login.usernamePlaceholder')"
|
||||
autofocus
|
||||
/>
|
||||
<input
|
||||
v-model="password"
|
||||
type="password"
|
||||
class="login-input"
|
||||
:placeholder="t('login.passwordPlaceholder')"
|
||||
@keyup.enter="handleLogin"
|
||||
/>
|
||||
</template>
|
||||
<input
|
||||
v-model="username"
|
||||
type="text"
|
||||
class="login-input"
|
||||
:placeholder="t('login.usernamePlaceholder')"
|
||||
autofocus
|
||||
/>
|
||||
<input
|
||||
v-model="password"
|
||||
type="password"
|
||||
class="login-input"
|
||||
:placeholder="t('login.passwordPlaceholder')"
|
||||
@keyup.enter="handleLogin"
|
||||
/>
|
||||
|
||||
<div v-if="errorMsg" class="login-error">{{ errorMsg }}</div>
|
||||
<button type="submit" class="login-btn" :disabled="loading">
|
||||
@@ -212,34 +132,6 @@ async function handlePasswordLogin() {
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.login-method-toggle {
|
||||
display: flex;
|
||||
margin-bottom: 24px;
|
||||
border: 1px solid $border-color;
|
||||
border-radius: $radius-sm;
|
||||
overflow: hidden;
|
||||
|
||||
.toggle-btn {
|
||||
flex: 1;
|
||||
padding: 10px;
|
||||
border: none;
|
||||
background: transparent;
|
||||
color: $text-muted;
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
transition: all $transition-fast;
|
||||
|
||||
&.active {
|
||||
background: $text-primary;
|
||||
color: var(--text-on-accent);
|
||||
}
|
||||
|
||||
&:not(.active):hover {
|
||||
background: rgba(var(--accent-primary-rgb), 0.06);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.login-form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
@@ -49,9 +49,15 @@ const showSessions = ref(
|
||||
let mobileQuery: MediaQueryList | null = null
|
||||
const isMobile = ref(false)
|
||||
|
||||
async function handleSessionClick(sessionId: string) {
|
||||
function findHistorySession(sessionId: string): SessionSummary | undefined {
|
||||
return hermesSessions.value.find(session => session.id === sessionId)
|
||||
}
|
||||
|
||||
async function handleSessionClick(sessionId: string, profile?: string | null) {
|
||||
const summary = findHistorySession(sessionId)
|
||||
const sessionProfile = profile || summary?.profile || null
|
||||
// First, fetch the Hermes session detail
|
||||
const sessionDetail = await fetchHermesSession(sessionId)
|
||||
const sessionDetail = await fetchHermesSession(sessionId, sessionProfile)
|
||||
if (!sessionDetail) {
|
||||
message.error(t('chat.sessionNotFound'))
|
||||
return
|
||||
@@ -60,6 +66,7 @@ async function handleSessionClick(sessionId: string) {
|
||||
// Convert SessionDetail to Session format and add to chatStore
|
||||
const sessionData: Session = {
|
||||
id: sessionDetail.id,
|
||||
profile: sessionDetail.profile || sessionProfile || undefined,
|
||||
title: sessionDetail.title || '',
|
||||
source: sessionDetail.source,
|
||||
createdAt: sessionDetail.started_at * 1000,
|
||||
@@ -132,7 +139,7 @@ const collapsedGroups = ref<Set<string>>(new Set(JSON.parse(localStorage.getItem
|
||||
function sessionSummaryToSession(summary: SessionSummary): Session {
|
||||
return {
|
||||
id: summary.id,
|
||||
profile: summary.profile,
|
||||
profile: summary.profile || undefined,
|
||||
title: summary.title || '',
|
||||
source: summary.source,
|
||||
createdAt: summary.started_at * 1000,
|
||||
@@ -212,7 +219,7 @@ function toggleGroup(source: string) {
|
||||
const group = groupedSessions.value.find(g => g.source === source)
|
||||
if (group?.sessions.length) {
|
||||
// Auto-select and load first session when expanding group
|
||||
handleSessionClick(group.sessions[0].id)
|
||||
handleSessionClick(group.sessions[0].id, group.sessions[0].profile)
|
||||
}
|
||||
}
|
||||
localStorage.setItem('hermes_collapsed_groups', JSON.stringify([...collapsedGroups.value]))
|
||||
@@ -247,7 +254,7 @@ watch(hermesSessionsLoaded, (loaded) => {
|
||||
collapsedGroups.value = new Set([...collapsedGroups.value].filter(s => s !== firstCliSession.source))
|
||||
}
|
||||
// Load session details
|
||||
handleSessionClick(firstCliSession.id)
|
||||
handleSessionClick(firstCliSession.id, firstCliSession.profile)
|
||||
}
|
||||
// If no CLI session exists, don't auto-load any session
|
||||
}
|
||||
@@ -271,8 +278,10 @@ async function copySessionId(id?: string) {
|
||||
}
|
||||
}
|
||||
|
||||
async function handleDeleteSession(id: string) {
|
||||
const ok = await deleteSession(id)
|
||||
async function handleDeleteSession(id: string, profile?: string | null) {
|
||||
const summary = findHistorySession(id)
|
||||
const sessionProfile = profile || summary?.profile || null
|
||||
const ok = await deleteSession(id, sessionProfile)
|
||||
if (!ok) {
|
||||
message.error(t('common.deleteFailed'))
|
||||
return
|
||||
@@ -285,7 +294,7 @@ async function handleDeleteSession(id: string) {
|
||||
historySessionId.value = null
|
||||
historySession.value = null
|
||||
const next = historySessions.value[0]
|
||||
if (next) await handleSessionClick(next.id)
|
||||
if (next) await handleSessionClick(next.id, next.profile)
|
||||
}
|
||||
|
||||
message.success(t('chat.sessionDeleted'))
|
||||
@@ -326,8 +335,8 @@ async function handleDeleteSession(id: string) {
|
||||
:can-delete="true"
|
||||
:streaming="false"
|
||||
:show-profile="false"
|
||||
@select="handleSessionClick(s.id)"
|
||||
@delete="handleDeleteSession(s.id)"
|
||||
@select="handleSessionClick(s.id, s.profile)"
|
||||
@delete="handleDeleteSession(s.id, s.profile)"
|
||||
/>
|
||||
</template>
|
||||
|
||||
@@ -347,8 +356,8 @@ async function handleDeleteSession(id: string) {
|
||||
:can-delete="true"
|
||||
:streaming="false"
|
||||
:show-profile="false"
|
||||
@select="handleSessionClick(s.id)"
|
||||
@delete="handleDeleteSession(s.id)"
|
||||
@select="handleSessionClick(s.id, s.profile)"
|
||||
@delete="handleDeleteSession(s.id, s.profile)"
|
||||
/>
|
||||
</template>
|
||||
</template>
|
||||
|
||||
@@ -16,7 +16,7 @@ const showImportModal = ref(false)
|
||||
const renamingProfile = ref<string | null>(null)
|
||||
|
||||
onMounted(() => {
|
||||
profilesStore.fetchProfiles()
|
||||
profilesStore.fetchHermesProfiles()
|
||||
})
|
||||
|
||||
function handleCreated() {
|
||||
|
||||
@@ -15,10 +15,13 @@ import SessionSettings from "@/components/hermes/settings/SessionSettings.vue";
|
||||
import PrivacySettings from "@/components/hermes/settings/PrivacySettings.vue";
|
||||
import ModelSettings from "@/components/hermes/settings/ModelSettings.vue";
|
||||
import AccountSettings from "@/components/hermes/settings/AccountSettings.vue";
|
||||
import UserManagementSettings from "@/components/hermes/settings/UserManagementSettings.vue";
|
||||
import VoiceSettings from "@/components/hermes/settings/VoiceSettings.vue";
|
||||
import { isStoredSuperAdmin } from "@/api/client";
|
||||
|
||||
const settingsStore = useSettingsStore();
|
||||
const { t } = useI18n();
|
||||
const canManageUsers = isStoredSuperAdmin();
|
||||
|
||||
onMounted(() => {
|
||||
settingsStore.fetchSettings();
|
||||
@@ -41,6 +44,9 @@ onMounted(() => {
|
||||
<NTabPane name="account" :tab="t('settings.tabs.account')">
|
||||
<AccountSettings />
|
||||
</NTabPane>
|
||||
<NTabPane v-if="canManageUsers" name="users" :tab="t('settings.tabs.users')">
|
||||
<UserManagementSettings />
|
||||
</NTabPane>
|
||||
<NTabPane name="display" :tab="t('settings.tabs.display')">
|
||||
<DisplaySettings />
|
||||
</NTabPane>
|
||||
|
||||
Reference in New Issue
Block a user