Fixed
All checks were successful
Docker Deploy / build-and-push (push) Successful in 4m30s

This commit is contained in:
2026-02-12 23:04:27 -07:00
parent 25c9d77599
commit 5f7b36582c
2 changed files with 13 additions and 8 deletions

View File

@@ -184,12 +184,10 @@ function isActive(item: { href: string; exact?: boolean }) {
</div>
<div class="px-3 pb-3">
<form action="/api/auth/logout" method="POST">
<button type="submit" class="btn btn-ghost btn-sm btn-block justify-start gap-2 text-base-content/60 hover:text-error hover:bg-error/10 font-medium">
<Icon name="arrow-right-on-rectangle" class="w-[18px] h-[18px]" />
Logout
</button>
</form>
<button id="logout-btn" type="button" class="btn btn-ghost btn-sm btn-block justify-start gap-2 text-base-content/60 hover:text-error hover:bg-error/10 font-medium">
<Icon name="arrow-right-on-rectangle" class="w-[18px] h-[18px]" />
Logout
</button>
</div>
</div>
</aside>
@@ -202,6 +200,13 @@ function isActive(item: { href: string; exact?: boolean }) {
document.cookie = 'currentTeamId=' + teamSwitcher.value + '; path=/';
window.location.reload();
});
// Logout - invalidate session via fetch, then redirect
const logoutBtn = document.getElementById('logout-btn');
logoutBtn?.addEventListener('click', async () => {
await fetch('/api/auth/logout', { method: 'POST' });
window.location.href = '/';
});
</script>
</body>
</html>

View File

@@ -1,11 +1,11 @@
import type { APIRoute } from 'astro';
import { invalidateSession } from '../../../lib/auth';
export const POST: APIRoute = async ({ cookies, redirect }) => {
export const POST: APIRoute = async ({ cookies }) => {
const sessionId = cookies.get('session_id')?.value;
if (sessionId) {
await invalidateSession(sessionId);
cookies.delete('session_id', { path: '/' });
}
return redirect('/login');
return new Response(null, { status: 200 });
};