@restorehub/widget 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +81 -48
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,42 +1,26 @@
1
1
  # @restorehub/widget
2
2
 
3
- Add Discord member verification to any website with one line of code.
3
+ Add Discord member verification to any website. One package, one function call.
4
4
 
5
- ## Quick Start
6
-
7
- ### CDN (no build step)
8
-
9
- ```html
10
- <script src="https://cdn.restorehub.net/widget.js"></script>
11
- <script>
12
- document.getElementById("verify-btn").onclick = function () {
13
- RestoreHub.verify("your-server-slug").then(function (result) {
14
- console.log("Verified!", result.user.username);
15
- // result.token — JWT to verify server-side
16
- // result.user — { id, username, avatar }
17
- });
18
- };
19
- </script>
20
- ```
21
-
22
- ### npm
5
+ ## Install
23
6
 
24
7
  ```bash
25
8
  npm install @restorehub/widget
26
9
  ```
27
10
 
11
+ ## Quick Start
12
+
28
13
  ```js
29
14
  import { verify } from "@restorehub/widget";
30
15
 
31
16
  const result = await verify("your-server-slug");
32
- console.log(result.user.username, result.token);
17
+ console.log(result.user.username); // Discord username
18
+ console.log(result.token); // signed JWT — verify on your backend
33
19
  ```
34
20
 
35
- ### React
21
+ That's it. `verify()` opens a popup where the user authenticates with Discord, verifies their identity, and returns a signed token with their info.
36
22
 
37
- ```bash
38
- npm install @restorehub/widget
39
- ```
23
+ ## React
40
24
 
41
25
  ```jsx
42
26
  import { RestoreHubButton } from "@restorehub/widget/react";
@@ -45,65 +29,114 @@ function App() {
45
29
  return (
46
30
  <RestoreHubButton
47
31
  serverSlug="your-server-slug"
48
- onSuccess={(result) => console.log("Verified!", result)}
32
+ onSuccess={(result) => {
33
+ // result.token — signed verification token
34
+ // result.user — { id, username, avatar }
35
+ fetch("/api/verify", {
36
+ method: "POST",
37
+ body: JSON.stringify({ token: result.token }),
38
+ });
39
+ }}
49
40
  onError={(err) => console.error(err)}
50
41
  />
51
42
  );
52
43
  }
53
44
  ```
54
45
 
55
- ## API
46
+ ## How It Works
47
+
48
+ 1. Your site calls `verify("your-server-slug")`
49
+ 2. A popup opens where the user authenticates with Discord
50
+ 3. Restore Hub verifies the user, assigns roles, and signs a token
51
+ 4. The token is returned to your site via `postMessage`
52
+ 5. You verify the token on your backend to confirm the user's identity
56
53
 
57
- ### `verify(serverSlug): Promise<Result>`
54
+ ## API Reference
58
55
 
59
- One-liner. Opens the verification popup and returns a promise.
56
+ ### `verify(serverSlug)`
57
+
58
+ Opens the verification popup and returns a promise with the result.
60
59
 
61
60
  ```js
62
61
  const { token, user } = await verify("my-server");
62
+ // user.id — Discord user ID
63
+ // user.username — Discord username
64
+ // user.avatar — Avatar hash (nullable)
65
+ // token — Signed JWT for server-side verification
63
66
  ```
64
67
 
65
- ### `init(options)` + `open()`
68
+ ### `init(options)` / `open()` / `destroy()`
66
69
 
67
- For more control:
70
+ For manual control over the widget lifecycle:
68
71
 
69
72
  ```js
70
73
  import { init, open, destroy } from "@restorehub/widget";
71
74
 
72
75
  init({
73
76
  serverSlug: "my-server",
74
- onSuccess: (result) => console.log(result),
75
- onError: (err) => console.error(err),
77
+ onSuccess: (result) => { /* handle success */ },
78
+ onError: (err) => { /* handle error */ },
76
79
  });
77
80
 
78
- // Call on button click
79
- open();
80
-
81
- // Clean up
82
- destroy();
81
+ document.getElementById("btn").onclick = () => open();
83
82
  ```
84
83
 
85
- ### Server-side token verification
84
+ ### Server-Side Token Verification
86
85
 
87
- Verify the JWT token on your backend:
86
+ Verify the token on your backend to confirm the user actually completed verification:
88
87
 
89
88
  ```bash
90
89
  curl -X POST https://api.restorehub.net/api/widget/token/verify \
91
90
  -H "Content-Type: application/json" \
92
- -d '{"token": "eyJ..."}'
91
+ -d '{"token": "eyJhbG..."}'
92
+ ```
93
+
94
+ Response:
95
+
96
+ ```json
97
+ {
98
+ "valid": true,
99
+ "userId": "123456789",
100
+ "username": "user",
101
+ "serverId": "abc-123",
102
+ "guildId": "987654321"
103
+ }
93
104
  ```
94
105
 
95
- ## Configuration
106
+ ## Dashboard Setup
107
+
108
+ Before using the widget, configure it in the [Restore Hub Dashboard](https://restorehub.net/dashboard):
96
109
 
97
- Configure your widget in the [Restore Hub Dashboard](https://restorehub.net/dashboard) under Server Settings > Widget:
110
+ 1. Go to **Server Settings** **Widget** tab
111
+ 2. Enable the widget
112
+ 3. Add your domain to **Allowed Origins**
113
+ 4. Customize button appearance (optional)
114
+ 5. Configure auto-pull, webhooks, and redirect URL (optional)
98
115
 
99
- - Allowed origins
100
- - Button customization
101
- - Auto-pull to Discord
102
- - Webhook notifications
103
- - Success redirect URL
116
+ Your server's **slug** (found in General settings) is what you pass to `verify()`.
117
+
118
+ ## Error Handling
119
+
120
+ ```js
121
+ try {
122
+ const result = await verify("my-server");
123
+ } catch (err) {
124
+ switch (err.code) {
125
+ case "POPUP_BLOCKED": // Browser blocked the popup
126
+ case "POPUP_CLOSED": // User closed without completing
127
+ case "VERIFICATION_FAILED": // Verification was denied
128
+ case "NETWORK_ERROR": // Connection issue
129
+ case "TIMEOUT": // 10 minute timeout
130
+ }
131
+ }
132
+ ```
104
133
 
105
134
  ## Links
106
135
 
107
- - [Documentation](https://restorehub.net/docs)
108
136
  - [Dashboard](https://restorehub.net/dashboard)
137
+ - [Documentation](https://restorehub.net/docs)
109
138
  - [Discord](https://discord.gg/restorehub)
139
+
140
+ ## License
141
+
142
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@restorehub/widget",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Embeddable Discord verification widget for Restore Hub. Add Discord SSO and member verification to any website with one line of code.",
5
5
  "main": "./dist/widget.js",
6
6
  "module": "./dist/widget.esm.js",