@supertokens/rownd-react 0.1.0-beta.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/LICENSE +21 -0
- package/README.md +308 -0
- package/dist/components/RequireSignIn.d.ts +11 -0
- package/dist/components/RequireSignIn.js +18 -0
- package/dist/components/RequireSignIn.js.map +1 -0
- package/dist/components/SignedIn.d.ts +7 -0
- package/dist/components/SignedIn.js +11 -0
- package/dist/components/SignedIn.js.map +1 -0
- package/dist/components/SignedOut.d.ts +7 -0
- package/dist/components/SignedOut.js +11 -0
- package/dist/components/SignedOut.js.map +1 -0
- package/dist/context/HubScriptInjector/HubScriptInjector.d.ts +17 -0
- package/dist/context/HubScriptInjector/HubScriptInjector.js +34 -0
- package/dist/context/HubScriptInjector/HubScriptInjector.js.map +1 -0
- package/dist/context/HubScriptInjector/InternalProviderHubScriptInjector.d.ts +3 -0
- package/dist/context/HubScriptInjector/InternalProviderHubScriptInjector.js +19 -0
- package/dist/context/HubScriptInjector/InternalProviderHubScriptInjector.js.map +1 -0
- package/dist/context/InternalProvider.d.ts +9 -0
- package/dist/context/InternalProvider.js +13 -0
- package/dist/context/InternalProvider.js.map +1 -0
- package/dist/context/ReactRowndProvider.d.ts +4 -0
- package/dist/context/ReactRowndProvider.js +43 -0
- package/dist/context/ReactRowndProvider.js.map +1 -0
- package/dist/context/RowndContext.d.ts +33 -0
- package/dist/context/RowndContext.js +13 -0
- package/dist/context/RowndContext.js.map +1 -0
- package/dist/context/index.d.ts +7 -0
- package/dist/context/index.js +9 -0
- package/dist/context/index.js.map +1 -0
- package/dist/context/types.d.ts +112 -0
- package/dist/hooks/useHub.d.ts +48 -0
- package/dist/hooks/useHub.js +153 -0
- package/dist/hooks/useHub.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/main.d.ts +1 -0
- package/dist/main.js +13 -0
- package/dist/main.js.map +1 -0
- package/dist/next/RowndProvider.d.ts +5 -0
- package/dist/next/RowndProvider.js +9 -0
- package/dist/next/RowndProvider.js.map +1 -0
- package/dist/next/client/components/RequireSignIn.d.ts +5 -0
- package/dist/next/client/components/RequireSignIn.js +30 -0
- package/dist/next/client/components/RequireSignIn.js.map +1 -0
- package/dist/next/client/components/RowndServerStateSync.d.ts +2 -0
- package/dist/next/client/components/RowndServerStateSync.js +36 -0
- package/dist/next/client/components/RowndServerStateSync.js.map +1 -0
- package/dist/next/client/components/RowndServerStateSync.test.d.ts +1 -0
- package/dist/next/client/index.d.ts +5 -0
- package/dist/next/client/index.js +49 -0
- package/dist/next/client/index.js.map +1 -0
- package/dist/next/client/store/index.d.ts +3 -0
- package/dist/next/client/store/index.js +52 -0
- package/dist/next/client/store/index.js.map +1 -0
- package/dist/next/client/store/store.d.ts +13 -0
- package/dist/next/client/store/store.js +32 -0
- package/dist/next/client/store/store.js.map +1 -0
- package/dist/next/client/store/useStore.d.ts +3 -0
- package/dist/next/client/store/useStore.js +14 -0
- package/dist/next/client/store/useStore.js.map +1 -0
- package/dist/next/client/useRownd.d.ts +3 -0
- package/dist/next/client/useRownd.js +32 -0
- package/dist/next/client/useRownd.js.map +1 -0
- package/dist/next/client/withRowndRequireSignIn.d.ts +8 -0
- package/dist/next/client/withRowndRequireSignIn.js +19 -0
- package/dist/next/client/withRowndRequireSignIn.js.map +1 -0
- package/dist/next/index.d.ts +6 -0
- package/dist/next/server/getRowndAccessToken.d.ts +3 -0
- package/dist/next/server/getRowndAccessToken.js +11 -0
- package/dist/next/server/getRowndAccessToken.js.map +1 -0
- package/dist/next/server/getRowndUser.d.ts +11 -0
- package/dist/next/server/getRowndUser.js +11 -0
- package/dist/next/server/getRowndUser.js.map +1 -0
- package/dist/next/server/getRowndUserId.d.ts +3 -0
- package/dist/next/server/getRowndUserId.js +11 -0
- package/dist/next/server/getRowndUserId.js.map +1 -0
- package/dist/next/server/index.d.ts +8 -0
- package/dist/next/server/isAuthenticated.d.ts +3 -0
- package/dist/next/server/isAuthenticated.js +11 -0
- package/dist/next/server/isAuthenticated.js.map +1 -0
- package/dist/next/server/withRowndMiddleware.d.ts +4 -0
- package/dist/next/server/withRowndMiddleware.js +11 -0
- package/dist/next/server/withRowndMiddleware.js.map +1 -0
- package/dist/next/useRownd.d.ts +3 -0
- package/dist/next-server.d.ts +1 -0
- package/dist/next-server.js +15 -0
- package/dist/next-server.js.map +1 -0
- package/dist/next.d.ts +1 -0
- package/dist/next.js +11 -0
- package/dist/next.js.map +1 -0
- package/dist/remix/RemixRowndProvider.d.ts +5 -0
- package/dist/remix/RemixRowndProvider.js +28 -0
- package/dist/remix/RemixRowndProvider.js.map +1 -0
- package/dist/remix/client/RemixClientScript.d.ts +4 -0
- package/dist/remix/client/RemixClientScript.js +22 -0
- package/dist/remix/client/RemixClientScript.js.map +1 -0
- package/dist/remix/client/useRownd.d.ts +4 -0
- package/dist/remix/client/useRownd.js +35 -0
- package/dist/remix/client/useRownd.js.map +1 -0
- package/dist/remix/client/withRowndRequireSignIn.d.ts +4 -0
- package/dist/remix/client/withRowndRequireSignIn.js +27 -0
- package/dist/remix/client/withRowndRequireSignIn.js.map +1 -0
- package/dist/remix/index.d.ts +7 -0
- package/dist/remix/server/getRowndUser.d.ts +3 -0
- package/dist/remix/server/getRowndUser.js +11 -0
- package/dist/remix/server/getRowndUser.js.map +1 -0
- package/dist/remix/server/getRowndUserId.d.ts +1 -0
- package/dist/remix/server/getRowndUserId.js +8 -0
- package/dist/remix/server/getRowndUserId.js.map +1 -0
- package/dist/remix/server/index.d.ts +8 -0
- package/dist/remix/server/isAuthenticated.d.ts +1 -0
- package/dist/remix/server/isAuthenticated.js +8 -0
- package/dist/remix/server/isAuthenticated.js.map +1 -0
- package/dist/remix/server/withRowndActionHandler.d.ts +2 -0
- package/dist/remix/server/withRowndActionHandler.js +41 -0
- package/dist/remix/server/withRowndActionHandler.js.map +1 -0
- package/dist/remix/server/withRowndLoader.d.ts +13 -0
- package/dist/remix/server/withRowndLoader.js +19 -0
- package/dist/remix/server/withRowndLoader.js.map +1 -0
- package/dist/remix-server.d.ts +1 -0
- package/dist/remix-server.js +15 -0
- package/dist/remix-server.js.map +1 -0
- package/dist/remix.d.ts +1 -0
- package/dist/remix.js +17 -0
- package/dist/remix.js.map +1 -0
- package/dist/ssr/hooks/useCookie.d.ts +7 -0
- package/dist/ssr/hooks/useCookie.js +22 -0
- package/dist/ssr/hooks/useCookie.js.map +1 -0
- package/dist/ssr/server/cookie.d.ts +13 -0
- package/dist/ssr/server/cookie.js +51 -0
- package/dist/ssr/server/cookie.js.map +1 -0
- package/dist/ssr/server/token.d.ts +44 -0
- package/dist/ssr/server/token.js +128 -0
- package/dist/ssr/server/token.js.map +1 -0
- package/dist/ssr/server/token.test.d.ts +1 -0
- package/dist/utils/listeners.d.ts +8 -0
- package/dist/utils/listeners.js +15 -0
- package/dist/utils/listeners.js.map +1 -0
- package/package.json +34 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Rownd, Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
#### README's for [Next](https://github.com/rownd/react/tree/main/packages/next) and [Remix](https://github.com/rownd/react/tree/main/packages/remix).
|
|
2
|
+
|
|
3
|
+
# React
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Simply run `npm install @rownd/react` or `yarn add @rownd/react`.
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
### React
|
|
12
|
+
|
|
13
|
+
The library provides a React provider and hook for the Rownd browser API.
|
|
14
|
+
|
|
15
|
+
In your app's main entrypoint, add the Rownd provider, likely before other providers:
|
|
16
|
+
|
|
17
|
+
```jsx
|
|
18
|
+
import React from 'react',
|
|
19
|
+
import ReactDOM from 'react-dom';
|
|
20
|
+
import { RowndProvider } from '@rownd/react';
|
|
21
|
+
import App from './App';
|
|
22
|
+
|
|
23
|
+
ReactDOM.render(
|
|
24
|
+
<RowndProvider
|
|
25
|
+
appKey="<your app key>"
|
|
26
|
+
>
|
|
27
|
+
<App />
|
|
28
|
+
</RowndProvider>,
|
|
29
|
+
document.getElementById('root')
|
|
30
|
+
);
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
{% hint style="warning" %}
|
|
34
|
+
The Rownd React SDK automatically injects the Rownd Hub snippet into your React application, so you should _not_ manually include the Hub snippet in your HTML page. Doing so will produce unexpected results.
|
|
35
|
+
{% endhint %}
|
|
36
|
+
|
|
37
|
+
### RowndProvider props
|
|
38
|
+
|
|
39
|
+
- `appKey` (required): This is the key generated by the [Rownd dashboard](https://app.rownd.io).
|
|
40
|
+
- `postLoginRedirect` (optional): Where the browser should redirect the user after a successful sign-in. If not supplied, the user will remain on the same page.
|
|
41
|
+
- `rootOrigin` (optional): If you're using Rownd across multiple domains (e.g., `rownd.io` and `app.rownd.io`), set this to the "root" _origin_ (e.g., https://rownd.io).
|
|
42
|
+
|
|
43
|
+
### Provider props
|
|
44
|
+
|
|
45
|
+
* `appKey` (required): This is the key generated by the [Rownd dashboard](https://app.rownd.io).
|
|
46
|
+
* `postLoginRedirect` (optional): Where the browser should redirect the user after a successful sign-in. If not supplied, the user will remain on the same page.
|
|
47
|
+
* `rootOrigin` (optional): If you're using Rownd across multiple domains (e.g., `rownd.io` and `app.rownd.io`), set this to the "root" _origin_ (e.g., https://rownd.io).
|
|
48
|
+
|
|
49
|
+
Later on within your app's components, you can use the Rownd hook to access the Rownd browser API:
|
|
50
|
+
|
|
51
|
+
```jsx
|
|
52
|
+
import React from 'react';
|
|
53
|
+
import { useRownd } from '@rownd/react';
|
|
54
|
+
|
|
55
|
+
export default function MyProtectedComponent(props) {
|
|
56
|
+
const { is_authenticated, user, requestSignIn, is_initializing } = useRownd();
|
|
57
|
+
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
if (!is_authenticated && !is_initializing) {
|
|
60
|
+
requestSignIn();
|
|
61
|
+
}
|
|
62
|
+
}, [is_authenticated, is_initializing]);
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<div>
|
|
66
|
+
{is_authenticated ? (
|
|
67
|
+
<div>
|
|
68
|
+
<h1>Welcome {user.data.first_name}</h1>
|
|
69
|
+
<h2>Email:{user.data.email}</h2>
|
|
70
|
+
<button onClick={() => getAccessToken()}>Get access token</button>
|
|
71
|
+
</div>
|
|
72
|
+
) : (
|
|
73
|
+
<div>
|
|
74
|
+
<h1>Please sign in to continue</h1>
|
|
75
|
+
</div>
|
|
76
|
+
)}
|
|
77
|
+
</div>
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Usage with redux, etc
|
|
83
|
+
|
|
84
|
+
Often, sending and receiving data from your server will rely on the Rownd access token as a means of authenticating the user within your back-end (see our [Node.js SDK](node.js.md) as an example of this). Many React apps leverage Redux or similar technologies to manage an app's global state.
|
|
85
|
+
|
|
86
|
+
The key here is to call Rownd's `getAccessToken({ waitForToken: true })` method when calling your own authenticated APIs. For example, if you're using [axios](https://npmjs.com/package/axios), you'd likely set up an interceptor that looks something like this:
|
|
87
|
+
|
|
88
|
+
```javascript
|
|
89
|
+
// api-client.js
|
|
90
|
+
|
|
91
|
+
import axios from 'axios';
|
|
92
|
+
|
|
93
|
+
let getAccessToken;
|
|
94
|
+
|
|
95
|
+
axios.interceptors.request.use(async (config) => {
|
|
96
|
+
if (!getAccessToken) {
|
|
97
|
+
return config;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (config.skipAuth || !config.url.startsWith('/api')) {
|
|
101
|
+
return config;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const accessToken = await getAccessToken({ waitForToken: true });
|
|
105
|
+
|
|
106
|
+
config.headers.common.Authorization = `Bearer ${accessToken}`;
|
|
107
|
+
return config;
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
export function setAccessTokenHelper(fn) {
|
|
111
|
+
getAccessToken = fn;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export default axios;
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Here's another example, this time using [ky](https://npmjs.com/package/ky):
|
|
118
|
+
|
|
119
|
+
```javascript
|
|
120
|
+
// api-client.js
|
|
121
|
+
|
|
122
|
+
import ky from 'ky';
|
|
123
|
+
|
|
124
|
+
let getAccessToken;
|
|
125
|
+
|
|
126
|
+
ky.extend({
|
|
127
|
+
hooks: {
|
|
128
|
+
beforeRequest: [
|
|
129
|
+
// Auto-refresh tokens
|
|
130
|
+
async (request) => {
|
|
131
|
+
if (!getAccessToken) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (request.skipAuth || !request.url.startsWith('/api')) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const accessToken = await getAccessToken({ waitForToken: true });
|
|
140
|
+
|
|
141
|
+
request.headers.set(
|
|
142
|
+
'Authorization',
|
|
143
|
+
`Bearer ${tokenResp.access_token}`
|
|
144
|
+
);
|
|
145
|
+
},
|
|
146
|
+
],
|
|
147
|
+
},
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
function setAccessTokenHelper(fn) {
|
|
151
|
+
getAccessToken = fn;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export { api, setAccessTokenHelper };
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
In both of the cases above, our async actions would use these instances of axios or ky to make requests back to the server, but before any of those fire, we need to set the access token helper from our React app like this:
|
|
158
|
+
|
|
159
|
+
```javascript
|
|
160
|
+
// AppWrapper.jsx
|
|
161
|
+
|
|
162
|
+
import { useRownd } from '@rownd/react';
|
|
163
|
+
import { setAccessTokenHelper } from './api-client';
|
|
164
|
+
import App from './app';
|
|
165
|
+
|
|
166
|
+
export default function MyReactAppWrapper() {
|
|
167
|
+
const { getAccessToken } = useRownd();
|
|
168
|
+
|
|
169
|
+
useEffect(() => {
|
|
170
|
+
setAccessTokenHelper(getAccessToken);
|
|
171
|
+
}, [getAccessToken]);
|
|
172
|
+
|
|
173
|
+
return <App />;
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
That's one way to solve this problem. Another might be to wrap the redux provider in your own component and simply pass the `getAccessToken` function down into the store during initialization. If you come up with a better mousetrap here, let us know!
|
|
178
|
+
|
|
179
|
+
## API reference
|
|
180
|
+
|
|
181
|
+
Most API methods are made available via the Rownd Provider and its associated `useRownd` React hook. Unless otherwise noted, we're assuming that you're using hooks.
|
|
182
|
+
|
|
183
|
+
#### requestSignIn()
|
|
184
|
+
|
|
185
|
+
Trigger the Rownd sign in dialog
|
|
186
|
+
|
|
187
|
+
```javascript
|
|
188
|
+
const { requestSignIn } = useRownd();
|
|
189
|
+
|
|
190
|
+
requestSignIn({
|
|
191
|
+
auto_sign_in: false, // optional
|
|
192
|
+
identifier: 'me@company.com' || '+19105551212', // optional
|
|
193
|
+
});
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
- `auto_sign_in: boolean` - when `true`, automatically trigger a sign-in attempt _if_ `identifier` is included or an email address or phone number has already been set in the user data.
|
|
197
|
+
- `identifier: string` - an email address or phone number (in E164 format) to which a verification message may be sent. If the Rownd app is configured to allow unverified users, then sign-in will complete without verification if the user has not signed in previously.
|
|
198
|
+
|
|
199
|
+
#### signOut()
|
|
200
|
+
|
|
201
|
+
Sign out the user and clear their profile, returning them to a completely unauthenticated state.
|
|
202
|
+
|
|
203
|
+
```javascript
|
|
204
|
+
const { signOut } = useRownd();
|
|
205
|
+
signOut();
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
#### **getAccessToken()**
|
|
209
|
+
|
|
210
|
+
Retrieves the active, valid access token for the current user. 
|
|
211
|
+
|
|
212
|
+
```javascript
|
|
213
|
+
const { getAccessToken } = useRownd();
|
|
214
|
+
|
|
215
|
+
let accessToken = await getAccessToken({
|
|
216
|
+
waitForToken: false,
|
|
217
|
+
});
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
- `waitForToken: boolean` - when `true`, if no access token is present or if it's expired, the promise will not resolve until a valid token is available. While unlikely, this could result in waiting forever.
|
|
221
|
+
|
|
222
|
+
**is_initializing**
|
|
223
|
+
|
|
224
|
+
`is_initializing` will be `true` until the Hub has fully loaded, recalled its state, and resolved the current user's authentication status. This usually takes only a few milliseconds, but if you make decisions that depend on the `is_authenticated` flag while `is_initializing` is still `true`, your code/logic may not work as you expect.
|
|
225
|
+
|
|
226
|
+
```javascript
|
|
227
|
+
const { is_initializing } = useRownd();
|
|
228
|
+
|
|
229
|
+
if (is_initializing) {
|
|
230
|
+
// return loading state or null
|
|
231
|
+
}
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
#### is_authenticated
|
|
235
|
+
|
|
236
|
+
Indicates whether the current user is signed in or not.
|
|
237
|
+
|
|
238
|
+
```javascript
|
|
239
|
+
const { is_authenticated } = useRownd();
|
|
240
|
+
|
|
241
|
+
return (
|
|
242
|
+
<>
|
|
243
|
+
{is_authenticated && <ProtectedRoute />}
|
|
244
|
+
{!is_authenticated && <PublicRoute />}
|
|
245
|
+
</>
|
|
246
|
+
);
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
#### access_token
|
|
250
|
+
|
|
251
|
+
Represents the current access token for the user.
|
|
252
|
+
|
|
253
|
+
```javascript
|
|
254
|
+
const { access_token } = useRownd();
|
|
255
|
+
|
|
256
|
+
useEffect(() => {
|
|
257
|
+
axios({
|
|
258
|
+
method: 'post',
|
|
259
|
+
url: '/api/sessions'
|
|
260
|
+
headers: {
|
|
261
|
+
authorization: `Bearer ${access_token}`
|
|
262
|
+
}
|
|
263
|
+
}).then(console.log);
|
|
264
|
+
}, [access_token]);
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
#### user
|
|
268
|
+
|
|
269
|
+
Represents information about the current user, specifically their profile information. In the example below, we use the existing data to display the current value of `first_name` in a form field, update a local copy of that data as the user changes it, and then save the changes to Rownd once the user submits the form.
|
|
270
|
+
|
|
271
|
+
```javascript
|
|
272
|
+
const { user } = useRownd();
|
|
273
|
+
|
|
274
|
+
const [profile, setProfile] = useState(user.data);
|
|
275
|
+
|
|
276
|
+
return (
|
|
277
|
+
<form onSubmit={() => user.set(profile)}>
|
|
278
|
+
<label htmlFor="first_name">
|
|
279
|
+
<input
|
|
280
|
+
id="first_name"
|
|
281
|
+
type="text"
|
|
282
|
+
value={profile?.first_name}
|
|
283
|
+
onInput={(evt) =>
|
|
284
|
+
setProfile({ ...profile, first_name: evt.target.value })
|
|
285
|
+
}
|
|
286
|
+
/>
|
|
287
|
+
</label>
|
|
288
|
+
<button type="submit">Save</button>
|
|
289
|
+
</form>
|
|
290
|
+
);
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
**Merge data into the user profile**
|
|
294
|
+
|
|
295
|
+
```javascript
|
|
296
|
+
const { user } = useRownd();
|
|
297
|
+
user.set({
|
|
298
|
+
first_name: 'Alice',
|
|
299
|
+
last_name: 'Ranier',
|
|
300
|
+
});
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
Set a specific field in the user profile
|
|
304
|
+
|
|
305
|
+
```javascript
|
|
306
|
+
const { user } = useRownd();
|
|
307
|
+
user.setValue('first_name', 'Alice');
|
|
308
|
+
```
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { SignInProps } from '../context/types';
|
|
3
|
+
|
|
4
|
+
interface RequireSignInProps {
|
|
5
|
+
children: any;
|
|
6
|
+
initializing?: React.ReactNode;
|
|
7
|
+
signInProps?: SignInProps;
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
}
|
|
10
|
+
declare const RequireSignIn: React.FC<RequireSignInProps>;
|
|
11
|
+
export default RequireSignIn;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import e, { useEffect as a } from "react";
|
|
2
|
+
import { useRownd as c } from "../context/RowndContext.js";
|
|
3
|
+
import "../context/InternalProvider.js";
|
|
4
|
+
const g = ({
|
|
5
|
+
children: o,
|
|
6
|
+
initializing: r,
|
|
7
|
+
signInProps: n,
|
|
8
|
+
disabled: u
|
|
9
|
+
}) => {
|
|
10
|
+
const { is_authenticated: i, is_initializing: t, requestSignIn: m } = c();
|
|
11
|
+
return a(() => {
|
|
12
|
+
!i && !t && !u && m({ prevent_closing: !0, ...n });
|
|
13
|
+
}, [i, t, m, n, u]), t && r ? /* @__PURE__ */ e.createElement(e.Fragment, null, r) : /* @__PURE__ */ e.createElement(e.Fragment, null, o);
|
|
14
|
+
};
|
|
15
|
+
export {
|
|
16
|
+
g as default
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=RequireSignIn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RequireSignIn.js","sources":["../../src/components/RequireSignIn.tsx"],"sourcesContent":["import React, { useEffect } from 'react';\nimport { useRownd } from '../context';\nimport { SignInProps } from '../context/types';\n\ninterface RequireSignInProps {\n children: any;\n initializing?: React.ReactNode;\n signInProps?: SignInProps;\n disabled?: boolean;\n}\n\nconst RequireSignIn: React.FC<RequireSignInProps> = ({\n children,\n initializing,\n signInProps,\n disabled\n}) => {\n const { is_authenticated, is_initializing, requestSignIn } = useRownd();\n\n useEffect(() => {\n if (!is_authenticated && !is_initializing && !disabled) {\n requestSignIn({ prevent_closing: true, ...signInProps });\n }\n }, [is_authenticated, is_initializing, requestSignIn, signInProps, disabled]);\n\n if (is_initializing && initializing) {\n return <>{initializing}</>;\n }\n\n return <>{children}</>;\n};\n\nexport default RequireSignIn;\n"],"names":["RequireSignIn","children","initializing","signInProps","disabled","is_authenticated","is_initializing","requestSignIn","useRownd","useEffect"],"mappings":";;;AAWA,MAAMA,IAA8C,CAAC;AAAA,EACnD,UAAAC;AAAA,EACA,cAAAC;AAAA,EACA,aAAAC;AAAA,EACA,UAAAC;AACF,MAAM;AACJ,QAAM,EAAE,kBAAAC,GAAkB,iBAAAC,GAAiB,eAAAC,EAAA,IAAkBC,EAAA;AAQ7D,SANAC,EAAU,MAAM;AACd,IAAI,CAACJ,KAAoB,CAACC,KAAmB,CAACF,KAC5CG,EAAc,EAAE,iBAAiB,IAAM,GAAGJ,GAAa;AAAA,EAE3D,GAAG,CAACE,GAAkBC,GAAiBC,GAAeJ,GAAaC,CAAQ,CAAC,GAExEE,KAAmBJ,sDACXA,CAAa,sDAGfD,CAAS;AACrB;"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import t from "react";
|
|
2
|
+
import { useRownd as r } from "../context/RowndContext.js";
|
|
3
|
+
import "../context/InternalProvider.js";
|
|
4
|
+
const m = ({ children: e }) => {
|
|
5
|
+
const { is_authenticated: n } = r();
|
|
6
|
+
return n ? /* @__PURE__ */ t.createElement(t.Fragment, null, e) : null;
|
|
7
|
+
};
|
|
8
|
+
export {
|
|
9
|
+
m as default
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=SignedIn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SignedIn.js","sources":["../../src/components/SignedIn.tsx"],"sourcesContent":["import React from 'react';\nimport { useRownd } from '../context';\n\ninterface SignedInProps {\n children: React.ReactNode;\n}\n\nconst SignedIn: React.FC<SignedInProps> = ({ children }) => {\n const { is_authenticated } = useRownd();\n\n if (!is_authenticated) {\n return null;\n }\n return <>{children}</>;\n};\n\nexport default SignedIn;\n"],"names":["SignedIn","children","is_authenticated","useRownd"],"mappings":";;;AAOA,MAAMA,IAAoC,CAAC,EAAE,UAAAC,QAAe;AAC1D,QAAM,EAAE,kBAAAC,EAAA,IAAqBC,EAAA;AAE7B,SAAKD,sDAGKD,CAAS,IAFV;AAGX;"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import t from "react";
|
|
2
|
+
import { useRownd as n } from "../context/RowndContext.js";
|
|
3
|
+
import "../context/InternalProvider.js";
|
|
4
|
+
const i = ({ children: e }) => {
|
|
5
|
+
const { is_authenticated: r } = n();
|
|
6
|
+
return r ? null : /* @__PURE__ */ t.createElement(t.Fragment, null, e);
|
|
7
|
+
};
|
|
8
|
+
export {
|
|
9
|
+
i as default
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=SignedOut.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SignedOut.js","sources":["../../src/components/SignedOut.tsx"],"sourcesContent":["import React from 'react';\nimport { useRownd } from '../context';\n\ninterface SignedOutProps {\n children: React.ReactNode;\n}\n\nconst SignedOut: React.FC<SignedOutProps> = ({ children }) => {\n const { is_authenticated } = useRownd();\n\n if (is_authenticated) {\n return null;\n }\n return <>{children}</>;\n};\n\nexport default SignedOut;\n"],"names":["SignedOut","children","is_authenticated","useRownd"],"mappings":";;;AAOA,MAAMA,IAAsC,CAAC,EAAE,UAAAC,QAAe;AAC5D,QAAM,EAAE,kBAAAC,EAAA,IAAqBC,EAAA;AAE7B,SAAID,IACK,yDAECD,CAAS;AACrB;"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { HubListenerProps, SuperTokensConfig } from '../RowndContext';
|
|
2
|
+
|
|
3
|
+
declare global {
|
|
4
|
+
interface Window {
|
|
5
|
+
_rphConfig: any;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export type HubScriptInjectorProps = {
|
|
9
|
+
appKey: string;
|
|
10
|
+
stateListener: ({ state, api }: HubListenerProps) => void;
|
|
11
|
+
apiUrl?: string;
|
|
12
|
+
supertokens: SuperTokensConfig;
|
|
13
|
+
hubUrlOverride?: string;
|
|
14
|
+
locationHash?: string;
|
|
15
|
+
apiVersion?: string;
|
|
16
|
+
};
|
|
17
|
+
export default function HubScriptInjector({ appKey, apiUrl, supertokens, hubUrlOverride, stateListener, apiVersion, ...rest }: HubScriptInjectorProps): null;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { useEffect as _ } from "react";
|
|
2
|
+
function t(s, o) {
|
|
3
|
+
o && (window == null || window._rphConfig.push([s, o]));
|
|
4
|
+
}
|
|
5
|
+
const m = "2026-01-21";
|
|
6
|
+
var h;
|
|
7
|
+
const f = typeof window < "u" ? (h = window == null ? void 0 : window.location) == null ? void 0 : h.hash : void 0;
|
|
8
|
+
function y({
|
|
9
|
+
appKey: s,
|
|
10
|
+
apiUrl: o,
|
|
11
|
+
supertokens: p,
|
|
12
|
+
hubUrlOverride: a,
|
|
13
|
+
stateListener: l,
|
|
14
|
+
apiVersion: u = m,
|
|
15
|
+
...c
|
|
16
|
+
}) {
|
|
17
|
+
return _(() => {
|
|
18
|
+
if (!window)
|
|
19
|
+
return;
|
|
20
|
+
const w = window._rphConfig = window._rphConfig || [], d = window.localStorage.getItem("rph_base_url_override") || a || "https://hub.rownd.io";
|
|
21
|
+
w.push(["setBaseUrl", d]), t("setAppKey", s), t("setStateListener", l), t("setLocationHash", f), t("setApiVersion", u), t("setSupertokens", p), t("setLegacyRowndApiUrl", o);
|
|
22
|
+
const n = document, r = n.createElement("script"), i = n.createElement("script"), e = n.getElementsByTagName("script")[0];
|
|
23
|
+
r.noModule = !0, r.async = !0, r.src = d + "/static/scripts/rph.js", i.type = "module", i.async = !0, i.src = d + "/static/scripts/rph.mjs", e != null && e.parentNode ? (e.parentNode.insertBefore(r, e), e.parentNode.insertBefore(i, e)) : (n.body.appendChild(r), n.body.appendChild(i)), window.localStorage.getItem("rph_log_level") === "debug" && console.debug("[debug] rest:", c), c && (Object.entries(c).forEach(([g, b]) => {
|
|
24
|
+
t(
|
|
25
|
+
`set${g.charAt(0).toUpperCase() + g.substring(1)}`,
|
|
26
|
+
b
|
|
27
|
+
);
|
|
28
|
+
}), window.localStorage.getItem("rph_log_level") === "debug" && console.debug("[debug] hubConfig:", window._rphConfig));
|
|
29
|
+
}, [s, o, p, l, f, a, u, c]), null;
|
|
30
|
+
}
|
|
31
|
+
export {
|
|
32
|
+
y as default
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=HubScriptInjector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HubScriptInjector.js","sources":["../../../src/context/HubScriptInjector/HubScriptInjector.tsx"],"sourcesContent":["import { useEffect } from 'react';\nimport { HubListenerProps, SuperTokensConfig } from '../RowndContext';\n\ndeclare global {\n interface Window {\n _rphConfig: any;\n }\n}\n\nfunction setConfigValue(key: string, value: any) {\n if (!value) {\n return;\n }\n\n window?._rphConfig.push([key, value]);\n}\n\n/**\n * Default API version for new SDK releases.\n * This controls which Hub features are enabled by default.\n */\nconst DEFAULT_API_VERSION = '2026-01-21';\n\nexport type HubScriptInjectorProps = {\n appKey: string;\n stateListener: ({ state, api }: HubListenerProps) => void;\n apiUrl?: string;\n supertokens: SuperTokensConfig;\n hubUrlOverride?: string;\n locationHash?: string;\n apiVersion?: string;\n};\n\n// Grab the URL hash ASAP in case it contains an `rph_init` param\nconst locationHash =\n typeof window !== 'undefined' ? window?.location?.hash : void 0;\n\nexport default function HubScriptInjector({\n appKey,\n apiUrl,\n supertokens,\n hubUrlOverride,\n stateListener,\n apiVersion = DEFAULT_API_VERSION,\n ...rest\n}: HubScriptInjectorProps) {\n\n useEffect(() => {\n if (!window) {\n return; // compat with server-side rendering\n }\n\n const _rphConfig = (window._rphConfig = window._rphConfig || []);\n const baseUrl =\n window.localStorage.getItem('rph_base_url_override') ||\n hubUrlOverride ||\n 'https://hub.rownd.io';\n _rphConfig.push(['setBaseUrl', baseUrl]);\n\n setConfigValue('setAppKey', appKey);\n setConfigValue('setStateListener', stateListener);\n setConfigValue('setLocationHash', locationHash);\n setConfigValue('setApiVersion', apiVersion);\n setConfigValue('setSupertokens', supertokens);\n setConfigValue('setLegacyRowndApiUrl', apiUrl);\n\n const d = document,\n g = d.createElement('script'),\n m = d.createElement('script'),\n s = d.getElementsByTagName('script')[0];\n g.noModule = true;\n g.async = true;\n g.src = baseUrl + '/static/scripts/rph.js';\n m.type = 'module';\n m.async = true;\n m.src = baseUrl + '/static/scripts/rph.mjs';\n\n if (s?.parentNode) {\n s.parentNode.insertBefore(g, s);\n s.parentNode.insertBefore(m, s);\n } else {\n d.body.appendChild(g);\n d.body.appendChild(m);\n }\n\n if (window.localStorage.getItem('rph_log_level') === 'debug') {\n console.debug('[debug] rest:', rest);\n }\n\n if (rest) {\n Object.entries(rest).forEach(([key, value]) => {\n setConfigValue(\n `set${key.charAt(0).toUpperCase() + key.substring(1)}`,\n value\n );\n });\n\n if (window.localStorage.getItem('rph_log_level') === 'debug') {\n console.debug('[debug] hubConfig:', window._rphConfig);\n }\n }\n }, [appKey, apiUrl, supertokens, stateListener, locationHash, hubUrlOverride, apiVersion, rest]);\n\n return null;\n}\n"],"names":["setConfigValue","key","value","DEFAULT_API_VERSION","locationHash","_a","HubScriptInjector","appKey","apiUrl","supertokens","hubUrlOverride","stateListener","apiVersion","rest","useEffect","_rphConfig","baseUrl","d","g","m","s"],"mappings":";AASA,SAASA,EAAeC,GAAaC,GAAY;AAC/C,EAAKA,MAIL,yBAAQ,WAAW,KAAK,CAACD,GAAKC,CAAK;AACrC;AAMA,MAAMC,IAAsB;;AAa5B,MAAMC,IACJ,OAAO,SAAW,OAAcC,IAAA,iCAAQ,aAAR,gBAAAA,EAAkB,OAAO;AAE3D,SAAwBC,EAAkB;AAAA,EACxC,QAAAC;AAAA,EACA,QAAAC;AAAA,EACA,aAAAC;AAAA,EACA,gBAAAC;AAAA,EACA,eAAAC;AAAA,EACA,YAAAC,IAAaT;AAAA,EACb,GAAGU;AACL,GAA2B;AAEzB,SAAAC,EAAU,MAAM;AACd,QAAI,CAAC;AACH;AAGF,UAAMC,IAAc,OAAO,aAAa,OAAO,cAAc,CAAA,GACvDC,IACJ,OAAO,aAAa,QAAQ,uBAAuB,KACnDN,KACA;AACF,IAAAK,EAAW,KAAK,CAAC,cAAcC,CAAO,CAAC,GAEvChB,EAAe,aAAaO,CAAM,GAClCP,EAAe,oBAAoBW,CAAa,GAChDX,EAAe,mBAAmBI,CAAY,GAC9CJ,EAAe,iBAAiBY,CAAU,GAC1CZ,EAAe,kBAAkBS,CAAW,GAC5CT,EAAe,wBAAwBQ,CAAM;AAE7C,UAAMS,IAAI,UACRC,IAAID,EAAE,cAAc,QAAQ,GAC5BE,IAAIF,EAAE,cAAc,QAAQ,GAC5BG,IAAIH,EAAE,qBAAqB,QAAQ,EAAE,CAAC;AACxC,IAAAC,EAAE,WAAW,IACbA,EAAE,QAAQ,IACVA,EAAE,MAAMF,IAAU,0BAClBG,EAAE,OAAO,UACTA,EAAE,QAAQ,IACVA,EAAE,MAAMH,IAAU,2BAEdI,KAAA,QAAAA,EAAG,cACLA,EAAE,WAAW,aAAaF,GAAGE,CAAC,GAC9BA,EAAE,WAAW,aAAaD,GAAGC,CAAC,MAE9BH,EAAE,KAAK,YAAYC,CAAC,GACpBD,EAAE,KAAK,YAAYE,CAAC,IAGlB,OAAO,aAAa,QAAQ,eAAe,MAAM,WACnD,QAAQ,MAAM,iBAAiBN,CAAI,GAGjCA,MACF,OAAO,QAAQA,CAAI,EAAE,QAAQ,CAAC,CAACZ,GAAKC,CAAK,MAAM;AAC7C,MAAAF;AAAA,QACE,MAAMC,EAAI,OAAO,CAAC,EAAE,gBAAgBA,EAAI,UAAU,CAAC,CAAC;AAAA,QACpDC;AAAA,MAAA;AAAA,IAEJ,CAAC,GAEG,OAAO,aAAa,QAAQ,eAAe,MAAM,WACnD,QAAQ,MAAM,sBAAsB,OAAO,UAAU;AAAA,EAG3D,GAAG,CAACK,GAAQC,GAAQC,GAAaE,GAAeP,GAAcM,GAAgBE,GAAYC,CAAI,CAAC,GAExF;AACT;"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import o from "react";
|
|
2
|
+
import { useInternalRownd as i } from "../InternalProvider.js";
|
|
3
|
+
import a from "./HubScriptInjector.js";
|
|
4
|
+
function u() {
|
|
5
|
+
const { appKey: r, hubUrlOverride: e, stateListener: t, ...n } = i();
|
|
6
|
+
return /* @__PURE__ */ o.createElement(
|
|
7
|
+
a,
|
|
8
|
+
{
|
|
9
|
+
appKey: r,
|
|
10
|
+
hubUrlOverride: e,
|
|
11
|
+
stateListener: t,
|
|
12
|
+
...n
|
|
13
|
+
}
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
u as default
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=InternalProviderHubScriptInjector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InternalProviderHubScriptInjector.js","sources":["../../../src/context/HubScriptInjector/InternalProviderHubScriptInjector.tsx"],"sourcesContent":["import React from 'react';\nimport { useInternalRownd } from '../InternalProvider';\nimport HubScriptInjector from './HubScriptInjector';\n\nexport default function InternalProviderHubScriptInjector() {\n const { appKey, hubUrlOverride, stateListener, ...rest } = useInternalRownd();\n\n return (\n <HubScriptInjector\n appKey={appKey}\n hubUrlOverride={hubUrlOverride}\n stateListener={stateListener}\n {...rest}\n />\n );\n}\n"],"names":["InternalProviderHubScriptInjector","appKey","hubUrlOverride","stateListener","rest","useInternalRownd","React","HubScriptInjector"],"mappings":";;;AAIA,SAAwBA,IAAoC;AAC1D,QAAM,EAAE,QAAAC,GAAQ,gBAAAC,GAAgB,eAAAC,GAAe,GAAGC,EAAA,IAASC,EAAA;AAE3D,SACE,gBAAAC,EAAA;AAAA,IAACC;AAAA,IAAA;AAAA,MACC,QAAAN;AAAA,MACA,gBAAAC;AAAA,MACA,eAAAC;AAAA,MACC,GAAGC;AAAA,IAAA;AAAA,EAAA;AAGV;"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { HubScriptInjectorProps } from './HubScriptInjector/HubScriptInjector';
|
|
3
|
+
|
|
4
|
+
type InternalRowndProvider = HubScriptInjectorProps & {
|
|
5
|
+
children: React.ReactNode;
|
|
6
|
+
};
|
|
7
|
+
export declare const InternalRowndProvider: ({ children, ...rest }: InternalRowndProvider) => React.JSX.Element;
|
|
8
|
+
export declare function useInternalRownd(): HubScriptInjectorProps;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import r, { createContext as o, useContext as d } from "react";
|
|
2
|
+
const n = o(void 0), i = ({ children: e, ...t }) => /* @__PURE__ */ r.createElement(n.Provider, { value: t }, e);
|
|
3
|
+
function u() {
|
|
4
|
+
const e = d(n);
|
|
5
|
+
if (e === void 0)
|
|
6
|
+
throw new Error("useInternalRownd must be used within a InternalRowndProvider");
|
|
7
|
+
return e;
|
|
8
|
+
}
|
|
9
|
+
export {
|
|
10
|
+
i as InternalRowndProvider,
|
|
11
|
+
u as useInternalRownd
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=InternalProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InternalProvider.js","sources":["../../src/context/InternalProvider.tsx"],"sourcesContent":["import React, { useContext, createContext } from 'react';\nimport { HubScriptInjectorProps } from './HubScriptInjector/HubScriptInjector';\n\nconst InternalRowndContext = createContext<HubScriptInjectorProps | undefined>(undefined);\n\ntype InternalRowndProvider = HubScriptInjectorProps & { children: React.ReactNode }\n\nexport const InternalRowndProvider = ({ children, ...rest }: InternalRowndProvider) => {\n return (\n <InternalRowndContext.Provider value={rest}> \n {children}\n </InternalRowndContext.Provider>\n );\n}\n\nexport function useInternalRownd(): HubScriptInjectorProps {\n const context = useContext(InternalRowndContext);\n\n if (context === undefined) {\n throw new Error('useInternalRownd must be used within a InternalRowndProvider');\n }\n\n return context;\n}\n"],"names":["InternalRowndContext","createContext","InternalRowndProvider","children","rest","useInternalRownd","context","useContext"],"mappings":";AAGA,MAAMA,IAAuBC,EAAkD,MAAS,GAI3EC,IAAwB,CAAC,EAAE,UAAAC,GAAU,GAAGC,wCAEhDJ,EAAqB,UAArB,EAA8B,OAAOI,KACnCD,CACH;AAIG,SAASE,IAA2C;AACzD,QAAMC,IAAUC,EAAWP,CAAoB;AAE/C,MAAIM,MAAY;AACd,UAAM,IAAI,MAAM,8DAA8D;AAGhF,SAAOA;AACT;"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import e, { useCallback as u, useEffect as h } from "react";
|
|
2
|
+
import { RowndContext as p } from "./RowndContext.js";
|
|
3
|
+
import v from "./HubScriptInjector/InternalProviderHubScriptInjector.js";
|
|
4
|
+
import E from "../hooks/useHub.js";
|
|
5
|
+
import { InternalRowndProvider as L } from "./InternalProvider.js";
|
|
6
|
+
import { addOnAuthenticatedListener as R, getOnAuthenticatedListeners as S, unsubscribeOnAuthenticatedListener as A } from "../utils/listeners.js";
|
|
7
|
+
const g = ({
|
|
8
|
+
children: c,
|
|
9
|
+
...d
|
|
10
|
+
}) => {
|
|
11
|
+
const { setInitialHubState: b, hubListenerCb: i } = E(), m = u(
|
|
12
|
+
(t) => {
|
|
13
|
+
const n = R(t);
|
|
14
|
+
return () => {
|
|
15
|
+
A(n);
|
|
16
|
+
};
|
|
17
|
+
},
|
|
18
|
+
[]
|
|
19
|
+
), [r, l] = e.useState({
|
|
20
|
+
...b(),
|
|
21
|
+
onAuthenticated: m
|
|
22
|
+
}), { user: a, is_authenticated: s, is_initializing: o } = r;
|
|
23
|
+
h(() => {
|
|
24
|
+
!s || o || !a.data.user_id || S().forEach(
|
|
25
|
+
({ callback: t }) => t(r.user.data)
|
|
26
|
+
);
|
|
27
|
+
}, [s, o, a.data.user_id]);
|
|
28
|
+
const f = u(({ state: t, api: n }) => {
|
|
29
|
+
i({ state: t, api: n, callback: l });
|
|
30
|
+
}, [i]);
|
|
31
|
+
return /* @__PURE__ */ e.createElement(
|
|
32
|
+
L,
|
|
33
|
+
{
|
|
34
|
+
stateListener: f,
|
|
35
|
+
...d
|
|
36
|
+
},
|
|
37
|
+
/* @__PURE__ */ e.createElement(p.Provider, { value: r }, /* @__PURE__ */ e.createElement(v, null), c)
|
|
38
|
+
);
|
|
39
|
+
};
|
|
40
|
+
export {
|
|
41
|
+
g as ReactRowndProvider
|
|
42
|
+
};
|
|
43
|
+
//# sourceMappingURL=ReactRowndProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReactRowndProvider.js","sources":["../../src/context/ReactRowndProvider.tsx"],"sourcesContent":["import React, { useCallback, useEffect } from 'react';\nimport { HubListenerProps, RowndContext, RowndProviderProps } from './RowndContext';\nimport InternalProviderHubScriptInjector from './HubScriptInjector/InternalProviderHubScriptInjector';\nimport useHub from '../hooks/useHub';\nimport { TRowndContext, UserDataContext } from './types';\nimport { InternalRowndProvider } from './InternalProvider';\nimport {\n addOnAuthenticatedListener,\n getOnAuthenticatedListeners,\n unsubscribeOnAuthenticatedListener,\n} from '../utils/listeners';\n\nexport const ReactRowndProvider: React.FC<RowndProviderProps> = ({\n children,\n ...props\n}) => {\n const { setInitialHubState, hubListenerCb } = useHub();\n\n const onAuthenticated: (\n callback: (userData: UserDataContext) => void\n ) => () => void = useCallback(\n (callback: (userData: UserDataContext) => void) => {\n const id = addOnAuthenticatedListener(callback);\n\n const unsubscribe = () => {\n unsubscribeOnAuthenticatedListener(id);\n };\n\n return unsubscribe;\n },\n []\n );\n\n const [hubState, setHubState] = React.useState<TRowndContext>({\n ...setInitialHubState(),\n onAuthenticated,\n });\n\n const { user, is_authenticated, is_initializing } = hubState;\n useEffect(() => {\n if (!is_authenticated || is_initializing || !user.data.user_id) {\n return;\n }\n\n getOnAuthenticatedListeners().forEach(({ callback }) =>\n callback(hubState.user.data)\n );\n }, [is_authenticated, is_initializing, user.data.user_id]);\n\n const stateListener = useCallback(({ state, api }: HubListenerProps) => {\n hubListenerCb({ state, api, callback: setHubState })\n }, [hubListenerCb]);\n\n return (\n <InternalRowndProvider\n stateListener={stateListener}\n {...props}\n >\n <RowndContext.Provider value={hubState}>\n <InternalProviderHubScriptInjector />\n {children}\n </RowndContext.Provider>\n </InternalRowndProvider>\n );\n};\n"],"names":["ReactRowndProvider","children","props","setInitialHubState","hubListenerCb","useHub","onAuthenticated","useCallback","callback","id","addOnAuthenticatedListener","unsubscribeOnAuthenticatedListener","hubState","setHubState","React","user","is_authenticated","is_initializing","useEffect","getOnAuthenticatedListeners","stateListener","state","api","InternalRowndProvider","RowndContext","InternalProviderHubScriptInjector"],"mappings":";;;;;;AAYO,MAAMA,IAAmD,CAAC;AAAA,EAC/D,UAAAC;AAAA,EACA,GAAGC;AACL,MAAM;AACJ,QAAM,EAAE,oBAAAC,GAAoB,eAAAC,EAAA,IAAkBC,EAAA,GAExCC,IAEYC;AAAA,IAChB,CAACC,MAAkD;AACjD,YAAMC,IAAKC,EAA2BF,CAAQ;AAM9C,aAJoB,MAAM;AACxB,QAAAG,EAAmCF,CAAE;AAAA,MACvC;AAAA,IAGF;AAAA,IACA,CAAA;AAAA,EAAC,GAGG,CAACG,GAAUC,CAAW,IAAIC,EAAM,SAAwB;AAAA,IAC5D,GAAGX,EAAA;AAAA,IACH,iBAAAG;AAAA,EAAA,CACD,GAEK,EAAE,MAAAS,GAAM,kBAAAC,GAAkB,iBAAAC,EAAA,IAAoBL;AACpD,EAAAM,EAAU,MAAM;AACd,IAAI,CAACF,KAAoBC,KAAmB,CAACF,EAAK,KAAK,WAIvDI,EAAA,EAA8B;AAAA,MAAQ,CAAC,EAAE,UAAAX,EAAA,MACvCA,EAASI,EAAS,KAAK,IAAI;AAAA,IAAA;AAAA,EAE/B,GAAG,CAACI,GAAkBC,GAAiBF,EAAK,KAAK,OAAO,CAAC;AAEzD,QAAMK,IAAgBb,EAAY,CAAC,EAAE,OAAAc,GAAO,KAAAC,QAA4B;AACtE,IAAAlB,EAAc,EAAE,OAAAiB,GAAO,KAAAC,GAAK,UAAUT,GAAa;AAAA,EACrD,GAAG,CAACT,CAAa,CAAC;AAElB,SACE,gBAAAU,EAAA;AAAA,IAACS;AAAA,IAAA;AAAA,MACC,eAAAH;AAAA,MACC,GAAGlB;AAAA,IAAA;AAAA,IAEJ,gBAAAY,EAAA,cAACU,EAAa,UAAb,EAAsB,OAAOZ,EAAA,GAC5B,gBAAAE,EAAA,cAACW,GAAA,IAAkC,GAClCxB,CACH;AAAA,EAAA;AAGN;"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { TRowndContext } from './types';
|
|
3
|
+
|
|
4
|
+
export declare const RowndContext: React.Context<TRowndContext | undefined>;
|
|
5
|
+
export type HubListenerProps = {
|
|
6
|
+
state: any;
|
|
7
|
+
api: any;
|
|
8
|
+
};
|
|
9
|
+
export type SuperTokensConfig = {
|
|
10
|
+
appInfo: {
|
|
11
|
+
appName?: string;
|
|
12
|
+
apiDomain: string;
|
|
13
|
+
apiBasePath?: string;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
export type RowndProviderProps = {
|
|
17
|
+
appKey: string;
|
|
18
|
+
apiUrl?: string;
|
|
19
|
+
supertokens: SuperTokensConfig;
|
|
20
|
+
rootOrigin?: string;
|
|
21
|
+
hubUrlOverride?: string;
|
|
22
|
+
postRegistrationUrl?: string;
|
|
23
|
+
postSignOutRedirect?: string;
|
|
24
|
+
/**
|
|
25
|
+
* API version date string (e.g., '2026-01-21') that controls which Hub features are enabled.
|
|
26
|
+
* Defaults to the current SDK version date for new features.
|
|
27
|
+
* Set to an earlier date to opt-out of newer behaviors.
|
|
28
|
+
*/
|
|
29
|
+
apiVersion?: string;
|
|
30
|
+
children: React.ReactNode;
|
|
31
|
+
};
|
|
32
|
+
declare function useRownd(): TRowndContext;
|
|
33
|
+
export { useRownd };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createContext as t, useContext as e } from "react";
|
|
2
|
+
const n = t(void 0);
|
|
3
|
+
function d() {
|
|
4
|
+
const o = e(n);
|
|
5
|
+
if (o === void 0)
|
|
6
|
+
throw new Error("useRownd must be used within a RowndProvider");
|
|
7
|
+
return o;
|
|
8
|
+
}
|
|
9
|
+
export {
|
|
10
|
+
n as RowndContext,
|
|
11
|
+
d as useRownd
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=RowndContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RowndContext.js","sources":["../../src/context/RowndContext.tsx"],"sourcesContent":["import React, { useContext, createContext } from 'react';\nimport { TRowndContext } from './types';\n\nexport const RowndContext = createContext<TRowndContext | undefined>(undefined);\n\nexport type HubListenerProps = {\n state: any;\n api: any;\n};\n\nexport type SuperTokensConfig = {\n appInfo: {\n appName?: string;\n apiDomain: string;\n apiBasePath?: string;\n };\n};\n\nexport type RowndProviderProps = {\n appKey: string;\n apiUrl?: string;\n supertokens: SuperTokensConfig;\n rootOrigin?: string;\n hubUrlOverride?: string;\n postRegistrationUrl?: string;\n postSignOutRedirect?: string;\n /**\n * API version date string (e.g., '2026-01-21') that controls which Hub features are enabled.\n * Defaults to the current SDK version date for new features.\n * Set to an earlier date to opt-out of newer behaviors.\n */\n apiVersion?: string;\n children: React.ReactNode;\n};\n\nfunction useRownd(): TRowndContext {\n const context = useContext(RowndContext);\n\n if (context === undefined) {\n throw new Error('useRownd must be used within a RowndProvider');\n }\n\n return context;\n}\n\nexport { useRownd };\n"],"names":["RowndContext","createContext","useRownd","context","useContext"],"mappings":";AAGO,MAAMA,IAAeC,EAAyC,MAAS;AAgC9E,SAASC,IAA0B;AACjC,QAAMC,IAAUC,EAAWJ,CAAY;AAEvC,MAAIG,MAAY;AACd,UAAM,IAAI,MAAM,8CAA8C;AAGhE,SAAOA;AACT;"}
|