Hub documentation

如何在 Spaces 中获取用户的套餐和状态

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

如何在 Spaces 中获取用户的套餐和状态

在 Space 的 iframe 内部,您可以检查用户是否已在主站登录,以及他们是否拥有 PRO 订阅,或其所属的某个组织是否拥有付费订阅。

window.addEventListener("message", (event) => {
    if (event.data.type === "USER_PLAN") {
        console.log("plan", event.data.plan);
    }
})

window.parent.postMessage({
    type: "USER_PLAN_REQUEST"
}, "https://huggingface.co");

event.data.plan 的类型为:

{
    user: "anonymous",
    org: undefined
} | {
    user: "pro" | "free",
    org: undefined | "team" | "enterprise" | "plus" | "academia"
}

您将获得用户的状态(已注销 = "anonymous")及其 plan。

示例

Update on GitHub