import { NextApiResponse } from "next";
import { ServerResponse } from "http";
import { deleteCookie } from "../../utils/cookies-actions";
import { APIResponseObject } from "@moduletrace/datasquirel/dist/package-shared/types";
import grabCookieNames from "../../utils/grab-cookie-names";

type Params = {
    res: NextApiResponse | ServerResponse;
};

export default async function logoutUser({
    res,
}: Params): Promise<APIResponseObject> {
    const { auth_key_cookie_name, csrf_cookie_name } = grabCookieNames();

    deleteCookie(res, [
        {
            name: auth_key_cookie_name,
            options: {
                path: "/",
                domain: process.env.DOMAIN,
            },
        },
        {
            name: csrf_cookie_name,
            options: {
                path: "/",
                domain: process.env.DOMAIN,
            },
        },
    ]);

    return {
        success: true,
    };
}
