"use server";

import { redirect } from "next/navigation";
import { cookies } from "next/headers";
import { createClient } from "@/lib/supabase/server";
import { env } from "@/lib/env";
import { ROUTES } from "@/lib/constants";

export async function signOutAction() {
  if (env.disableAuth) {
    const cookieStore = await cookies();
    cookieStore.delete("local_viewer_role");
    cookieStore.delete("local_viewer_scope");
    redirect(ROUTES.login);
  }

  const supabase = await createClient();
  await supabase.auth.signOut();
  redirect(ROUTES.login);
}
