@oasisprotocol/privana-sdk 0.5.2 → 0.5.3

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 CHANGED
@@ -117,6 +117,40 @@ The hooks cache the returned `X-SIWE-Token`, dedupe concurrent auth so a group o
117
117
  private-read hooks only triggers one sign prompt, and retry once on `401` by re-authenticating
118
118
  through the same shared in-flight auth request.
119
119
 
120
+ ### Direct in-app SIWE auth (`siweAuth`)
121
+
122
+ For same-origin apps that want an explicit authenticated session (and JWT-authenticated writes),
123
+ enable `siweAuth` on `PrivanaProvider`. The connected wallet signs an EIP-4361 message in-app and
124
+ `useSiweAuth()` exposes `login`, `logout`, `session`, and the raw `tokens`:
125
+
126
+ ```tsx
127
+ import { PrivanaProvider, useSiweAuth } from '@oasisprotocol/privana-sdk'
128
+ ;<PrivanaProvider siweAuth={{ autoLogin: true }}>
129
+ <AuthGate />
130
+ </PrivanaProvider>
131
+ ```
132
+
133
+ `siweAuth` accepts `true`, or an object with `autoLogin` (default `true`) and `persistJwt`
134
+ (default `false`). It is mutually exclusive with `hostedAuth`.
135
+
136
+ #### Persistent JWT sessions (`persistJwt`)
137
+
138
+ Set `persistJwt: true` to mirror the session in `localStorage` (key scoped by API URL and chain ID)
139
+ so a page reload restores an active session without another signature prompt:
140
+
141
+ ```tsx
142
+ ;<PrivanaProvider siweAuth={{ autoLogin: true, persistJwt: true }}>
143
+ <App />
144
+ </PrivanaProvider>
145
+ ```
146
+
147
+ Logout captures the refresh token, clears local and cross-tab state immediately, suppresses
148
+ automatic re-login, and attempts server-side revocation.
149
+
150
+ > **Security note:** storing long-lived refresh credentials in `localStorage` makes them reachable
151
+ > from any JavaScript running on the page. An XSS vulnerability could exfiltrate them and forge a
152
+ > session, so only enable `persistJwt` on origins you fully control.
153
+
120
154
  ### Hosted redirect auth for cross-domain apps
121
155
 
122
156
  For widget or cross-domain frontends, configure `hostedAuth` on `PrivanaProvider` and use