route.js 649 B

123456789101112131415161718192021222324252627282930
  1. // app/api/auth/logout/route.js
  2. import { destroySession } from "@/lib/auth/session";
  3. /**
  4. * GET /api/auth/logout
  5. *
  6. * Destroys the current session by clearing the auth cookie.
  7. * Always returns { ok: true } on success.
  8. */
  9. export async function GET() {
  10. try {
  11. await destroySession();
  12. return new Response(JSON.stringify({ ok: true }), {
  13. status: 200,
  14. headers: {
  15. "Content-Type": "application/json",
  16. },
  17. });
  18. } catch (error) {
  19. console.error("Logout error:", error);
  20. return new Response(JSON.stringify({ error: "Internal server error" }), {
  21. status: 500,
  22. headers: {
  23. "Content-Type": "application/json",
  24. },
  25. });
  26. }
  27. }