fix: add logout endpoint and session cleanup

This commit is contained in:
2026-04-03 01:38:15 +03:00
parent 1e6f200433
commit 56aa822730
5 changed files with 58 additions and 3 deletions

View File

@@ -1,3 +1,4 @@
import { useMutation } from '@tanstack/react-query'
import {
ArrowLeft,
ArrowRight,
@@ -19,6 +20,7 @@ import { CommandPalette } from '@/components/command-palette'
import { FullPlayer } from '@/components/full-player'
import { PlayerBar } from '@/components/player-bar'
import { SettingsModal } from '@/components/settings-modal'
import { logout } from '@/lib/api'
import { usePlayerStore } from '@/stores/player-store'
import { useSessionStore } from '@/stores/session-store'
@@ -42,6 +44,13 @@ export function AppShell({ children }: { children: React.ReactNode }) {
const [settingsOpen, setSettingsOpen] = useState(false)
const [userMenuOpen, setUserMenuOpen] = useState(false)
const [paletteOpen, setPaletteOpen] = useState(false)
const logoutMutation = useMutation({
mutationFn: logout,
onSettled: () => {
clearSession()
setUserMenuOpen(false)
},
})
useEffect(() => {
function onKeyDown(event: KeyboardEvent) {
@@ -99,7 +108,7 @@ export function AppShell({ children }: { children: React.ReactNode }) {
</button>
<button
className="flex w-full items-center justify-between border-t border-[#24314f] px-4 py-3 text-left text-sm text-slate-100 hover:bg-[#18233a]"
onClick={clearSession}
onClick={() => logoutMutation.mutate()}
type="button"
>
Выйти из аккаунта

View File

@@ -116,6 +116,12 @@ export async function login(username: string, password: string) {
})
}
export async function logout() {
return request<{ status: string }>('/api/auth/logout', {
method: 'POST',
})
}
export async function fetchHome() {
return request<HomePayload>('/api/home')
}

View File

@@ -92,7 +92,7 @@ export function LoginPage() {
{mutation.isError ? (
<div className="rounded-2xl border border-red-400/30 bg-red-500/10 px-4 py-3 text-sm text-red-200">
Could not reach the backend. Make sure the API is running on `http://localhost:4040`.
Could not reach the backend. Make sure the API is running on the same origin, or on `http://localhost:5050` in dev.
</div>
) : null}
</form>
@@ -111,4 +111,3 @@ function InfoCard({ label, value }: { label: string; value: string }) {
</div>
)
}