import { logoutResponse } from "./logout.js";
import { addAnonymousCookieState, getExchangeStateURL } from "../../data/index.js";
import { setAuthenticationStateCookie } from "../authentication.js";
export async function anonymousRoutes(fastify) {
    const { ALLOW_ANONYMOUS_USER } = process.env;
    if (!ALLOW_ANONYMOUS_USER)
        return;
    fastify.get("/anonymous", {
        async handler(request, response) {
            await logoutResponse(response);
            const state = await addAnonymousCookieState();
            setAuthenticationStateCookie(response, state);
            const { state: userState, redirect } = request.query;
            const exchange = await getExchangeStateURL(userState);
            const location = exchange || redirect || "/home";
            response.header("Location", location);
            response.status(302);
            response.send();
        }
    });
}
//# sourceMappingURL=anonymous.js.map