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")と、そのユーザーのプランの両方が取得されます。

例

Update on GitHub