jazz-tools 0.18.8 → 0.18.10
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/.turbo/turbo-build.log +42 -42
- package/CHANGELOG.md +20 -0
- package/dist/better-auth/auth/client.d.ts +1 -1
- package/dist/better-auth/auth/client.d.ts.map +1 -1
- package/dist/better-auth/auth/client.js.map +1 -1
- package/dist/{chunk-QF3R3C4N.js → chunk-RQHJFPIB.js} +56 -25
- package/dist/{chunk-QF3R3C4N.js.map → chunk-RQHJFPIB.js.map} +1 -1
- package/dist/index.js +1 -1
- package/dist/react/hooks.d.ts +1 -1
- package/dist/react/hooks.d.ts.map +1 -1
- package/dist/react/index.d.ts +1 -1
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +3 -1
- package/dist/react/index.js.map +1 -1
- package/dist/react-core/hooks.d.ts +56 -0
- package/dist/react-core/hooks.d.ts.map +1 -1
- package/dist/react-core/index.js +20 -0
- package/dist/react-core/index.js.map +1 -1
- package/dist/react-core/tests/useAccountWithSelector.test.d.ts +2 -0
- package/dist/react-core/tests/useAccountWithSelector.test.d.ts.map +1 -0
- package/dist/react-native-core/hooks.d.ts +1 -1
- package/dist/react-native-core/hooks.d.ts.map +1 -1
- package/dist/react-native-core/index.js +3 -1
- package/dist/react-native-core/index.js.map +1 -1
- package/dist/testing.js +1 -1
- package/dist/tools/implementation/ContextManager.d.ts +2 -0
- package/dist/tools/implementation/ContextManager.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/better-auth/auth/client.ts +1 -1
- package/src/better-auth/auth/tests/client.test.ts +229 -0
- package/src/react/hooks.tsx +1 -0
- package/src/react/index.ts +1 -0
- package/src/react-core/hooks.ts +84 -0
- package/src/react-core/tests/useAccountWithSelector.test.ts +411 -0
- package/src/react-native-core/hooks.tsx +1 -0
- package/src/tools/implementation/ContextManager.ts +75 -32
- package/src/tools/tests/ContextManager.test.ts +252 -0
package/.turbo/turbo-build.log
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
|
2
|
-
> jazz-tools@0.18.
|
2
|
+
> jazz-tools@0.18.10 build /home/runner/_work/jazz/jazz/packages/jazz-tools
|
3
3
|
> tsup && pnpm types && pnpm build:svelte
|
4
4
|
|
5
5
|
[34mCLI[39m Building entry: {"index":"src/index.ts","testing":"src/testing.ts"}
|
@@ -109,20 +109,20 @@
|
|
109
109
|
[34mESM[39m Build start
|
110
110
|
[32mESM[39m [1mdist/react/ssr.js [22m[32m688.00 B[39m
|
111
111
|
[32mESM[39m [1mdist/react/ssr.js.map [22m[32m1.12 KB[39m
|
112
|
-
[32mESM[39m ⚡️ Build success in
|
113
|
-
[32mESM[39m [1mdist/
|
114
|
-
[32mESM[39m [1mdist/
|
115
|
-
[32mESM[39m
|
116
|
-
[32mESM[39m [1mdist/react-native/testing.js.map [22m[32m176.00 B[39m
|
117
|
-
[32mESM[39m [1mdist/react-native/index.js.map [22m[32m5.68 KB[39m
|
118
|
-
[32mESM[39m [1mdist/react-native/crypto.js.map [22m[32m197.00 B[39m
|
119
|
-
[32mESM[39m ⚡️ Build success in 18ms
|
112
|
+
[32mESM[39m ⚡️ Build success in 26ms
|
113
|
+
[32mESM[39m [1mdist/worker/index.js [22m[32m2.47 KB[39m
|
114
|
+
[32mESM[39m [1mdist/worker/index.js.map [22m[32m5.26 KB[39m
|
115
|
+
[32mESM[39m ⚡️ Build success in 22ms
|
120
116
|
[32mESM[39m [1mdist/tiptap/index.js [22m[32m564.00 B[39m
|
121
117
|
[32mESM[39m [1mdist/tiptap/index.js.map [22m[32m1.21 KB[39m
|
122
118
|
[32mESM[39m ⚡️ Build success in 22ms
|
123
|
-
[32mESM[39m [1mdist/
|
124
|
-
[32mESM[39m [1mdist/
|
125
|
-
[32mESM[39m
|
119
|
+
[32mESM[39m [1mdist/better-auth/auth/client.js [22m[32m4.44 KB[39m
|
120
|
+
[32mESM[39m [1mdist/better-auth/auth/server.js [22m[32m8.36 KB[39m
|
121
|
+
[32mESM[39m [1mdist/better-auth/auth/react.js [22m[32m799.00 B[39m
|
122
|
+
[32mESM[39m [1mdist/better-auth/auth/client.js.map [22m[32m8.24 KB[39m
|
123
|
+
[32mESM[39m [1mdist/better-auth/auth/server.js.map [22m[32m15.29 KB[39m
|
124
|
+
[32mESM[39m [1mdist/better-auth/auth/react.js.map [22m[32m2.04 KB[39m
|
125
|
+
[32mESM[39m ⚡️ Build success in 25ms
|
126
126
|
[32mESM[39m [1mdist/media/index.js [22m[32m236.00 B[39m
|
127
127
|
[32mESM[39m [1mdist/media/index.browser.js [22m[32m2.79 KB[39m
|
128
128
|
[32mESM[39m [1mdist/media/index.native.js [22m[32m2.90 KB[39m
|
@@ -133,67 +133,67 @@
|
|
133
133
|
[32mESM[39m [1mdist/media/index.native.js.map [22m[32m6.09 KB[39m
|
134
134
|
[32mESM[39m [1mdist/media/index.server.js.map [22m[32m6.37 KB[39m
|
135
135
|
[32mESM[39m [1mdist/media/chunk-W3S526L3.js.map [22m[32m16.57 KB[39m
|
136
|
-
[32mESM[39m ⚡️ Build success in
|
137
|
-
[32mESM[39m [1mdist/better-auth/auth/client.js [22m[32m4.44 KB[39m
|
138
|
-
[32mESM[39m [1mdist/better-auth/auth/server.js [22m[32m8.36 KB[39m
|
139
|
-
[32mESM[39m [1mdist/better-auth/auth/react.js [22m[32m799.00 B[39m
|
140
|
-
[32mESM[39m [1mdist/better-auth/auth/client.js.map [22m[32m8.24 KB[39m
|
141
|
-
[32mESM[39m [1mdist/better-auth/auth/react.js.map [22m[32m2.04 KB[39m
|
142
|
-
[32mESM[39m [1mdist/better-auth/auth/server.js.map [22m[32m15.29 KB[39m
|
143
|
-
[32mESM[39m ⚡️ Build success in 29ms
|
144
|
-
[32mESM[39m [1mdist/browser/index.js [22m[32m13.64 KB[39m
|
145
|
-
[32mESM[39m [1mdist/browser/index.js.map [22m[32m29.14 KB[39m
|
146
|
-
[32mESM[39m ⚡️ Build success in 38ms
|
136
|
+
[32mESM[39m ⚡️ Build success in 40ms
|
147
137
|
[32mESM[39m [1mdist/expo/index.js [22m[32m4.68 KB[39m
|
148
138
|
[32mESM[39m [1mdist/expo/testing.js [22m[32m112.00 B[39m
|
149
139
|
[32mESM[39m [1mdist/expo/crypto.js [22m[32m153.00 B[39m
|
150
140
|
[32mESM[39m [1mdist/expo/index.js.map [22m[32m10.23 KB[39m
|
151
141
|
[32mESM[39m [1mdist/expo/testing.js.map [22m[32m168.00 B[39m
|
152
142
|
[32mESM[39m [1mdist/expo/crypto.js.map [22m[32m189.00 B[39m
|
143
|
+
[32mESM[39m ⚡️ Build success in 40ms
|
144
|
+
[32mESM[39m [1mdist/react-native/index.js [22m[32m2.53 KB[39m
|
145
|
+
[32mESM[39m [1mdist/react-native/testing.js [22m[32m120.00 B[39m
|
146
|
+
[32mESM[39m [1mdist/react-native/crypto.js [22m[32m161.00 B[39m
|
147
|
+
[32mESM[39m [1mdist/react-native/index.js.map [22m[32m5.68 KB[39m
|
148
|
+
[32mESM[39m [1mdist/react-native/testing.js.map [22m[32m176.00 B[39m
|
149
|
+
[32mESM[39m [1mdist/react-native/crypto.js.map [22m[32m197.00 B[39m
|
150
|
+
[32mESM[39m ⚡️ Build success in 36ms
|
151
|
+
[32mESM[39m [1mdist/browser/index.js [22m[32m13.64 KB[39m
|
152
|
+
[32mESM[39m [1mdist/browser/index.js.map [22m[32m29.14 KB[39m
|
153
153
|
[32mESM[39m ⚡️ Build success in 41ms
|
154
|
-
[32mESM[39m [1mdist/react-native-core/index.js [22m[
|
154
|
+
[32mESM[39m [1mdist/react-native-core/index.js [22m[32m18.00 KB[39m
|
155
155
|
[32mESM[39m [1mdist/react-native-core/testing.js [22m[32m119.00 B[39m
|
156
156
|
[32mESM[39m [1mdist/react-native-core/crypto.js [22m[32m2.10 KB[39m
|
157
|
+
[32mESM[39m [1mdist/react-native-core/index.js.map [22m[32m36.73 KB[39m
|
157
158
|
[32mESM[39m [1mdist/react-native-core/testing.js.map [22m[32m175.00 B[39m
|
158
159
|
[32mESM[39m [1mdist/react-native-core/crypto.js.map [22m[32m4.25 KB[39m
|
159
|
-
[32mESM[39m
|
160
|
-
[32mESM[39m ⚡️ Build success in 41ms
|
161
|
-
[32mESM[39m [1mdist/react/index.js [22m[32m24.71 KB[39m
|
162
|
-
[32mESM[39m [1mdist/react/testing.js [22m[32m122.00 B[39m
|
163
|
-
[32mESM[39m [1mdist/react/index.js.map [22m[32m53.50 KB[39m
|
164
|
-
[32mESM[39m [1mdist/react/testing.js.map [22m[32m165.00 B[39m
|
165
|
-
[32mESM[39m ⚡️ Build success in 42ms
|
160
|
+
[32mESM[39m ⚡️ Build success in 46ms
|
166
161
|
[32mESM[39m [1mdist/prosemirror/index.js [22m[32m77.63 KB[39m
|
167
162
|
[32mESM[39m [1mdist/prosemirror/index.js.map [22m[32m306.98 KB[39m
|
168
|
-
[32mESM[39m ⚡️ Build success in
|
163
|
+
[32mESM[39m ⚡️ Build success in 49ms
|
164
|
+
[32mESM[39m [1mdist/react/index.js [22m[32m24.76 KB[39m
|
165
|
+
[32mESM[39m [1mdist/react/testing.js [22m[32m122.00 B[39m
|
166
|
+
[32mESM[39m [1mdist/react/index.js.map [22m[32m53.56 KB[39m
|
167
|
+
[32mESM[39m [1mdist/react/testing.js.map [22m[32m165.00 B[39m
|
168
|
+
[32mESM[39m ⚡️ Build success in 49ms
|
169
169
|
[32mESM[39m [1mdist/inspector/index.js [22m[32m69.71 KB[39m
|
170
170
|
[32mESM[39m [1mdist/inspector/index.js.map [22m[32m121.38 KB[39m
|
171
|
-
[32mESM[39m ⚡️ Build success in
|
171
|
+
[32mESM[39m ⚡️ Build success in 61ms
|
172
172
|
[32mESM[39m [1mdist/testing.js [22m[32m7.17 KB[39m
|
173
173
|
[32mESM[39m [1mdist/index.js [22m[32m26.13 KB[39m
|
174
|
-
[32mESM[39m [1mdist/chunk-
|
174
|
+
[32mESM[39m [1mdist/chunk-RQHJFPIB.js [22m[32m169.74 KB[39m
|
175
175
|
[32mESM[39m [1mdist/testing.js.map [22m[32m14.10 KB[39m
|
176
176
|
[32mESM[39m [1mdist/index.js.map [22m[32m52.92 KB[39m
|
177
|
-
[32mESM[39m [1mdist/chunk-
|
178
|
-
[32mESM[39m ⚡️ Build success in
|
179
|
-
[32mESM[39m [1mdist/react-core/index.js [22m[
|
177
|
+
[32mESM[39m [1mdist/chunk-RQHJFPIB.js.map [22m[32m402.59 KB[39m
|
178
|
+
[32mESM[39m ⚡️ Build success in 88ms
|
179
|
+
[32mESM[39m [1mdist/react-core/index.js [22m[32m146.19 KB[39m
|
180
180
|
[32mESM[39m [1mdist/react-core/testing.js [22m[32m1.17 KB[39m
|
181
181
|
[32mESM[39m [1mdist/react-core/chunk-7DYMJ74I.js [22m[32m279.00 B[39m
|
182
|
-
[32mESM[39m [1mdist/react-core/index.js.map [22m[32m399.79 KB[39m
|
183
182
|
[32mESM[39m [1mdist/react-core/testing.js.map [22m[32m1.82 KB[39m
|
184
183
|
[32mESM[39m [1mdist/react-core/chunk-7DYMJ74I.js.map [22m[32m533.00 B[39m
|
185
|
-
[32mESM[39m
|
184
|
+
[32mESM[39m [1mdist/react-core/index.js.map [22m[32m404.45 KB[39m
|
185
|
+
[32mESM[39m ⚡️ Build success in 90ms
|
186
186
|
[32mESM[39m [1mdist/inspector/register-custom-element.js [22m[32m218.00 B[39m
|
187
187
|
[32mESM[39m [1mdist/inspector/register-custom-element.js.map [22m[32m314.00 B[39m
|
188
188
|
[32mESM[39m [1mdist/inspector/custom-element-G6SPZEBR.js [22m[32m1.54 MB[39m
|
189
189
|
[32mESM[39m [1mdist/inspector/custom-element-G6SPZEBR.js.map [22m[32m2.36 MB[39m
|
190
|
-
[32mESM[39m ⚡️ Build success in
|
190
|
+
[32mESM[39m ⚡️ Build success in 122ms
|
191
191
|
|
192
|
-
> jazz-tools@0.18.
|
192
|
+
> jazz-tools@0.18.10 types /home/runner/_work/jazz/jazz/packages/jazz-tools
|
193
193
|
> tsc --outDir dist
|
194
194
|
|
195
195
|
|
196
|
-
> jazz-tools@0.18.
|
196
|
+
> jazz-tools@0.18.10 build:svelte /home/runner/_work/jazz/jazz/packages/jazz-tools
|
197
197
|
> rm -rf dist/svelte && svelte-package -i src/svelte -o dist/svelte --tsconfig tsconfig.svelte.json
|
198
198
|
|
199
199
|
src/svelte -> dist/svelte
|
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,25 @@
|
|
1
1
|
# jazz-tools
|
2
2
|
|
3
|
+
## 0.18.10
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- Updated dependencies [95cc9af]
|
8
|
+
- cojson-transport-ws@0.18.10
|
9
|
+
- cojson@0.18.10
|
10
|
+
- cojson-storage-indexeddb@0.18.10
|
11
|
+
|
12
|
+
## 0.18.9
|
13
|
+
|
14
|
+
### Patch Changes
|
15
|
+
|
16
|
+
- c8167de: fix: improve handling of concurrent authentication attempts in ContextManager
|
17
|
+
- 910b8d6: Added useAccountWithSelector hook for granular account data selection with custom equality checking
|
18
|
+
- Updated dependencies [f058875]
|
19
|
+
- cojson@0.18.9
|
20
|
+
- cojson-storage-indexeddb@0.18.9
|
21
|
+
- cojson-transport-ws@0.18.9
|
22
|
+
|
3
23
|
## 0.18.8
|
4
24
|
|
5
25
|
### Patch Changes
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/better-auth/auth/client.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,iBAAiB,EAEjB,
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/better-auth/auth/client.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,OAAO,EACP,iBAAiB,EAEjB,eAAe,EAChB,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAS9C;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB;;wBAmBC,UAAU,CAAC,OAAO,UAAU,CAAC;;;sCAIvB,eAAe,CAAC,OAAO,CAAC;4CAGlB,iBAAiB;;;;;;;;;;;CA4H1D,CAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/better-auth/auth/client.ts"],"sourcesContent":["import type { BetterAuthClientPlugin } from \"better-auth\";\nimport type {\n
|
1
|
+
{"version":3,"sources":["../../../src/better-auth/auth/client.ts"],"sourcesContent":["import type { BetterAuthClientPlugin } from \"better-auth\";\nimport type {\n Account,\n AuthSecretStorage,\n AuthSetPayload,\n JazzContextType,\n} from \"jazz-tools\";\nimport type { jazzPlugin } from \"./server.js\";\n\nconst SIGNUP_URLS = [\n \"/sign-up\",\n \"/sign-in/social\",\n \"/sign-in/oauth2\",\n \"/email-otp/send-verification-otp\",\n];\n\n/**\n * @example\n * ```ts\n * const auth = betterAuth({\n * plugins: [jazzPluginClient()],\n * });\n * ```\n */\nexport const jazzPluginClient = () => {\n let jazzContext: JazzContextType<Account>;\n let authSecretStorage: AuthSecretStorage;\n let signOutUnsubscription: () => void;\n\n const authenticateOnJazz = async (jazzAuth: AuthSetPayload) => {\n const parsedJazzAuth = {\n ...jazzAuth,\n secretSeed: jazzAuth.secretSeed\n ? Uint8Array.from(jazzAuth.secretSeed)\n : undefined,\n };\n\n await jazzContext.authenticate(parsedJazzAuth);\n await authSecretStorage.set(parsedJazzAuth);\n };\n\n return {\n id: \"jazz-plugin\",\n $InferServerPlugin: {} as ReturnType<typeof jazzPlugin>,\n getActions: ($fetch, $store) => {\n return {\n jazz: {\n setJazzContext: (context: JazzContextType<Account>) => {\n jazzContext = context;\n },\n setAuthSecretStorage: (storage: AuthSecretStorage) => {\n authSecretStorage = storage;\n if (signOutUnsubscription) signOutUnsubscription();\n\n // This is a workaround to logout from Better Auth when user logs out directly from Jazz\n signOutUnsubscription = authSecretStorage.onUpdate(\n (isAuthenticated) => {\n if (isAuthenticated === false) {\n const session = $store.atoms.session?.get();\n if (!session) return;\n\n // if the user logs out from Better Auth, the get session is immediately called\n // so we must wait the next fetched session to understand if we need to call sign-out\n if (session.isPending || session.isRefetching) {\n // listen once for next session's data\n const unsub = $store.atoms.session?.listen((session) => {\n unsub?.();\n // if the session is null, user has been already logged out from Better Auth\n if (session.data !== null) {\n $fetch(\"/sign-out\", { method: \"POST\" });\n }\n });\n }\n // if the session is not pending, it means user logged out from Jazz only\n // so we call the sign-out api\n else {\n $fetch(\"/sign-out\", { method: \"POST\" });\n }\n }\n },\n );\n },\n },\n };\n },\n fetchPlugins: [\n {\n id: \"jazz-plugin\",\n name: \"jazz-plugin\",\n hooks: {\n async onRequest(context) {\n if (\n SIGNUP_URLS.some((url) => context.url.toString().includes(url))\n ) {\n const credentials = await authSecretStorage.get();\n\n if (!credentials) {\n throw new Error(\"Jazz credentials not found\");\n }\n\n context.headers.set(\n \"x-jazz-auth\",\n JSON.stringify({\n accountID: credentials.accountID,\n secretSeed: credentials.secretSeed,\n accountSecret: credentials.accountSecret,\n }),\n );\n }\n },\n async onSuccess(context) {\n if (context.request.url.toString().includes(\"/sign-up\")) {\n await authenticateOnJazz(context.data.jazzAuth);\n return;\n }\n\n if (context.request.url.toString().includes(\"/sign-in/email\")) {\n await authenticateOnJazz(context.data.jazzAuth);\n return;\n }\n\n if (context.request.url.toString().includes(\"/get-session\")) {\n if (context.data === null) {\n if (authSecretStorage.isAuthenticated === true) {\n console.warn(\n \"Jazz is authenticated, but the session is null\",\n );\n }\n return;\n }\n\n if (!context.data?.user) {\n return;\n }\n\n if (authSecretStorage.isAuthenticated === false) {\n console.info(\n \"Jazz is not authenticated, using Better Auth stored credentials\",\n );\n await authenticateOnJazz(context.data.jazzAuth);\n return;\n }\n\n const sessionAccountID = context.data.user.accountID;\n\n const credentials = await authSecretStorage.get();\n\n if (!credentials) {\n throw new Error(\"Jazz credentials not found\");\n }\n\n if (credentials.accountID !== sessionAccountID) {\n console.info(\n \"Jazz credentials mismatch, using Better Auth stored credentials\",\n );\n await authenticateOnJazz(context.data.jazzAuth);\n }\n return;\n }\n\n if (context.request.url.toString().includes(\"/sign-out\")) {\n await jazzContext.logOut();\n return;\n }\n\n if (context.request.url.toString().includes(\"/delete-user\")) {\n await jazzContext.logOut();\n return;\n }\n },\n },\n },\n ],\n } satisfies BetterAuthClientPlugin;\n};\n"],"mappings":"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","names":["session"]}
|
@@ -5366,10 +5366,12 @@ var JazzContextManager = class {
|
|
5366
5366
|
constructor(opts) {
|
5367
5367
|
this.authSecretStorage = new AuthSecretStorage();
|
5368
5368
|
this.keepContextOpen = false;
|
5369
|
+
this.authenticatingAccountID = null;
|
5369
5370
|
this.logOut = async () => {
|
5370
5371
|
if (!this.context || !this.props) {
|
5371
5372
|
return;
|
5372
5373
|
}
|
5374
|
+
this.authenticatingAccountID = null;
|
5373
5375
|
await this.props.onLogOut?.();
|
5374
5376
|
if (this.props.logOutReplacement) {
|
5375
5377
|
await this.props.logOutReplacement();
|
@@ -5399,38 +5401,64 @@ var JazzContextManager = class {
|
|
5399
5401
|
if (!this.props) {
|
5400
5402
|
throw new Error("Props required");
|
5401
5403
|
}
|
5402
|
-
|
5403
|
-
|
5404
|
-
|
5405
|
-
|
5406
|
-
|
5407
|
-
|
5408
|
-
|
5409
|
-
|
5404
|
+
if (this.authenticatingAccountID && this.authenticatingAccountID === credentials.accountID) {
|
5405
|
+
console.info(
|
5406
|
+
"Authentication already in progress for account",
|
5407
|
+
credentials.accountID,
|
5408
|
+
"skipping duplicate request"
|
5409
|
+
);
|
5410
|
+
return;
|
5411
|
+
}
|
5412
|
+
if (this.authenticatingAccountID && this.authenticatingAccountID !== credentials.accountID) {
|
5413
|
+
throw new Error(
|
5414
|
+
`Authentication already in progress for different account (${this.authenticatingAccountID}), cannot authenticate ${credentials.accountID}`
|
5415
|
+
);
|
5416
|
+
}
|
5417
|
+
this.authenticatingAccountID = credentials.accountID;
|
5418
|
+
try {
|
5419
|
+
const prevContext = this.context;
|
5420
|
+
const migratingAnonymousAccount = await this.shouldMigrateAnonymousAccount();
|
5421
|
+
this.keepContextOpen = migratingAnonymousAccount;
|
5422
|
+
await this.createContext(this.props, { credentials }).finally(() => {
|
5423
|
+
this.keepContextOpen = false;
|
5424
|
+
});
|
5425
|
+
if (migratingAnonymousAccount) {
|
5426
|
+
await this.handleAnonymousAccountMigration(prevContext);
|
5427
|
+
}
|
5428
|
+
} finally {
|
5429
|
+
this.authenticatingAccountID = null;
|
5410
5430
|
}
|
5411
5431
|
};
|
5412
5432
|
this.register = async (accountSecret, creationProps) => {
|
5413
5433
|
if (!this.props) {
|
5414
5434
|
throw new Error("Props required");
|
5415
5435
|
}
|
5416
|
-
|
5417
|
-
|
5418
|
-
this.keepContextOpen = migratingAnonymousAccount;
|
5419
|
-
await this.createContext(this.props, {
|
5420
|
-
newAccountProps: {
|
5421
|
-
secret: accountSecret,
|
5422
|
-
creationProps
|
5423
|
-
}
|
5424
|
-
}).finally(() => {
|
5425
|
-
this.keepContextOpen = false;
|
5426
|
-
});
|
5427
|
-
if (migratingAnonymousAccount) {
|
5428
|
-
await this.handleAnonymousAccountMigration(prevContext);
|
5436
|
+
if (this.authenticatingAccountID) {
|
5437
|
+
throw new Error("Authentication already in progress");
|
5429
5438
|
}
|
5430
|
-
|
5431
|
-
|
5439
|
+
this.authenticatingAccountID = "register";
|
5440
|
+
try {
|
5441
|
+
const prevContext = this.context;
|
5442
|
+
const migratingAnonymousAccount = await this.shouldMigrateAnonymousAccount();
|
5443
|
+
this.keepContextOpen = migratingAnonymousAccount;
|
5444
|
+
await this.createContext(this.props, {
|
5445
|
+
newAccountProps: {
|
5446
|
+
secret: accountSecret,
|
5447
|
+
creationProps
|
5448
|
+
}
|
5449
|
+
}).finally(() => {
|
5450
|
+
this.keepContextOpen = false;
|
5451
|
+
});
|
5452
|
+
if (migratingAnonymousAccount) {
|
5453
|
+
await this.handleAnonymousAccountMigration(prevContext);
|
5454
|
+
}
|
5455
|
+
if (this.context && "me" in this.context) {
|
5456
|
+
return this.context.me.$jazz.id;
|
5457
|
+
}
|
5458
|
+
throw new Error("The registration hasn't created a new account");
|
5459
|
+
} finally {
|
5460
|
+
this.authenticatingAccountID = null;
|
5432
5461
|
}
|
5433
|
-
throw new Error("The registration hasn't created a new account");
|
5434
5462
|
};
|
5435
5463
|
this.listeners = /* @__PURE__ */ new Set();
|
5436
5464
|
this.subscribe = (callback) => {
|
@@ -5500,6 +5528,9 @@ var JazzContextManager = class {
|
|
5500
5528
|
getAuthSecretStorage() {
|
5501
5529
|
return this.authSecretStorage;
|
5502
5530
|
}
|
5531
|
+
getAuthenticatingAccountID() {
|
5532
|
+
return this.authenticatingAccountID;
|
5533
|
+
}
|
5503
5534
|
async handleAnonymousAccountMigration(prevContext) {
|
5504
5535
|
if (!this.props) {
|
5505
5536
|
throw new Error("Props required");
|
@@ -5911,4 +5942,4 @@ export {
|
|
5911
5942
|
JazzContextManager
|
5912
5943
|
};
|
5913
5944
|
/* istanbul ignore file -- @preserve */
|
5914
|
-
//# sourceMappingURL=chunk-
|
5945
|
+
//# sourceMappingURL=chunk-RQHJFPIB.js.map
|