@molecule/app-react 3.0.1 → 3.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 +108 -53
- package/dist/hooks/useAuth.d.ts +10 -4
- package/dist/hooks/useAuth.d.ts.map +1 -1
- package/dist/hooks/useAuth.js +10 -4
- package/dist/hooks/useAuth.js.map +1 -1
- package/dist/hooks/useChat.d.ts.map +1 -1
- package/dist/hooks/useChat.js +1 -0
- package/dist/hooks/useChat.js.map +1 -1
- package/dist/hooks/useForm.d.ts +7 -4
- package/dist/hooks/useForm.d.ts.map +1 -1
- package/dist/hooks/useForm.js +36 -5
- package/dist/hooks/useForm.js.map +1 -1
- package/dist/hooks/useProfileForm.d.ts.map +1 -1
- package/dist/hooks/useProfileForm.js +48 -11
- package/dist/hooks/useProfileForm.js.map +1 -1
- package/dist/index.d.ts +11 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -3
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +7 -3
- package/dist/types.d.ts.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@ AUTO-GENERATED — DO NOT EDIT THIS FILE.
|
|
|
3
3
|
Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
|
|
4
4
|
Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
|
|
5
5
|
To change this document, edit the module-level JSDoc in src/index.ts.
|
|
6
|
-
Generated: 2026-10-
|
|
6
|
+
Generated: 2026-10-31T13:49:35.490Z
|
|
7
7
|
-->
|
|
8
8
|
|
|
9
9
|
# @molecule/app-react
|
|
@@ -24,6 +24,11 @@ server's saved user. Use its `onSaved` callback to update other query caches
|
|
|
24
24
|
from that response before navigating. Configure the endpoint, method and JSON
|
|
25
25
|
envelope once in `AuthClientConfig`; no page-local session store is needed.
|
|
26
26
|
|
|
27
|
+
**Session restore:** `useAuth().status === 'loading'` is undecided: wait for
|
|
28
|
+
it and redirect only on `status === 'unauthenticated'`. `'unavailable'` keeps
|
|
29
|
+
the session candidate for retry, but `isAuthenticated` can be false and `user`
|
|
30
|
+
can be null. A restore failure other than 401/403 never signs out.
|
|
31
|
+
|
|
27
32
|
> **Auto-generated, AI-first package reference** for the [molecule.dev](https://molecule.dev) ecosystem.
|
|
28
33
|
> It is written to be read by coding agents as much as by people, and is generated from this
|
|
29
34
|
> package's source — edit `src/index.ts` JSDoc, not this file.
|
|
@@ -57,16 +62,21 @@ import { createJWTAuthClient } from '@molecule/app-auth'
|
|
|
57
62
|
const authClient = createJWTAuthClient({ baseURL: '/api' })
|
|
58
63
|
|
|
59
64
|
function Dashboard() {
|
|
60
|
-
const { user,
|
|
65
|
+
const { user, status, logout } = useAuth<{ name?: string }>()
|
|
61
66
|
const { t } = useTranslation()
|
|
62
67
|
const { theme, toggleTheme } = useTheme()
|
|
63
68
|
|
|
64
|
-
if (
|
|
69
|
+
if (status === 'loading') {
|
|
70
|
+
return <p>{t('auth.restoring', undefined, { defaultValue: 'Restoring session...' })}</p>
|
|
71
|
+
}
|
|
72
|
+
if (status === 'unauthenticated') {
|
|
65
73
|
return <p>{t('auth.required', undefined, { defaultValue: 'Please log in.' })}</p>
|
|
66
74
|
}
|
|
67
75
|
return (
|
|
68
76
|
<div style={{ background: theme.colors.background }}>
|
|
69
|
-
<h1>
|
|
77
|
+
<h1>
|
|
78
|
+
{t('greeting.welcome', { name: user?.name ?? '' }, { defaultValue: 'Welcome, {{name}}!' })}
|
|
79
|
+
</h1>
|
|
70
80
|
<button onClick={toggleTheme}>
|
|
71
81
|
{t('theme.toggle', undefined, { defaultValue: 'Toggle theme' })}
|
|
72
82
|
</button>
|
|
@@ -114,7 +124,10 @@ Reactive authentication state snapshot (initialized, authenticated, user, loadin
|
|
|
114
124
|
interface AuthState<T = UserProfile> {
|
|
115
125
|
/**
|
|
116
126
|
* The session's state as one value — render from this instead of combining
|
|
117
|
-
* `initialized`/`authenticated`/`loading`.
|
|
127
|
+
* `initialized`/`authenticated`/`loading`. `'loading'` is undecided, so wait
|
|
128
|
+
* and redirect only on `'unauthenticated'`; `'unavailable'` keeps the candidate
|
|
129
|
+
* for retry and can have a null profile. A restore failure other than 401/403
|
|
130
|
+
* never signs out. See {@link AuthStatus}.
|
|
118
131
|
*/
|
|
119
132
|
status: AuthStatus
|
|
120
133
|
/**
|
|
@@ -122,11 +135,14 @@ interface AuthState<T = UserProfile> {
|
|
|
122
135
|
*/
|
|
123
136
|
initialized: boolean
|
|
124
137
|
/**
|
|
125
|
-
* Whether the
|
|
138
|
+
* Whether the client has an authenticated session. This is not a server
|
|
139
|
+
* confirmation flag: during `'unavailable'` it can be false for a retained
|
|
140
|
+
* token/cookie-only candidate with no cached profile. Use `status` for redirects.
|
|
126
141
|
*/
|
|
127
142
|
authenticated: boolean
|
|
128
143
|
/**
|
|
129
|
-
* Current user
|
|
144
|
+
* Current user, or null when none is cached. In particular, an `'unavailable'`
|
|
145
|
+
* token/cookie-only restore has a retained candidate but no profile yet.
|
|
130
146
|
*/
|
|
131
147
|
user: T | null
|
|
132
148
|
/**
|
|
@@ -180,12 +196,23 @@ interface AuthClient<T = UserProfile, TRegister extends RegisterExtraShape<TRegi
|
|
|
180
196
|
* Updates the cached user object (state + persistent storage) without
|
|
181
197
|
* hitting the network. Intended for local refreshes after a per-app
|
|
182
198
|
* mutation (e.g., the user just PATCHed their own profile and the
|
|
183
|
-
* server returned the canonical row).
|
|
199
|
+
* server returned the canonical row). A non-null profile does NOT change
|
|
200
|
+
* tokens or sign the client in: `authenticated` and `status` are unchanged,
|
|
201
|
+
* so an anonymous client stays anonymous. Use {@link login} /
|
|
202
|
+
* {@link register} for a credential exchange, or {@link setSession} when
|
|
203
|
+
* the token was issued outside the client.
|
|
184
204
|
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
205
|
+
* Passing `null` on a signed-in client, or while any session operation is
|
|
206
|
+
* pending, ends the local session: it clears the access token, refresh token
|
|
207
|
+
* and cached user, stops automatic refresh, and settles `authenticated: false`
|
|
208
|
+
* with `status: 'unauthenticated'` in one notification. Every older operation
|
|
209
|
+
* loses session ownership, and a persistent sign-out marker prevents a reload
|
|
210
|
+
* from restoring its credentials or a late cookie. A late credential exchange
|
|
211
|
+
* is revoked best-effort when a logout endpoint is configured, without blocking
|
|
212
|
+
* the caller. This method does not otherwise call the server for a settled
|
|
213
|
+
* session; use {@link logout} for explicit server revocation. On a settled
|
|
214
|
+
* anonymous client, `null` only clears the cached profile and leaves tokens
|
|
215
|
+
* and auth state unchanged.
|
|
189
216
|
*/
|
|
190
217
|
setUser(user: T | null): void;
|
|
191
218
|
/**
|
|
@@ -200,10 +227,13 @@ interface AuthClient<T = UserProfile, TRegister extends RegisterExtraShape<TRegi
|
|
|
200
227
|
* which would violate the storage contract and make a stored bearer token
|
|
201
228
|
* JS-readable (XSS-exfiltratable). Pass `null` to clear it.
|
|
202
229
|
*
|
|
203
|
-
* This changes token storage only
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
*
|
|
230
|
+
* This changes token storage only: passing `null` does not by itself sign a
|
|
231
|
+
* signed-in client out, and a non-null token does not sign an anonymous
|
|
232
|
+
* client in (`authenticated` and `status` are unchanged). Use {@link logout}
|
|
233
|
+
* to end a session, or {@link setUser} with `null` for local-only sign-out.
|
|
234
|
+
* Use {@link login} / {@link register} for a credential exchange, or call
|
|
235
|
+
* {@link setSession} with the token and user to establish an already-issued
|
|
236
|
+
* session.
|
|
207
237
|
*/
|
|
208
238
|
setAccessToken(token: string | null): void;
|
|
209
239
|
/**
|
|
@@ -228,7 +258,16 @@ interface AuthClient<T = UserProfile, TRegister extends RegisterExtraShape<TRegi
|
|
|
228
258
|
*/
|
|
229
259
|
login(credentials: LoginCredentials): Promise<AuthResult<T>>;
|
|
230
260
|
/**
|
|
231
|
-
* Logs out the current user.
|
|
261
|
+
* Logs out the current user. The server request is best-effort: a missing
|
|
262
|
+
* logout route (404), any other HTTP failure, or a network error never makes
|
|
263
|
+
* this method reject. It always clears the access token, refresh token and
|
|
264
|
+
* cached user, stops automatic refresh, and publishes one settled
|
|
265
|
+
* `authenticated: false`, `status: 'unauthenticated'` transition. Every pending
|
|
266
|
+
* session operation loses ownership; a persistent marker prevents reload from
|
|
267
|
+
* restoring an older session, and late credentials are revoked best-effort.
|
|
268
|
+
*
|
|
269
|
+
* When the API has no logout route, set {@link AuthClientConfigOptions.logoutEndpoint}
|
|
270
|
+
* to `null` (or `''`) to skip the request. Local sign-out still happens.
|
|
232
271
|
*/
|
|
233
272
|
logout(): Promise<void>;
|
|
234
273
|
/**
|
|
@@ -280,37 +319,6 @@ interface AuthClient<T = UserProfile, TRegister extends RegisterExtraShape<TRegi
|
|
|
280
319
|
* until the cookie restore decides.
|
|
281
320
|
*
|
|
282
321
|
* Do not put this call (or a `/me` request of your own) in front of the first
|
|
283
|
-
* render, and do not render a loading screen over a session it just restored:
|
|
284
|
-
* `whenRestored()` already resolves as soon as the restore has settled, and the
|
|
285
|
-
* HTTP gate built on it holds requests for exactly that window.
|
|
286
|
-
*/
|
|
287
|
-
initialize(): Promise<void>;
|
|
288
|
-
/**
|
|
289
|
-
* Re-checks a restored session against the server, in the background — the
|
|
290
|
-
* boot-time validation an app with a stored token needs when a revoked or
|
|
291
|
-
* expired token must sign the user out. Call it AFTER the first render
|
|
292
|
-
* (`initialize()` restores synchronously from storage; this costs one request).
|
|
293
|
-
*
|
|
294
|
-
* - The server confirms the user: the session is refreshed and {@link AuthState.status}
|
|
295
|
-
* stays `'authenticated'`.
|
|
296
|
-
* - The server answers 401 or 403: the token is dead — the stored session is
|
|
297
|
-
* cleared and the status becomes `'unauthenticated'`.
|
|
298
|
-
* - The server cannot confirm the session — a network failure, a 5xx, or a 404
|
|
299
|
-
* from a misconfigured {@link AuthClientConfig.currentUserEndpoint}: the
|
|
300
|
-
* session (token AND user) is KEPT and the status becomes `'unavailable'`, so
|
|
301
|
-
* the app can retry instead of signing the user out over a bad connection or a
|
|
302
|
-
* route that does not exist. The 404 error names `currentUserEndpoint`.
|
|
303
|
-
*
|
|
304
|
-
* Do not hand-write this beside the client: a parallel token/user store for a
|
|
305
|
-
* "validating"/"unavailable" flag is the race this method removes.
|
|
306
|
-
*
|
|
307
|
-
* Optional: a provider with no restorable session has nothing to validate.
|
|
308
|
-
*/
|
|
309
|
-
validateSession?(): Promise<void>;
|
|
310
|
-
/**
|
|
311
|
-
* Resolves when the session restore started by `initialize()` has settled — the point
|
|
312
|
-
* after which the client knows whether this visitor is signed in.
|
|
313
|
-
*
|
|
314
322
|
// … truncated — the full declaration is in node_modules/@molecule/app-react/dist
|
|
315
323
|
```
|
|
316
324
|
|
|
@@ -399,9 +407,20 @@ interface FormController<T extends FormValuesConstraint<T> = Record<string, unkn
|
|
|
399
407
|
* `defaultValues`, or the values a previous `reset(values)` established.
|
|
400
408
|
* Passing `values` merges them over the current baseline and makes the
|
|
401
409
|
* result the new baseline, so a form reset to freshly loaded or saved data
|
|
402
|
-
* reads clean (`isDirty === false`).
|
|
410
|
+
* reads clean (`isDirty === false`). A changed non-null `id` replaces the
|
|
411
|
+
* record and cancels a pending submit.
|
|
403
412
|
*/
|
|
404
413
|
reset(values?: Partial<T>): void
|
|
414
|
+
/**
|
|
415
|
+
* Applies externally loaded values without clearing submission state.
|
|
416
|
+
*
|
|
417
|
+
* The new clean baseline is the original `defaultValues` plus this latest
|
|
418
|
+
* record, never a merge of earlier records. With `keepDirtyValues`, edited
|
|
419
|
+
* fields retain their values while pristine fields take the loaded values.
|
|
420
|
+
* A changed non-null `id` still replaces the record and cancels a pending
|
|
421
|
+
* submit. Equal-content baselines cause no update.
|
|
422
|
+
*/
|
|
423
|
+
updateValues(values: Partial<T>, resetOptions?: FormResetOptions): void
|
|
405
424
|
/**
|
|
406
425
|
* Handles form submission.
|
|
407
426
|
*/
|
|
@@ -424,6 +443,21 @@ interface FormController<T extends FormValuesConstraint<T> = Record<string, unkn
|
|
|
424
443
|
}
|
|
425
444
|
```
|
|
426
445
|
|
|
446
|
+
#### `FormResetOptions`
|
|
447
|
+
|
|
448
|
+
Options controlling how externally supplied values replace a form's baseline.
|
|
449
|
+
|
|
450
|
+
```typescript
|
|
451
|
+
interface FormResetOptions {
|
|
452
|
+
/**
|
|
453
|
+
* Keep fields whose current value differs from their baseline when `values`
|
|
454
|
+
* changes. Pristine fields still take the new values. False by default, so a
|
|
455
|
+
* new record can replace edits from the previous record.
|
|
456
|
+
*/
|
|
457
|
+
keepDirtyValues?: boolean
|
|
458
|
+
}
|
|
459
|
+
```
|
|
460
|
+
|
|
427
461
|
#### `FormOptions`
|
|
428
462
|
|
|
429
463
|
Form creation options.
|
|
@@ -435,6 +469,14 @@ interface FormOptions<T extends FormValuesConstraint<T>> {
|
|
|
435
469
|
* is created. Mutating this object afterwards does not change the baseline.
|
|
436
470
|
*/
|
|
437
471
|
defaultValues?: Partial<T>
|
|
472
|
+
/**
|
|
473
|
+
* Externally loaded values, merged over `defaultValues` as the clean
|
|
474
|
+
* baseline. Framework bindings also apply later content changes; use
|
|
475
|
+
* `resetOptions.keepDirtyValues` to preserve edits while pristine fields fill.
|
|
476
|
+
*/
|
|
477
|
+
values?: Partial<T>
|
|
478
|
+
/** Controls how framework bindings apply changed `values`. */
|
|
479
|
+
resetOptions?: FormResetOptions
|
|
438
480
|
/**
|
|
439
481
|
* Validation mode.
|
|
440
482
|
*/
|
|
@@ -877,8 +919,11 @@ interface UseFormResult<T extends FormValuesConstraint<T>> {
|
|
|
877
919
|
clearErrors: () => void
|
|
878
920
|
|
|
879
921
|
// Form methods
|
|
880
|
-
handleSubmit: (
|
|
922
|
+
handleSubmit: (
|
|
923
|
+
onSubmit: (values: T) => void | Promise<void>,
|
|
924
|
+
) => (event?: React.FormEvent) => Promise<void>
|
|
881
925
|
reset: (values?: Partial<T>) => void
|
|
926
|
+
updateValues: (values: Partial<T>, resetOptions?: FormResetOptions) => void
|
|
882
927
|
validate: () => Promise<boolean>
|
|
883
928
|
}
|
|
884
929
|
```
|
|
@@ -1479,7 +1524,9 @@ interface UseAuthResult<
|
|
|
1479
1524
|
* The session state as one value — render from this instead of combining
|
|
1480
1525
|
* `initialized`/`authenticated`/`loading`. A stored token AND user make it
|
|
1481
1526
|
* `'authenticated'` on the first render; only `'loading'` means "no decision
|
|
1482
|
-
* yet", so a route guard waits on that and nothing else.
|
|
1527
|
+
* yet", so a route guard waits on that and nothing else. `'unavailable'` keeps
|
|
1528
|
+
* a session candidate for retry and can have a null profile; redirect only on
|
|
1529
|
+
* `'unauthenticated'`.
|
|
1483
1530
|
*/
|
|
1484
1531
|
status: AuthState<T>['status']
|
|
1485
1532
|
state: AuthState<T>
|
|
@@ -1499,8 +1546,10 @@ interface UseAuthResult<
|
|
|
1499
1546
|
* `authenticated` read signed out.
|
|
1500
1547
|
*/
|
|
1501
1548
|
setSession: AuthClient<T>['setSession']
|
|
1549
|
+
/** Whether a session is authenticated locally; this can be false while unavailable. */
|
|
1502
1550
|
isAuthenticated: boolean
|
|
1503
1551
|
isLoading: boolean
|
|
1552
|
+
/** The cached profile, which can be null while an unavailable candidate is retained. */
|
|
1504
1553
|
user: T | null
|
|
1505
1554
|
}
|
|
1506
1555
|
```
|
|
@@ -1980,6 +2029,12 @@ function useAuthClient<
|
|
|
1980
2029
|
|
|
1981
2030
|
Hook for authentication state and actions.
|
|
1982
2031
|
|
|
2032
|
+
`status === 'loading'` is undecided: wait for it and redirect only on
|
|
2033
|
+
`status === 'unauthenticated'`. `'unavailable'` keeps the session candidate
|
|
2034
|
+
for retry, but `isAuthenticated` can be false and `user` can be null while a
|
|
2035
|
+
token/cookie-only restore has no cached profile. A restore failure other than
|
|
2036
|
+
401/403 never signs out.
|
|
2037
|
+
|
|
1983
2038
|
Pass the app's user type — the SAME type used for the auth client and its
|
|
1984
2039
|
config (`createJWTAuthClient<MyUser>`, `AuthClientConfig<MyUser>`) — so
|
|
1985
2040
|
`user` and `setSession`/`setUser` are typed for the pages:
|
|
@@ -2183,7 +2238,7 @@ function useForm<T extends FormValuesConstraint<T> = Record<string, unknown>>(
|
|
|
2183
2238
|
): UseFormResult<T>
|
|
2184
2239
|
```
|
|
2185
2240
|
|
|
2186
|
-
- `options` — Form options. `defaultValues`, `mode` and the form-level `validate` are forwarded to the provider;
|
|
2241
|
+
- `options` — Form options. `defaultValues`, `mode` and the form-level `validate` are forwarded to the provider. When `values` changes by content, it becomes the new baseline; `resetOptions.keepDirtyValues` retains edited fields while pristine fields take the loaded values. Omit the options entirely for a form whose fields are registered with their own defaults.
|
|
2187
2242
|
|
|
2188
2243
|
**Returns:** Form state and methods
|
|
2189
2244
|
|
|
@@ -3250,7 +3305,7 @@ Peer dependencies:
|
|
|
3250
3305
|
|
|
3251
3306
|
- `@molecule/app-auth` ^3.0.0
|
|
3252
3307
|
- `@molecule/app-ai-models` ^1.0.1
|
|
3253
|
-
- `@molecule/app-forms` ^2.
|
|
3308
|
+
- `@molecule/app-forms` ^2.2.0
|
|
3254
3309
|
- `@molecule/app-utilities` ^1.0.1
|
|
3255
3310
|
- `@molecule/app-http` ^1.0.1
|
|
3256
3311
|
- `@molecule/app-i18n` ^1.0.1
|
package/dist/hooks/useAuth.d.ts
CHANGED
|
@@ -19,6 +19,12 @@ export declare function useAuthClient<T = unknown, TRegister extends RegisterExt
|
|
|
19
19
|
/**
|
|
20
20
|
* Hook for authentication state and actions.
|
|
21
21
|
*
|
|
22
|
+
* `status === 'loading'` is undecided: wait for it and redirect only on
|
|
23
|
+
* `status === 'unauthenticated'`. `'unavailable'` keeps the session candidate
|
|
24
|
+
* for retry, but `isAuthenticated` can be false and `user` can be null while a
|
|
25
|
+
* token/cookie-only restore has no cached profile. A restore failure other than
|
|
26
|
+
* 401/403 never signs out.
|
|
27
|
+
*
|
|
22
28
|
* Pass the app's user type — the SAME type used for the auth client and its
|
|
23
29
|
* config (`createJWTAuthClient<MyUser>`, `AuthClientConfig<MyUser>`) — so
|
|
24
30
|
* `user` and `setSession`/`setUser` are typed for the pages:
|
|
@@ -44,13 +50,13 @@ export declare function useAuthClient<T = unknown, TRegister extends RegisterExt
|
|
|
44
50
|
*
|
|
45
51
|
* @example
|
|
46
52
|
* ```tsx
|
|
47
|
-
* const { user,
|
|
53
|
+
* const { user, status, login, logout } = useAuth<{ id: string; name?: string }>()
|
|
48
54
|
* const { register } = useAuth<MyUser, { username: string }>()
|
|
49
55
|
* await register({ email, password, username }) // `username` is typed
|
|
50
56
|
*
|
|
51
|
-
* if (
|
|
52
|
-
*
|
|
53
|
-
* }
|
|
57
|
+
* if (status === 'loading') return <p>Restoring session...</p>
|
|
58
|
+
* if (status === 'unauthenticated') return <Navigate to="/login" replace />
|
|
59
|
+
* return <div>Welcome, {user?.name}!</div>
|
|
54
60
|
* ```
|
|
55
61
|
*/
|
|
56
62
|
export declare function useAuth<T = unknown, TRegister extends RegisterExtraShape<TRegister> = Record<never, never>>(options?: UseAuthOptions): UseAuthResult<T, TRegister>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAuth.d.ts","sourceRoot":"","sources":["../../src/hooks/useAuth.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,EACV,UAAU,EAKV,kBAAkB,EACnB,MAAM,oBAAoB,CAAA;AAI3B,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAEhE;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAC3B,CAAC,GAAG,OAAO,EACX,SAAS,SAAS,kBAAkB,CAAC,SAAS,CAAC,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,KACnE,UAAU,CAAC,CAAC,EAAE,SAAS,CAAC,CAU5B;AAED
|
|
1
|
+
{"version":3,"file":"useAuth.d.ts","sourceRoot":"","sources":["../../src/hooks/useAuth.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,EACV,UAAU,EAKV,kBAAkB,EACnB,MAAM,oBAAoB,CAAA;AAI3B,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAEhE;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAC3B,CAAC,GAAG,OAAO,EACX,SAAS,SAAS,kBAAkB,CAAC,SAAS,CAAC,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,KACnE,UAAU,CAAC,CAAC,EAAE,SAAS,CAAC,CAU5B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,wBAAgB,OAAO,CACrB,CAAC,GAAG,OAAO,EACX,SAAS,SAAS,kBAAkB,CAAC,SAAS,CAAC,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,EACtE,OAAO,CAAC,EAAE,cAAc,GAAG,aAAa,CAAC,CAAC,EAAE,SAAS,CAAC,CA2EvD;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,CAAC,GAAG,OAAO,KAAK,CAAC,GAAG,IAAI,CAG/C;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,IAAI,OAAO,CAG5C"}
|
package/dist/hooks/useAuth.js
CHANGED
|
@@ -28,6 +28,12 @@ export function useAuthClient() {
|
|
|
28
28
|
/**
|
|
29
29
|
* Hook for authentication state and actions.
|
|
30
30
|
*
|
|
31
|
+
* `status === 'loading'` is undecided: wait for it and redirect only on
|
|
32
|
+
* `status === 'unauthenticated'`. `'unavailable'` keeps the session candidate
|
|
33
|
+
* for retry, but `isAuthenticated` can be false and `user` can be null while a
|
|
34
|
+
* token/cookie-only restore has no cached profile. A restore failure other than
|
|
35
|
+
* 401/403 never signs out.
|
|
36
|
+
*
|
|
31
37
|
* Pass the app's user type — the SAME type used for the auth client and its
|
|
32
38
|
* config (`createJWTAuthClient<MyUser>`, `AuthClientConfig<MyUser>`) — so
|
|
33
39
|
* `user` and `setSession`/`setUser` are typed for the pages:
|
|
@@ -53,13 +59,13 @@ export function useAuthClient() {
|
|
|
53
59
|
*
|
|
54
60
|
* @example
|
|
55
61
|
* ```tsx
|
|
56
|
-
* const { user,
|
|
62
|
+
* const { user, status, login, logout } = useAuth<{ id: string; name?: string }>()
|
|
57
63
|
* const { register } = useAuth<MyUser, { username: string }>()
|
|
58
64
|
* await register({ email, password, username }) // `username` is typed
|
|
59
65
|
*
|
|
60
|
-
* if (
|
|
61
|
-
*
|
|
62
|
-
* }
|
|
66
|
+
* if (status === 'loading') return <p>Restoring session...</p>
|
|
67
|
+
* if (status === 'unauthenticated') return <Navigate to="/login" replace />
|
|
68
|
+
* return <div>Welcome, {user?.name}!</div>
|
|
63
69
|
* ```
|
|
64
70
|
*/
|
|
65
71
|
export function useAuth(options) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAuth.js","sourceRoot":"","sources":["../../src/hooks/useAuth.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAA;AAUxF,OAAO,EAAE,CAAC,EAAE,MAAM,oBAAoB,CAAA;AAEtC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAG5C;;;;;;;;;GASG;AACH,MAAM,UAAU,aAAa;IAI3B,MAAM,MAAM,GAAG,UAAU,CAAC,WAAW,CAAC,CAAA;IACtC,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CACb,CAAC,CAAC,oCAAoC,EAAE,SAAS,EAAE;YACjD,YAAY,EAAE,mDAAmD;SAClE,CAAC,CACH,CAAA;IACH,CAAC;IACD,OAAO,MAAkC,CAAA;AAC3C,CAAC;AAED
|
|
1
|
+
{"version":3,"file":"useAuth.js","sourceRoot":"","sources":["../../src/hooks/useAuth.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAA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G,WAAW,EAAE,CAc1F;AAiBD;;;;;;;;;;;;GAYG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,WAAW,EAAE,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,WAAW,EAAE,CAQ5F;AAyDD;;;;GAIG;AACH,wBAAgB,uBAAuB,IAAI,IAAI,CAK9C;AAED;;;;GAIG;AACH,wBAAgB,eAAe,IAAI,YAAY,CAU9C;AAkDD;;;;;;;;GAQG;AACH,wBAAgB,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,aAAa,
|
|
1
|
+
{"version":3,"file":"useChat.d.ts","sourceRoot":"","sources":["../../src/hooks/useChat.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAYH,OAAO,KAAK,EAIV,WAAW,EACX,YAAY,EAGb,MAAM,uBAAuB,CAAA;AAK9B,OAAO,KAAK,EAAsB,cAAc,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AA8cpF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,WAAW,EAAE,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,WAAW,EAAE,CAc1F;AAiBD;;;;;;;;;;;;GAYG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,WAAW,EAAE,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,WAAW,EAAE,CAQ5F;AAyDD;;;;GAIG;AACH,wBAAgB,uBAAuB,IAAI,IAAI,CAK9C;AAED;;;;GAIG;AACH,wBAAgB,eAAe,IAAI,YAAY,CAU9C;AAkDD;;;;;;;;GAQG;AACH,wBAAgB,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,aAAa,CAo4E9D"}
|
package/dist/hooks/useChat.js
CHANGED
|
@@ -1519,6 +1519,7 @@ export function useChat(options) {
|
|
|
1519
1519
|
type: 'verification',
|
|
1520
1520
|
status: event.status,
|
|
1521
1521
|
...(event.output ? { output: event.output } : {}),
|
|
1522
|
+
...(event.renderCheckUnavailable ? { renderCheckUnavailable: true } : {}),
|
|
1522
1523
|
workspaces: event.workspaces,
|
|
1523
1524
|
...(event.categories ? { categories: event.categories } : {}),
|
|
1524
1525
|
});
|