This commit is contained in:
@@ -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">
|
||||
<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>
|
||||
</form>
|
||||
</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>
|
||||
|
||||
@@ -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 });
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user