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>
<div class="px-3 pb-3"> <div class="px-3 pb-3">
<form action="/api/auth/logout" method="POST"> <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">
<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]" />
<Icon name="arrow-right-on-rectangle" class="w-[18px] h-[18px]" /> Logout
Logout </button>
</button>
</form>
</div> </div>
</div> </div>
</aside> </aside>
@@ -202,6 +200,13 @@ function isActive(item: { href: string; exact?: boolean }) {
document.cookie = 'currentTeamId=' + teamSwitcher.value + '; path=/'; document.cookie = 'currentTeamId=' + teamSwitcher.value + '; path=/';
window.location.reload(); 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> </script>
</body> </body>
</html> </html>

View File

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