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