Files
multica/packages/core/auth/index.ts
Naiyuan Qing f41a0cf423 feat(views): extract packages/views — shared business UI + navigation adapter
- Create NavigationAdapter interface (push, replace, back, pathname, searchParams)
- Create AppLink component replacing next/link in 4 files
- Replace useRouter → useNavigation in 3 files (issue-detail, create-issue, create-workspace)
- Create WebNavigationProvider wrapping Next.js useRouter/usePathname/useSearchParams
- Move ~85 feature UI files (issues, editor, modals, my-issues, skills, runtimes) to packages/views/
- Add store singleton registration pattern (registerAuthStore, registerWorkspaceStore)
- Create data-aware wrappers in packages/views/common/ (ActorAvatar, Markdown)
- Update all app-layer imports to @multica/views/*
- Add @source directive for Tailwind to scan views package
- packages/views/ has zero next/* imports

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-09 11:49:55 +08:00

40 lines
1.2 KiB
TypeScript

export { createAuthStore } from "./store";
export type { AuthStoreOptions, AuthState } from "./store";
import type { createAuthStore as CreateAuthStoreFn } from "./store";
type AuthStoreInstance = ReturnType<typeof CreateAuthStoreFn>;
/** Module-level singleton — set once at app boot via `registerAuthStore()`. */
let _store: AuthStoreInstance | null = null;
/**
* Register the auth store instance created by the app.
* Must be called at boot before any component renders.
*/
export function registerAuthStore(store: AuthStoreInstance) {
_store = store;
}
/**
* Singleton accessor — a Zustand hook backed by the registered instance.
* Supports `useAuthStore(selector)` and `useAuthStore.getState()`.
*/
export const useAuthStore: AuthStoreInstance = new Proxy(
(() => {}) as unknown as AuthStoreInstance,
{
apply(_target, _thisArg, args) {
if (!_store)
throw new Error(
"Auth store not initialised — call registerAuthStore() first",
);
return (_store as unknown as (...a: unknown[]) => unknown)(...args);
},
get(_target, prop) {
// Allow property inspection (HMR/React Refresh) before registration
if (!_store) return undefined;
return Reflect.get(_store, prop);
},
},
);