@metagptx/web-sdk 0.0.7 → 0.0.8

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 +58 -0
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -39,6 +39,64 @@ The SDK provides four main modules:
39
39
 
40
40
  Handles user authentication and session management.
41
41
 
42
+ #### Authentication Callback Setup
43
+
44
+ When using this SDK, your project needs to implement an `/auth/callback` route and page. This callback page is used to handle the authentication flow after a successful login.
45
+
46
+ **Required Setup:**
47
+
48
+ 1. Create an `/auth/callback` route in your application
49
+ 2. In the callback page, read the `token` parameter from the URL query string
50
+ 3. Call `client.auth.login()` to save the token to localStorage
51
+
52
+ **Example Implementation:**
53
+
54
+ ```tsx
55
+ // In your /auth/callback page component
56
+ import { useEffect } from 'react';
57
+
58
+ function AuthCallbackPage() {
59
+ useEffect(() => {
60
+ // This will automatically read the token from URL query string
61
+ // and save it to localStorage
62
+ client.auth.login().then((token) => {
63
+ if (token) {
64
+ // Token saved successfully, redirect to your app
65
+ window.location.href = '/dashboard'; // or your desired route
66
+ } else {
67
+ // No token found, handle error
68
+ console.error('No token found in URL');
69
+ }
70
+ });
71
+ }, []);
72
+
73
+ return <div>Processing authentication...</div>;
74
+ }
75
+ ```
76
+
77
+ **How it works:**
78
+ - After successful authentication, the user will be redirected to `/auth/callback?token=xxx`
79
+ - The `auth.login()` method reads the token from the URL and stores it in localStorage
80
+ - Once the token is saved, redirect the user to your application
81
+
82
+ #### `auth.login()`
83
+
84
+ Read the token from the URL query string and save it to localStorage.
85
+
86
+ **HTTP Details:**
87
+ - **Method:** Client-side only (no HTTP request)
88
+ - **Parameters:** None (automatically reads `token` from URL query string)
89
+
90
+ **Returns:** The token value if found, or null if not found.
91
+
92
+ **Example:**
93
+ ```typescript
94
+ const token = await client.auth.login();
95
+ if (token) {
96
+ console.log('Token saved to localStorage');
97
+ }
98
+ ```
99
+
42
100
  #### `auth.me()`
43
101
 
44
102
  Get current user information.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@metagptx/web-sdk",
3
3
  "type": "module",
4
- "version": "0.0.7",
4
+ "version": "0.0.8",
5
5
  "packageManager": "pnpm@10.15.0+sha512.486ebc259d3e999a4e8691ce03b5cac4a71cbeca39372a9b762cb500cfdf0873e2cb16abe3d951b1ee2cf012503f027b98b6584e4df22524e0c7450d9ec7aa7b",
6
6
  "description": "TypeScript SDK for interacting with FuncSea API",
7
7
  "author": "MetaGPTX",