a tool for shared writing and social publishing
1import { NextRequest } from "next/server";
2import { supabaseServerClient } from "supabase/serverClient";
3export const runtime = "edge";
4export const preferredRegion = [];
5export const dynamic = "force-dynamic";
6
7export async function GET(req: NextRequest) {
8 const host = req.headers.get("host");
9 const response = new Response("Logged out successfully", {
10 status: 200,
11 headers: {
12 "Content-Type": "text/plain",
13 },
14 });
15
16 // Get the base domain from the host
17 const domain = host?.includes(":") ? host.split(":")[0] : host;
18 let token = req.cookies.get("auth_token");
19 if (token)
20 supabaseServerClient.from("email_auth_tokens").delete().eq("id", token);
21
22 // Clear the auth_token cookie on both the base domain and the domain with a leading dot
23 response.headers.append(
24 "Set-Cookie",
25 `auth_token=; Path=/; Domain=${domain}; Max-Age=0; HttpOnly; Secure; SameSite=Strict`,
26 );
27 response.headers.append(
28 "Set-Cookie",
29 `auth_token=; Path=/; Domain=.${domain}; Max-Age=0; HttpOnly; Secure; SameSite=Strict`,
30 );
31
32 return response;
33}