import { Archon } from "../Archon.js";
import { Session, SessionId } from "../types/user.js";

/**
 * End the session of the user. You should redirect the user away from protected resources after calling this function.
 * @param session The session to end.
 */
export default async function endSession(session: Session | SessionId): Promise<void> {
    const request = await Archon.request(`/users/session/${typeof session === "number" ? session : session.id}`, "DELETE");

    if (request.status !== 200) {
        throw new Error(`Failed to end session: ${request.data}`);
    }

    return;
}