@emblemvault/emblem-auth-react 2.0.4 → 2.1.0
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.
- package/README.md +27 -4
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -92,15 +92,38 @@ const {
|
|
|
92
92
|
|
|
93
93
|
### useEmblemAuthOptional
|
|
94
94
|
|
|
95
|
-
Same as `useEmblemAuth` but returns `null` when used outside
|
|
95
|
+
Same as `useEmblemAuth` but returns `null` when used outside `EmblemAuthProvider` instead of throwing an error.
|
|
96
|
+
|
|
97
|
+
**When to use:**
|
|
98
|
+
- Components that may render with or without auth context
|
|
99
|
+
- Libraries/packages that support multiple authentication strategies (e.g., user login OR API key)
|
|
100
|
+
- Shared components used across apps with different auth setups
|
|
96
101
|
|
|
97
102
|
```tsx
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
103
|
+
import { useEmblemAuthOptional } from '@emblemvault/emblem-auth-react';
|
|
104
|
+
|
|
105
|
+
function MyComponent() {
|
|
106
|
+
const auth = useEmblemAuthOptional();
|
|
107
|
+
|
|
108
|
+
// Gracefully handle missing provider
|
|
109
|
+
if (!auth) {
|
|
110
|
+
return <p>Auth provider not available</p>;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (!auth.isAuthenticated) {
|
|
114
|
+
return <button onClick={auth.openAuthModal}>Connect</button>;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return <p>Connected: {auth.walletAddress}</p>;
|
|
101
118
|
}
|
|
102
119
|
```
|
|
103
120
|
|
|
121
|
+
**Comparison:**
|
|
122
|
+
| Hook | Outside Provider |
|
|
123
|
+
|------|------------------|
|
|
124
|
+
| `useEmblemAuth()` | Throws error |
|
|
125
|
+
| `useEmblemAuthOptional()` | Returns `null` |
|
|
126
|
+
|
|
104
127
|
### ConnectButton
|
|
105
128
|
|
|
106
129
|
Pre-styled connect/disconnect button.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@emblemvault/emblem-auth-react",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -68,6 +68,6 @@
|
|
|
68
68
|
],
|
|
69
69
|
"license": "MIT",
|
|
70
70
|
"dependencies": {
|
|
71
|
-
"@emblemvault/auth-sdk": "^2.0
|
|
71
|
+
"@emblemvault/auth-sdk": "^2.1.0"
|
|
72
72
|
}
|
|
73
73
|
}
|