Skip to content

Commit b4bbe46

Browse files
coyotte508julien-c
andauthored
docs about getting user plan in spaces (#1978)
* docs about getting user plan in spaces * add link to space * link * Update docs/hub/spaces-get-user-status.md Co-authored-by: Julien Chaumond <[email protected]> * rename * proof-read* --------- Co-authored-by: Julien Chaumond <[email protected]>
1 parent f80b8c8 commit b4bbe46

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-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 and Status
381383

382384
- local: other
383385
title: Other

docs/hub/spaces-advanced.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@
1010
- [How to Add a Space to ArXiv](./spaces-add-to-arxiv)
1111
- [Cookie limitations in Spaces](./spaces-cookie-limitations)
1212
- [How to handle URL parameters in Spaces](./spaces-handle-url-parameters)
13+
- [How to get user status and plan in Spaces](./spaces-get-user-plan)

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# How to get a user's plan and status in Spaces
2+
3+
From inside a Space's iframe, you can check if a user is logged in or not on the main site, and if they have a PRO subscription or if 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: "anonymous",
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>.
30+
31+
## Examples
32+
33+
- https://huggingface.co/spaces/huggingfacejs/plan

0 commit comments

Comments
 (0)