feat(login): add onUserFetched plugin hook
The host's access function is memoized on `initialState` and runs
exactly once per commit. Plugins that maintain identity-scoped
caches the access predicate reads from (e.g. an org context cache)
had no way to seed those caches synchronously before the caller's
`setInitialState({currentUser: ...})` fired — any post-commit hydrate
couldn't widen the predicate, leaving the sidebar in a stale view
until the next identity change.
Add `LoginPlugin.onUserFetched(userInfo, ctx)` and call it inside
`fetchUserInfo` after the server confirms identity but before
returning. Also commit the identity to `userAtom` storage here so
localStorage's identity marker is in lockstep with whatever caches
the plugin seeds — the predicate's first evaluation then sees a
consistent view rather than the prior session's data.
Errors thrown from the hook are swallowed and logged; they never
block fetchUserInfo.
This commit is contained in:
@@ -57,6 +57,26 @@ export interface LoginPlugin {
|
||||
userInfo: any,
|
||||
ctx: { request: <T = any>(url: string, options?: any) => Promise<T> }
|
||||
) => Promise<string | null | undefined> | string | null | undefined;
|
||||
/**
|
||||
* Lifecycle hook fired inside `fetchUserInfo` after the server
|
||||
* confirms identity but before any caller (boot path, LoginForm)
|
||||
* commits that identity to `initialState`.
|
||||
*
|
||||
* The host's access function is memoized on `initialState` and
|
||||
* runs exactly once per commit. Plugins that maintain
|
||||
* identity-scoped caches (e.g. an org context cache the access
|
||||
* predicate reads from) MUST seed those caches synchronously
|
||||
* here — any work that happens after the caller's
|
||||
* `setInitialState` won't influence the access predicate until
|
||||
* the next identity change.
|
||||
*
|
||||
* Errors thrown from the hook are swallowed and logged; they
|
||||
* never block fetchUserInfo.
|
||||
*/
|
||||
onUserFetched?: (
|
||||
userInfo: any,
|
||||
ctx: { request: <T = any>(url: string, options?: any) => Promise<T> }
|
||||
) => Promise<void> | void;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user