Skip to content

Commit 6cc1420

Browse files
committed
docs about getting user plan in spaces
1 parent 58ec3a2 commit 6cc1420

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

docs/hub/_toctree.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,8 @@
378378
title: Cookie limitations in Spaces
379379
- local: spaces-handle-url-parameters
380380
title: Set URL query and hash
381+
- local: spaces-get-user-plan
382+
title: Get User Plan
381383

382384
- local: other
383385
title: Other

docs/hub/spaces-get-user-status.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# How to get a user's status in Spaces
2+
3+
You can check if a user is logged in or not on the main site, and if they have a PRO subscription or one of their orgs has a paid subscription.
4+
5+
```js
6+
window.addEventListener("message", (event) => {
7+
if (event.data.type === "USER_PLAN") {
8+
console.log("plan", event.data.plan);
9+
}
10+
})
11+
12+
window.parent.postMessage({
13+
type: "USER_PLAN_REQUEST"
14+
}, "https://huggingface.co");
15+
```
16+
17+
`event.data.plan` will be of type:
18+
19+
```ts
20+
{
21+
user: "anonymoous",
22+
org: undefined
23+
} | {
24+
user: "pro" | "free",
25+
org: undefined | "team" | "enterprise" | "plus" | "academia"
26+
}
27+
```
28+
29+
You will get both the user's status (logged-out = `"anonymous"`) and their <a href="https://huggingface.co/pricing">plan</a>.

0 commit comments

Comments
 (0)