# Spaces에서 사용자의 플랜과 상태를 가져오는 방법

Space의 iframe 내부에서 사용자가 메인 사이트에 로그인되어 있는지, PRO 구독을 보유하고 있는지, 또는 해당 사용자의 조직 중 하나가 유료 구독을 보유하고 있는지 확인할 수 있습니다.

```js
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`의 타입은 다음과 같습니다:

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

사용자의 상태(로그아웃 = `"anonymous"`)와 플랜을 모두 가져옵니다.

## 예시

- https://huggingface.co/spaces/huggingfacejs/plan

