import {NextApiRequest, NextApiResponse} from "next";
import {getAuth, signOut} from "firebase/auth";
import {app} from "@/firebase";
import {sessionOptions} from "@/lib/session";
import {withIronSessionApiRoute} from "iron-session/next";

const auth = getAuth(app);

export default withIronSessionApiRoute(logout, sessionOptions);

async function logout(req: NextApiRequest, res: NextApiResponse) {
	await auth.signOut();
	req.session.destroy();
	res.status(200).json(undefined);
}
