@oxyhq/auth 2.0.0 → 2.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.
- package/README.md +36 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -28,6 +28,7 @@ npm install @oxyhq/auth
|
|
|
28
28
|
- **Query hooks** — useCurrentUser, useUserProfile, usePrivacySettings, useSecurityActivity, and more
|
|
29
29
|
- **Mutation hooks** — useUpdateProfile, useUploadAvatar, useSwitchSession, useLogoutSession, and more
|
|
30
30
|
- **Stores** — authStore, assetStore, accountStore, followStore (zustand)
|
|
31
|
+
- **useSessionSocket** — zero-config real-time session sync via WebSocket
|
|
31
32
|
- **Session management utilities**
|
|
32
33
|
|
|
33
34
|
## Usage
|
|
@@ -54,3 +55,38 @@ function YourApp() {
|
|
|
54
55
|
return <p>Welcome, {user?.name}</p>;
|
|
55
56
|
}
|
|
56
57
|
```
|
|
58
|
+
|
|
59
|
+
## Real-time Session Sync
|
|
60
|
+
|
|
61
|
+
`useSessionSocket` connects a WebSocket to the API and listens for session events (remote sign-out, device removal, etc.). It requires **zero configuration** — all auth state is pulled from `WebOxyProvider` context automatically.
|
|
62
|
+
|
|
63
|
+
```tsx
|
|
64
|
+
import { useSessionSocket } from '@oxyhq/auth';
|
|
65
|
+
|
|
66
|
+
function App() {
|
|
67
|
+
// Zero-config — just call it
|
|
68
|
+
useSessionSocket();
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Optional callbacks for custom handling:
|
|
73
|
+
|
|
74
|
+
```tsx
|
|
75
|
+
useSessionSocket({
|
|
76
|
+
onRemoteSignOut: () => router.push('/login'),
|
|
77
|
+
onSessionRemoved: (sessionId) => console.log('Session removed:', sessionId),
|
|
78
|
+
});
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Migration from v1.x
|
|
82
|
+
|
|
83
|
+
v1.x required passing 8+ props manually. In v2.0 all state is derived from context:
|
|
84
|
+
|
|
85
|
+
```diff
|
|
86
|
+
- useSessionSocket({
|
|
87
|
+
- userId, activeSessionId, currentDeviceId,
|
|
88
|
+
- refreshSessions, logout, clearSessionState,
|
|
89
|
+
- baseURL, getAccessToken,
|
|
90
|
+
- });
|
|
91
|
+
+ useSessionSocket();
|
|
92
|
+
```
|
package/package.json
CHANGED