@korajs/auth 0.4.0 → 0.6.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/dist/react.js CHANGED
@@ -1,5 +1,13 @@
1
+ import {
2
+ checkOrgPermission,
3
+ createAuthSession,
4
+ createOrgMembersActions,
5
+ createOrgSession,
6
+ loadOrgMembers
7
+ } from "./chunk-7OXBRSJL.js";
8
+
1
9
  // src/react/AuthProvider.tsx
2
- import { createElement, useEffect, useState } from "react";
10
+ import { createElement, useEffect, useMemo, useSyncExternalStore } from "react";
3
11
 
4
12
  // src/react/auth-context.ts
5
13
  import { createContext } from "react";
@@ -7,35 +15,14 @@ var AuthContext = createContext(null);
7
15
 
8
16
  // src/react/AuthProvider.tsx
9
17
  function AuthProvider({ client, children, fallback }) {
10
- const [state, setState] = useState(client.state);
11
- const [isLoading, setIsLoading] = useState(true);
12
- const [initError, setInitError] = useState(null);
13
- useEffect(() => {
14
- let cancelled = false;
15
- const unsubscribe = client.onAuthChange((newState) => {
16
- if (!cancelled) {
17
- setState(newState);
18
- }
19
- });
20
- client.initialize().then(() => {
21
- if (!cancelled) {
22
- setState(client.state);
23
- setIsLoading(false);
24
- }
25
- }).catch((error) => {
26
- if (!cancelled) {
27
- const err = error instanceof Error ? error : new Error(String(error));
28
- console.error("[Kora Auth] Initialization failed:", err);
29
- setInitError(err);
30
- setIsLoading(false);
31
- }
32
- });
33
- return () => {
34
- cancelled = true;
35
- unsubscribe();
36
- };
37
- }, [client]);
38
- if (initError) {
18
+ const session = useMemo(() => createAuthSession(client), [client]);
19
+ useEffect(() => () => session.destroy(), [session]);
20
+ const snapshot = useSyncExternalStore(
21
+ (onStoreChange) => session.subscribe(onStoreChange),
22
+ () => session.getSnapshot(),
23
+ () => session.getSnapshot()
24
+ );
25
+ if (snapshot.initError) {
39
26
  return createElement(
40
27
  "div",
41
28
  {
@@ -43,22 +30,23 @@ function AuthProvider({ client, children, fallback }) {
43
30
  role: "alert"
44
31
  },
45
32
  createElement("strong", null, "Kora Auth initialization error: "),
46
- initError.message
33
+ snapshot.initError.message
47
34
  );
48
35
  }
49
- if (isLoading && fallback !== void 0) {
36
+ if (snapshot.isLoading && fallback !== void 0) {
50
37
  return fallback;
51
38
  }
52
39
  const contextValue = {
53
40
  client,
54
- state,
55
- isLoading
41
+ session,
42
+ state: snapshot.state,
43
+ isLoading: snapshot.isLoading
56
44
  };
57
45
  return createElement(AuthContext.Provider, { value: contextValue }, children);
58
46
  }
59
47
 
60
48
  // src/react/hooks.ts
61
- import { useCallback, useContext, useRef, useState as useState2, useSyncExternalStore } from "react";
49
+ import { useContext, useSyncExternalStore as useSyncExternalStore2 } from "react";
62
50
  function useAuthContext() {
63
51
  const ctx = useContext(AuthContext);
64
52
  if (ctx === null) {
@@ -68,113 +56,58 @@ function useAuthContext() {
68
56
  }
69
57
  return ctx;
70
58
  }
71
- function useAuth() {
72
- const { client, state, isLoading } = useAuthContext();
73
- const [error, setError] = useState2(null);
74
- const userSnapshotRef = useRef(client.currentUser);
75
- const stateSerializedRef = useRef(JSON.stringify(client.currentUser));
76
- const subscribe = useCallback(
77
- (onStoreChange) => {
78
- return client.onAuthChange(() => {
79
- const newUser = client.currentUser;
80
- const newSerialized = JSON.stringify(newUser);
81
- if (newSerialized !== stateSerializedRef.current) {
82
- userSnapshotRef.current = newUser;
83
- stateSerializedRef.current = newSerialized;
84
- onStoreChange();
85
- }
86
- });
87
- },
88
- [client]
89
- );
90
- const getSnapshot = useCallback(() => {
91
- return userSnapshotRef.current;
92
- }, []);
93
- const user = useSyncExternalStore(subscribe, getSnapshot);
94
- const signUp = useCallback(
95
- async (params) => {
96
- setError(null);
97
- try {
98
- await client.signUp(params);
99
- } catch (err) {
100
- const message = err instanceof Error ? err.message : String(err);
101
- setError(message);
102
- }
103
- },
104
- [client]
105
- );
106
- const signIn = useCallback(
107
- async (params) => {
108
- setError(null);
109
- try {
110
- await client.signIn(params);
111
- } catch (err) {
112
- const message = err instanceof Error ? err.message : String(err);
113
- setError(message);
114
- }
115
- },
116
- [client]
59
+ function useAuthSessionSnapshot() {
60
+ const { session } = useAuthContext();
61
+ return useSyncExternalStore2(
62
+ (onStoreChange) => session.subscribe(onStoreChange),
63
+ () => session.getSnapshot(),
64
+ () => session.getSnapshot()
117
65
  );
118
- const signOut = useCallback(async () => {
119
- setError(null);
120
- try {
121
- await client.signOut();
122
- } catch (err) {
123
- const message = err instanceof Error ? err.message : String(err);
124
- setError(message);
125
- }
126
- }, [client]);
66
+ }
67
+ function useAuth() {
68
+ const { session } = useAuthContext();
69
+ const snapshot = useAuthSessionSnapshot();
127
70
  return {
128
- user,
129
- isAuthenticated: state === "authenticated",
130
- isLoading,
131
- signUp,
132
- signIn,
133
- signOut,
134
- error
71
+ user: snapshot.user,
72
+ isAuthenticated: snapshot.isAuthenticated,
73
+ isLoading: snapshot.isLoading,
74
+ error: snapshot.error,
75
+ initError: snapshot.initError,
76
+ signUp: (params) => session.signUp(params),
77
+ signIn: (params) => session.signIn(params),
78
+ signInWithOAuth: (provider, options) => session.signInWithOAuth(provider, options),
79
+ completeOAuthSignIn: (provider, params) => session.completeOAuthSignIn(provider, params),
80
+ getOAuthAuthorizationUrl: (provider, options) => session.getOAuthAuthorizationUrl(provider, options),
81
+ linkOAuth: (provider, params) => session.linkOAuth(provider, params),
82
+ listLinkedAccounts: () => session.listLinkedAccounts(),
83
+ unlinkOAuth: (provider) => session.unlinkOAuth(provider),
84
+ signOut: () => session.signOut()
135
85
  };
136
86
  }
137
87
  function useCurrentUser() {
138
- const { client } = useAuthContext();
139
- const userSnapshotRef = useRef(client.currentUser);
140
- const stateSerializedRef = useRef(JSON.stringify(client.currentUser));
141
- const subscribe = useCallback(
142
- (onStoreChange) => {
143
- return client.onAuthChange(() => {
144
- const newUser = client.currentUser;
145
- const newSerialized = JSON.stringify(newUser);
146
- if (newSerialized !== stateSerializedRef.current) {
147
- userSnapshotRef.current = newUser;
148
- stateSerializedRef.current = newSerialized;
149
- onStoreChange();
150
- }
151
- });
152
- },
153
- [client]
154
- );
155
- const getSnapshot = useCallback(() => {
156
- return userSnapshotRef.current;
157
- }, []);
158
- return useSyncExternalStore(subscribe, getSnapshot);
88
+ return useAuthSessionSnapshot().user;
159
89
  }
160
90
  function useAuthStatus() {
161
- const { state, isLoading } = useAuthContext();
91
+ const snapshot = useAuthSessionSnapshot();
162
92
  return {
163
- state,
164
- isAuthenticated: state === "authenticated",
165
- isLoading
93
+ state: snapshot.state,
94
+ isAuthenticated: snapshot.isAuthenticated,
95
+ isLoading: snapshot.isLoading
166
96
  };
167
97
  }
168
98
 
99
+ // src/react/OrgProvider.tsx
100
+ import { useEffect as useEffect3, useMemo as useMemo2, useRef as useRef2 } from "react";
101
+
169
102
  // src/react/org-hooks.ts
170
103
  import {
171
104
  createContext as createContext2,
172
- useCallback as useCallback2,
105
+ useCallback,
173
106
  useContext as useContext2,
174
- useEffect as useEffect3,
175
- useRef as useRef2,
176
- useState as useState3,
177
- useSyncExternalStore as useSyncExternalStore2
107
+ useEffect as useEffect2,
108
+ useRef,
109
+ useState,
110
+ useSyncExternalStore as useSyncExternalStore3
178
111
  } from "react";
179
112
  var OrgContext = createContext2(null);
180
113
  function useOrgContext() {
@@ -186,30 +119,25 @@ function useOrgContext() {
186
119
  }
187
120
  return ctx;
188
121
  }
189
- function useOrg() {
190
- const { client } = useOrgContext();
191
- const [error, setError] = useState3(null);
192
- const orgSnapshotRef = useRef2({
193
- orgId: client.activeOrgId,
194
- org: client.activeOrg,
195
- role: client.activeRole
196
- });
197
- const subscribe = useCallback2(
122
+ function useOrgSnapshot(session) {
123
+ const snapshotRef = useRef(session.getSnapshot());
124
+ const subscribe = useCallback(
198
125
  (onStoreChange) => {
199
- return client.onOrgChange(() => {
200
- orgSnapshotRef.current = {
201
- orgId: client.activeOrgId,
202
- org: client.activeOrg,
203
- role: client.activeRole
204
- };
126
+ return session.subscribe(() => {
127
+ snapshotRef.current = session.getSnapshot();
205
128
  onStoreChange();
206
129
  });
207
130
  },
208
- [client]
131
+ [session]
209
132
  );
210
- const getSnapshot = useCallback2(() => orgSnapshotRef.current, []);
211
- const { orgId, org, role } = useSyncExternalStore2(subscribe, getSnapshot);
212
- const switchOrg = useCallback2(
133
+ const getSnapshot = useCallback(() => snapshotRef.current, []);
134
+ return useSyncExternalStore3(subscribe, getSnapshot);
135
+ }
136
+ function useOrg() {
137
+ const { client, session } = useOrgContext();
138
+ const { orgId, org, role } = useOrgSnapshot(session);
139
+ const [error, setError] = useState(null);
140
+ const switchOrg = useCallback(
213
141
  async (newOrgId) => {
214
142
  setError(null);
215
143
  try {
@@ -220,7 +148,7 @@ function useOrg() {
220
148
  },
221
149
  [client]
222
150
  );
223
- const createOrg = useCallback2(
151
+ const createOrg = useCallback(
224
152
  async (params) => {
225
153
  setError(null);
226
154
  try {
@@ -233,7 +161,7 @@ function useOrg() {
233
161
  },
234
162
  [client]
235
163
  );
236
- const leaveOrg = useCallback2(async () => {
164
+ const leaveOrg = useCallback(async () => {
237
165
  if (!orgId) return;
238
166
  setError(null);
239
167
  try {
@@ -242,10 +170,10 @@ function useOrg() {
242
170
  setError(err instanceof Error ? err.message : String(err));
243
171
  }
244
172
  }, [client, orgId]);
245
- const clearOrg = useCallback2(() => {
173
+ const clearOrg = useCallback(() => {
246
174
  client.clearActiveOrg();
247
175
  }, [client]);
248
- const listOrgs = useCallback2(async () => {
176
+ const listOrgs = useCallback(async () => {
249
177
  try {
250
178
  return await client.listOrgs();
251
179
  } catch (err) {
@@ -257,99 +185,96 @@ function useOrg() {
257
185
  }
258
186
  function useOrgMembers(orgId) {
259
187
  const { client } = useOrgContext();
260
- const [members, setMembers] = useState3([]);
261
- const [isLoading, setIsLoading] = useState3(true);
262
- const [error, setError] = useState3(null);
263
- const refresh = useCallback2(async () => {
188
+ const [members, setMembers] = useState([]);
189
+ const [isLoading, setIsLoading] = useState(true);
190
+ const [error, setError] = useState(null);
191
+ const refresh = useCallback(async () => {
264
192
  setIsLoading(true);
265
193
  setError(null);
266
194
  try {
267
- const result = await client.listMembers(orgId);
268
- setMembers(result);
195
+ setMembers(await loadOrgMembers(client, orgId));
269
196
  } catch (err) {
270
197
  setError(err instanceof Error ? err.message : String(err));
271
198
  } finally {
272
199
  setIsLoading(false);
273
200
  }
274
201
  }, [client, orgId]);
275
- useEffect3(() => {
276
- refresh();
202
+ useEffect2(() => {
203
+ void refresh();
277
204
  }, [refresh]);
278
- const invite = useCallback2(
205
+ const actions = createOrgMembersActions(client, orgId, setError);
206
+ const invite = useCallback(
279
207
  async (email, role) => {
280
- setError(null);
281
- try {
282
- const result = await client.inviteMember(orgId, { email, role });
283
- return result;
284
- } catch (err) {
285
- const msg = err instanceof Error ? err.message : String(err);
286
- setError(msg);
287
- throw err;
288
- }
208
+ const result = await actions.invite(email, role);
209
+ await refresh();
210
+ return result;
289
211
  },
290
- [client, orgId]
212
+ [actions, refresh]
291
213
  );
292
- const removeMember = useCallback2(
214
+ const removeMember = useCallback(
293
215
  async (userId) => {
294
- setError(null);
295
- try {
296
- await client.removeMember(orgId, userId);
297
- await refresh();
298
- } catch (err) {
299
- setError(err instanceof Error ? err.message : String(err));
300
- }
216
+ await actions.removeMember(userId);
217
+ await refresh();
301
218
  },
302
- [client, orgId, refresh]
219
+ [actions, refresh]
303
220
  );
304
- const updateRole = useCallback2(
221
+ const updateRole = useCallback(
305
222
  async (userId, role) => {
306
- setError(null);
307
- try {
308
- await client.updateMemberRole(orgId, userId, role);
309
- await refresh();
310
- } catch (err) {
311
- setError(err instanceof Error ? err.message : String(err));
312
- }
223
+ await actions.updateRole(userId, role);
224
+ await refresh();
313
225
  },
314
- [client, orgId, refresh]
226
+ [actions, refresh]
315
227
  );
316
228
  return { members, isLoading, refresh, invite, removeMember, updateRole, error };
317
229
  }
318
230
  function usePermission(requiredRole) {
319
- const { client } = useOrgContext();
320
- const snapshotRef = useRef2(checkPermission(client.activeRole, requiredRole));
321
- const subscribe = useCallback2(
231
+ const { session } = useOrgContext();
232
+ const snapshotRef = useRef(session.checkPermission(requiredRole));
233
+ const subscribe = useCallback(
322
234
  (onStoreChange) => {
323
- return client.onOrgChange(() => {
324
- const newValue = checkPermission(client.activeRole, requiredRole);
325
- if (newValue !== snapshotRef.current) {
326
- snapshotRef.current = newValue;
235
+ return session.subscribe(() => {
236
+ const next = session.checkPermission(requiredRole);
237
+ if (next !== snapshotRef.current) {
238
+ snapshotRef.current = next;
327
239
  onStoreChange();
328
240
  }
329
241
  });
330
242
  },
331
- [client, requiredRole]
243
+ [session, requiredRole]
332
244
  );
333
- const getSnapshot = useCallback2(() => snapshotRef.current, []);
334
- return useSyncExternalStore2(subscribe, getSnapshot);
245
+ const getSnapshot = useCallback(() => snapshotRef.current, []);
246
+ return useSyncExternalStore3(subscribe, getSnapshot);
335
247
  }
336
- var ROLE_LEVELS = {
337
- viewer: 10,
338
- billing: 15,
339
- member: 20,
340
- admin: 30,
341
- owner: 40
342
- };
343
- function checkPermission(currentRole, requiredRole) {
344
- if (!currentRole) return false;
345
- const currentLevel = ROLE_LEVELS[currentRole] ?? 0;
346
- const requiredLevel = ROLE_LEVELS[requiredRole] ?? 0;
347
- return currentLevel >= requiredLevel;
248
+
249
+ // src/react/OrgProvider.tsx
250
+ import { jsx } from "react/jsx-runtime";
251
+ function OrgProvider({ client, children }) {
252
+ const sessionRef = useRef2(null);
253
+ if (sessionRef.current === null || sessionRef.current.client !== client) {
254
+ sessionRef.current?.destroy();
255
+ sessionRef.current = createOrgSession(client);
256
+ }
257
+ useEffect3(() => {
258
+ return () => {
259
+ sessionRef.current?.destroy();
260
+ sessionRef.current = null;
261
+ };
262
+ }, []);
263
+ const value = useMemo2(
264
+ () => ({
265
+ client,
266
+ session: sessionRef.current
267
+ }),
268
+ [client]
269
+ );
270
+ return /* @__PURE__ */ jsx(OrgContext.Provider, { value, children });
348
271
  }
349
272
  export {
350
273
  AuthContext,
351
274
  AuthProvider,
352
275
  OrgContext,
276
+ OrgProvider,
277
+ checkOrgPermission,
353
278
  useAuth,
354
279
  useAuthStatus,
355
280
  useCurrentUser,
package/dist/react.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/react/AuthProvider.tsx","../src/react/auth-context.ts","../src/react/hooks.ts","../src/react/org-hooks.ts"],"sourcesContent":["import { createElement, useEffect, useState } from 'react'\nimport type { ReactElement, ReactNode } from 'react'\nimport type { AuthClient, AuthState } from '../client/auth-client'\nimport { AuthContext } from './auth-context'\n\n/**\n * Props for the AuthProvider component.\n */\ninterface AuthProviderProps {\n\t/** The AuthClient instance to provide to child components */\n\tclient: AuthClient\n\n\t/** Child components that will have access to auth context */\n\tchildren: ReactNode\n\n\t/**\n\t * Optional fallback content to render while the auth client is initializing.\n\t * If not provided, children are rendered with `isLoading: true` in the context.\n\t */\n\tfallback?: ReactNode\n}\n\n/**\n * React context provider that wraps the AuthClient for use with auth hooks.\n *\n * Calls `client.initialize()` on mount to restore any existing session from\n * stored tokens. Subscribes to auth state changes and re-renders children\n * when the state transitions.\n *\n * Must be placed above any component that uses {@link useAuth},\n * {@link useCurrentUser}, or {@link useAuthStatus}.\n *\n * @param props - Provider props including the AuthClient instance and children\n * @returns A React element wrapping children in the AuthContext\n *\n * @example\n * ```typescript\n * import { AuthClient } from '@korajs/auth'\n * import { AuthProvider } from '@korajs/auth/react'\n *\n * const authClient = new AuthClient({ serverUrl: 'http://localhost:3001' })\n *\n * function App() {\n * return (\n * <AuthProvider client={authClient} fallback={<div>Loading...</div>}>\n * <MyApp />\n * </AuthProvider>\n * )\n * }\n * ```\n */\nfunction AuthProvider({ client, children, fallback }: AuthProviderProps): ReactElement {\n\tconst [state, setState] = useState<AuthState>(client.state)\n\tconst [isLoading, setIsLoading] = useState(true)\n\tconst [initError, setInitError] = useState<Error | null>(null)\n\n\t// Initialize the auth client on mount\n\tuseEffect(() => {\n\t\tlet cancelled = false\n\n\t\t// Subscribe to auth state changes\n\t\tconst unsubscribe = client.onAuthChange((newState) => {\n\t\t\tif (!cancelled) {\n\t\t\t\tsetState(newState)\n\t\t\t}\n\t\t})\n\n\t\tclient\n\t\t\t.initialize()\n\t\t\t.then(() => {\n\t\t\t\tif (!cancelled) {\n\t\t\t\t\tsetState(client.state)\n\t\t\t\t\tsetIsLoading(false)\n\t\t\t\t}\n\t\t\t})\n\t\t\t.catch((error: unknown) => {\n\t\t\t\tif (!cancelled) {\n\t\t\t\t\tconst err = error instanceof Error ? error : new Error(String(error))\n\t\t\t\t\tconsole.error('[Kora Auth] Initialization failed:', err)\n\t\t\t\t\tsetInitError(err)\n\t\t\t\t\tsetIsLoading(false)\n\t\t\t\t}\n\t\t\t})\n\n\t\treturn () => {\n\t\t\tcancelled = true\n\t\t\tunsubscribe()\n\t\t}\n\t}, [client])\n\n\t// Show error if initialization failed\n\tif (initError) {\n\t\treturn createElement(\n\t\t\t'div',\n\t\t\t{\n\t\t\t\tstyle: { color: 'red', padding: '1rem', fontFamily: 'monospace' },\n\t\t\t\trole: 'alert',\n\t\t\t},\n\t\t\tcreateElement('strong', null, 'Kora Auth initialization error: '),\n\t\t\tinitError.message,\n\t\t)\n\t}\n\n\t// Show fallback while loading\n\tif (isLoading && fallback !== undefined) {\n\t\treturn fallback as ReactElement\n\t}\n\n\tconst contextValue = {\n\t\tclient,\n\t\tstate,\n\t\tisLoading,\n\t}\n\n\treturn createElement(AuthContext.Provider, { value: contextValue }, children)\n}\n\nexport { AuthProvider }\nexport type { AuthProviderProps }\n","import { createContext } from 'react'\nimport type { AuthClient } from '../client/auth-client'\n\n/**\n * Possible authentication states for the client.\n * - 'loading': Initial state while restoring tokens from storage\n * - 'authenticated': User is signed in with a valid session\n * - 'unauthenticated': No valid session exists\n */\ntype AuthState = 'loading' | 'authenticated' | 'unauthenticated'\n\n/**\n * Shape of the value provided by the AuthContext.\n * Includes the AuthClient instance, reactive state, and a loading flag.\n */\ninterface AuthContextValue {\n\t/** The underlying AuthClient instance for direct access */\n\tclient: AuthClient\n\n\t/** Current authentication state */\n\tstate: AuthState\n\n\t/** Whether the client is still initializing (restoring session from storage) */\n\tisLoading: boolean\n}\n\n/**\n * React context for Kora authentication.\n *\n * Provides the AuthClient and reactive auth state to child components.\n * Must be provided by an AuthProvider higher in the component tree.\n * Defaults to null — hooks that consume this context throw if it is missing.\n */\nconst AuthContext = createContext<AuthContextValue | null>(null)\n\nexport { AuthContext }\nexport type { AuthContextValue, AuthState }\n","import { useCallback, useContext, useEffect, useRef, useState, useSyncExternalStore } from 'react'\nimport type { AuthState, AuthUser } from '../client/auth-client'\nimport { AuthContext } from './auth-context'\n\n// ---------------------------------------------------------------------------\n// Internal context accessor\n// ---------------------------------------------------------------------------\n\n/**\n * Internal hook that reads and validates the AuthContext.\n * Throws a descriptive error if used outside an AuthProvider.\n */\nfunction useAuthContext(): {\n\tclient: import('../client/auth-client').AuthClient\n\tstate: AuthState\n\tisLoading: boolean\n} {\n\tconst ctx = useContext(AuthContext)\n\tif (ctx === null) {\n\t\tthrow new Error(\n\t\t\t'useAuth / useCurrentUser / useAuthStatus must be used within an <AuthProvider>. ' +\n\t\t\t\t'Wrap your component tree with <AuthProvider client={authClient}>.',\n\t\t)\n\t}\n\treturn ctx\n}\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\n/**\n * Return value of the {@link useAuth} hook.\n */\ninterface UseAuthResult {\n\t/** Current authenticated user, or null if not signed in */\n\tuser: AuthUser | null\n\n\t/** Whether the user is currently authenticated */\n\tisAuthenticated: boolean\n\n\t/** Whether the auth client is still initializing (restoring session) */\n\tisLoading: boolean\n\n\t/** Sign up a new user account */\n\tsignUp: (params: { email: string; password: string; name?: string }) => Promise<void>\n\n\t/** Sign in with email and password */\n\tsignIn: (params: { email: string; password: string }) => Promise<void>\n\n\t/** Sign out the current user */\n\tsignOut: () => Promise<void>\n\n\t/** Last error message from a sign-up, sign-in, or sign-out attempt, or null */\n\terror: string | null\n}\n\n/**\n * Auth status information returned by {@link useAuthStatus}.\n */\ninterface AuthStatus {\n\t/** Current authentication state */\n\tstate: AuthState\n\n\t/** Whether the user is currently authenticated */\n\tisAuthenticated: boolean\n\n\t/** Whether the auth client is still initializing */\n\tisLoading: boolean\n}\n\n// ---------------------------------------------------------------------------\n// useAuth\n// ---------------------------------------------------------------------------\n\n/**\n * React hook providing full authentication functionality.\n *\n * Returns the current user, loading state, error state, and methods for\n * sign-up, sign-in, and sign-out. Re-renders when auth state changes.\n *\n * Must be used within an {@link AuthProvider}.\n *\n * @returns An object with user info, auth methods, and status flags\n *\n * @example\n * ```typescript\n * function LoginPage() {\n * const { user, isAuthenticated, isLoading, signIn, error } = useAuth()\n *\n * if (isLoading) return <div>Loading...</div>\n * if (isAuthenticated) return <div>Welcome, {user?.name}</div>\n *\n * return (\n * <form onSubmit={async (e) => {\n * e.preventDefault()\n * await signIn({ email: 'user@example.com', password: 'secret' })\n * }}>\n * {error && <p>{error}</p>}\n * <button type=\"submit\">Sign In</button>\n * </form>\n * )\n * }\n * ```\n */\nfunction useAuth(): UseAuthResult {\n\tconst { client, state, isLoading } = useAuthContext()\n\tconst [error, setError] = useState<string | null>(null)\n\n\t// Use useSyncExternalStore to track the user reactively via auth state changes\n\tconst userSnapshotRef = useRef<AuthUser | null>(client.currentUser)\n\tconst stateSerializedRef = useRef<string>(JSON.stringify(client.currentUser))\n\n\tconst subscribe = useCallback(\n\t\t(onStoreChange: () => void): (() => void) => {\n\t\t\treturn client.onAuthChange(() => {\n\t\t\t\tconst newUser = client.currentUser\n\t\t\t\tconst newSerialized = JSON.stringify(newUser)\n\t\t\t\tif (newSerialized !== stateSerializedRef.current) {\n\t\t\t\t\tuserSnapshotRef.current = newUser\n\t\t\t\t\tstateSerializedRef.current = newSerialized\n\t\t\t\t\tonStoreChange()\n\t\t\t\t}\n\t\t\t})\n\t\t},\n\t\t[client],\n\t)\n\n\tconst getSnapshot = useCallback((): AuthUser | null => {\n\t\treturn userSnapshotRef.current\n\t}, [])\n\n\tconst user = useSyncExternalStore(subscribe, getSnapshot)\n\n\tconst signUp = useCallback(\n\t\tasync (params: { email: string; password: string; name?: string }): Promise<void> => {\n\t\t\tsetError(null)\n\t\t\ttry {\n\t\t\t\tawait client.signUp(params)\n\t\t\t} catch (err: unknown) {\n\t\t\t\tconst message = err instanceof Error ? err.message : String(err)\n\t\t\t\tsetError(message)\n\t\t\t}\n\t\t},\n\t\t[client],\n\t)\n\n\tconst signIn = useCallback(\n\t\tasync (params: { email: string; password: string }): Promise<void> => {\n\t\t\tsetError(null)\n\t\t\ttry {\n\t\t\t\tawait client.signIn(params)\n\t\t\t} catch (err: unknown) {\n\t\t\t\tconst message = err instanceof Error ? err.message : String(err)\n\t\t\t\tsetError(message)\n\t\t\t}\n\t\t},\n\t\t[client],\n\t)\n\n\tconst signOut = useCallback(async (): Promise<void> => {\n\t\tsetError(null)\n\t\ttry {\n\t\t\tawait client.signOut()\n\t\t} catch (err: unknown) {\n\t\t\tconst message = err instanceof Error ? err.message : String(err)\n\t\t\tsetError(message)\n\t\t}\n\t}, [client])\n\n\treturn {\n\t\tuser,\n\t\tisAuthenticated: state === 'authenticated',\n\t\tisLoading,\n\t\tsignUp,\n\t\tsignIn,\n\t\tsignOut,\n\t\terror,\n\t}\n}\n\n// ---------------------------------------------------------------------------\n// useCurrentUser\n// ---------------------------------------------------------------------------\n\n/**\n * React hook that returns the currently authenticated user, or null.\n *\n * A lightweight alternative to {@link useAuth} when you only need the user\n * object and do not need auth methods or error state.\n *\n * Must be used within an {@link AuthProvider}.\n *\n * @returns The current AuthUser or null if not authenticated\n *\n * @example\n * ```typescript\n * function UserAvatar() {\n * const user = useCurrentUser()\n * if (!user) return null\n * return <span>{user.name ?? user.email}</span>\n * }\n * ```\n */\nfunction useCurrentUser(): AuthUser | null {\n\tconst { client } = useAuthContext()\n\n\tconst userSnapshotRef = useRef<AuthUser | null>(client.currentUser)\n\tconst stateSerializedRef = useRef<string>(JSON.stringify(client.currentUser))\n\n\tconst subscribe = useCallback(\n\t\t(onStoreChange: () => void): (() => void) => {\n\t\t\treturn client.onAuthChange(() => {\n\t\t\t\tconst newUser = client.currentUser\n\t\t\t\tconst newSerialized = JSON.stringify(newUser)\n\t\t\t\tif (newSerialized !== stateSerializedRef.current) {\n\t\t\t\t\tuserSnapshotRef.current = newUser\n\t\t\t\t\tstateSerializedRef.current = newSerialized\n\t\t\t\t\tonStoreChange()\n\t\t\t\t}\n\t\t\t})\n\t\t},\n\t\t[client],\n\t)\n\n\tconst getSnapshot = useCallback((): AuthUser | null => {\n\t\treturn userSnapshotRef.current\n\t}, [])\n\n\treturn useSyncExternalStore(subscribe, getSnapshot)\n}\n\n// ---------------------------------------------------------------------------\n// useAuthStatus\n// ---------------------------------------------------------------------------\n\n/**\n * React hook that returns the current authentication status.\n *\n * Re-renders only when the auth state changes, not on every auth event.\n * Use this for status indicators, route guards, and conditional rendering.\n *\n * Must be used within an {@link AuthProvider}.\n *\n * @returns An AuthStatus object with state, isAuthenticated, and isLoading flags\n *\n * @example\n * ```typescript\n * function AuthGuard({ children }: { children: React.ReactNode }) {\n * const { isAuthenticated, isLoading } = useAuthStatus()\n * if (isLoading) return <Spinner />\n * if (!isAuthenticated) return <Navigate to=\"/login\" />\n * return <>{children}</>\n * }\n * ```\n */\nfunction useAuthStatus(): AuthStatus {\n\tconst { state, isLoading } = useAuthContext()\n\n\treturn {\n\t\tstate,\n\t\tisAuthenticated: state === 'authenticated',\n\t\tisLoading,\n\t}\n}\n\nexport { useAuth, useCurrentUser, useAuthStatus }\nexport type { UseAuthResult, AuthStatus }\n","import {\n\tcreateContext,\n\tuseCallback,\n\tuseContext,\n\tuseEffect,\n\tuseRef,\n\tuseState,\n\tuseSyncExternalStore,\n} from 'react'\nimport type {\n\tClientInvitation,\n\tClientMembership,\n\tClientOrganization,\n\tOrgClient,\n} from '../client/org-client'\n\n// ============================================================================\n// OrgContext\n// ============================================================================\n\n/**\n * Shape of the OrgContext value.\n */\nexport interface OrgContextValue {\n\t/** The OrgClient instance */\n\tclient: OrgClient\n}\n\n/**\n * React context for organization state.\n */\nexport const OrgContext = createContext<OrgContextValue | null>(null)\n\nfunction useOrgContext(): OrgContextValue {\n\tconst ctx = useContext(OrgContext)\n\tif (ctx === null) {\n\t\tthrow new Error(\n\t\t\t'useOrg / useOrgMembers / usePermission must be used within an <OrgProvider>. ' +\n\t\t\t\t'Wrap your component tree with <OrgProvider client={orgClient}>.',\n\t\t)\n\t}\n\treturn ctx\n}\n\n// ============================================================================\n// useOrg\n// ============================================================================\n\n/**\n * Return value of the {@link useOrg} hook.\n */\nexport interface UseOrgResult {\n\t/** Currently active organization, or null */\n\torg: ClientOrganization | null\n\t/** Current user's role in the active organization, or null */\n\trole: string | null\n\t/** Active organization ID, or null */\n\torgId: string | null\n\t/** Switch to a different organization */\n\tswitchOrg: (orgId: string) => Promise<void>\n\t/** Create a new organization */\n\tcreateOrg: (params: { name: string; slug?: string }) => Promise<ClientOrganization>\n\t/** Leave the active organization */\n\tleaveOrg: () => Promise<void>\n\t/** Clear the active organization */\n\tclearOrg: () => void\n\t/** List all organizations the user belongs to */\n\tlistOrgs: () => Promise<ClientOrganization[]>\n\t/** Last error, or null */\n\terror: string | null\n}\n\n/**\n * React hook for organization management and context switching.\n *\n * Re-renders when the active organization changes.\n *\n * @example\n * ```typescript\n * function OrgSwitcher() {\n * const { org, switchOrg, listOrgs, error } = useOrg()\n * const [orgs, setOrgs] = useState<ClientOrganization[]>([])\n *\n * useEffect(() => { listOrgs().then(setOrgs) }, [listOrgs])\n *\n * return (\n * <select value={org?.id ?? ''} onChange={(e) => switchOrg(e.target.value)}>\n * <option value=\"\">Select org...</option>\n * {orgs.map(o => <option key={o.id} value={o.id}>{o.name}</option>)}\n * </select>\n * )\n * }\n * ```\n */\nexport function useOrg(): UseOrgResult {\n\tconst { client } = useOrgContext()\n\tconst [error, setError] = useState<string | null>(null)\n\n\t// Track active org reactively\n\tconst orgSnapshotRef = useRef({\n\t\torgId: client.activeOrgId,\n\t\torg: client.activeOrg,\n\t\trole: client.activeRole,\n\t})\n\n\tconst subscribe = useCallback(\n\t\t(onStoreChange: () => void): (() => void) => {\n\t\t\treturn client.onOrgChange(() => {\n\t\t\t\torgSnapshotRef.current = {\n\t\t\t\t\torgId: client.activeOrgId,\n\t\t\t\t\torg: client.activeOrg,\n\t\t\t\t\trole: client.activeRole,\n\t\t\t\t}\n\t\t\t\tonStoreChange()\n\t\t\t})\n\t\t},\n\t\t[client],\n\t)\n\n\tconst getSnapshot = useCallback(() => orgSnapshotRef.current, [])\n\n\tconst { orgId, org, role } = useSyncExternalStore(subscribe, getSnapshot)\n\n\tconst switchOrg = useCallback(\n\t\tasync (newOrgId: string): Promise<void> => {\n\t\t\tsetError(null)\n\t\t\ttry {\n\t\t\t\tawait client.switchOrg(newOrgId)\n\t\t\t} catch (err) {\n\t\t\t\tsetError(err instanceof Error ? err.message : String(err))\n\t\t\t}\n\t\t},\n\t\t[client],\n\t)\n\n\tconst createOrg = useCallback(\n\t\tasync (params: { name: string; slug?: string }): Promise<ClientOrganization> => {\n\t\t\tsetError(null)\n\t\t\ttry {\n\t\t\t\treturn await client.createOrg(params)\n\t\t\t} catch (err) {\n\t\t\t\tconst msg = err instanceof Error ? err.message : String(err)\n\t\t\t\tsetError(msg)\n\t\t\t\tthrow err\n\t\t\t}\n\t\t},\n\t\t[client],\n\t)\n\n\tconst leaveOrg = useCallback(async (): Promise<void> => {\n\t\tif (!orgId) return\n\t\tsetError(null)\n\t\ttry {\n\t\t\tawait client.leaveOrg(orgId)\n\t\t} catch (err) {\n\t\t\tsetError(err instanceof Error ? err.message : String(err))\n\t\t}\n\t}, [client, orgId])\n\n\tconst clearOrg = useCallback((): void => {\n\t\tclient.clearActiveOrg()\n\t}, [client])\n\n\tconst listOrgs = useCallback(async (): Promise<ClientOrganization[]> => {\n\t\ttry {\n\t\t\treturn await client.listOrgs()\n\t\t} catch (err) {\n\t\t\tsetError(err instanceof Error ? err.message : String(err))\n\t\t\treturn []\n\t\t}\n\t}, [client])\n\n\treturn { org, role, orgId, switchOrg, createOrg, leaveOrg, clearOrg, listOrgs, error }\n}\n\n// ============================================================================\n// useOrgMembers\n// ============================================================================\n\n/**\n * Return value of the {@link useOrgMembers} hook.\n */\nexport interface UseOrgMembersResult {\n\t/** Members of the organization (empty until loaded) */\n\tmembers: ClientMembership[]\n\t/** Whether members are being loaded */\n\tisLoading: boolean\n\t/** Reload the members list */\n\trefresh: () => Promise<void>\n\t/** Invite a user by email */\n\tinvite: (email: string, role: string) => Promise<ClientInvitation>\n\t/** Remove a member */\n\tremoveMember: (userId: string) => Promise<void>\n\t/** Update a member's role */\n\tupdateRole: (userId: string, role: string) => Promise<void>\n\t/** Last error, or null */\n\terror: string | null\n}\n\n/**\n * React hook for managing organization members.\n *\n * Automatically loads members when the orgId changes.\n *\n * @param orgId - Organization ID to manage members for\n */\nexport function useOrgMembers(orgId: string): UseOrgMembersResult {\n\tconst { client } = useOrgContext()\n\tconst [members, setMembers] = useState<ClientMembership[]>([])\n\tconst [isLoading, setIsLoading] = useState(true)\n\tconst [error, setError] = useState<string | null>(null)\n\n\tconst refresh = useCallback(async () => {\n\t\tsetIsLoading(true)\n\t\tsetError(null)\n\t\ttry {\n\t\t\tconst result = await client.listMembers(orgId)\n\t\t\tsetMembers(result)\n\t\t} catch (err) {\n\t\t\tsetError(err instanceof Error ? err.message : String(err))\n\t\t} finally {\n\t\t\tsetIsLoading(false)\n\t\t}\n\t}, [client, orgId])\n\n\tuseEffect(() => {\n\t\trefresh()\n\t}, [refresh])\n\n\tconst invite = useCallback(\n\t\tasync (email: string, role: string): Promise<ClientInvitation> => {\n\t\t\tsetError(null)\n\t\t\ttry {\n\t\t\t\tconst result = await client.inviteMember(orgId, { email, role })\n\t\t\t\treturn result\n\t\t\t} catch (err) {\n\t\t\t\tconst msg = err instanceof Error ? err.message : String(err)\n\t\t\t\tsetError(msg)\n\t\t\t\tthrow err\n\t\t\t}\n\t\t},\n\t\t[client, orgId],\n\t)\n\n\tconst removeMember = useCallback(\n\t\tasync (userId: string): Promise<void> => {\n\t\t\tsetError(null)\n\t\t\ttry {\n\t\t\t\tawait client.removeMember(orgId, userId)\n\t\t\t\tawait refresh()\n\t\t\t} catch (err) {\n\t\t\t\tsetError(err instanceof Error ? err.message : String(err))\n\t\t\t}\n\t\t},\n\t\t[client, orgId, refresh],\n\t)\n\n\tconst updateRole = useCallback(\n\t\tasync (userId: string, role: string): Promise<void> => {\n\t\t\tsetError(null)\n\t\t\ttry {\n\t\t\t\tawait client.updateMemberRole(orgId, userId, role)\n\t\t\t\tawait refresh()\n\t\t\t} catch (err) {\n\t\t\t\tsetError(err instanceof Error ? err.message : String(err))\n\t\t\t}\n\t\t},\n\t\t[client, orgId, refresh],\n\t)\n\n\treturn { members, isLoading, refresh, invite, removeMember, updateRole, error }\n}\n\n// ============================================================================\n// usePermission\n// ============================================================================\n\n/**\n * React hook that checks if the current user has a specific role level\n * in the active organization.\n *\n * @param requiredRole - Minimum role required (uses ROLE_HIERARCHY from org-types)\n * @returns true if the user's role is at least requiredRole\n *\n * @example\n * ```typescript\n * function AdminPanel() {\n * const canManage = usePermission('admin')\n * if (!canManage) return <p>Access denied</p>\n * return <AdminSettings />\n * }\n * ```\n */\nexport function usePermission(requiredRole: string): boolean {\n\tconst { client } = useOrgContext()\n\n\tconst snapshotRef = useRef(checkPermission(client.activeRole, requiredRole))\n\n\tconst subscribe = useCallback(\n\t\t(onStoreChange: () => void): (() => void) => {\n\t\t\treturn client.onOrgChange(() => {\n\t\t\t\tconst newValue = checkPermission(client.activeRole, requiredRole)\n\t\t\t\tif (newValue !== snapshotRef.current) {\n\t\t\t\t\tsnapshotRef.current = newValue\n\t\t\t\t\tonStoreChange()\n\t\t\t\t}\n\t\t\t})\n\t\t},\n\t\t[client, requiredRole],\n\t)\n\n\tconst getSnapshot = useCallback(() => snapshotRef.current, [])\n\n\treturn useSyncExternalStore(subscribe, getSnapshot)\n}\n\n// Simple role hierarchy check (mirrors ROLE_HIERARCHY from org-types)\nconst ROLE_LEVELS: Record<string, number> = {\n\tviewer: 10,\n\tbilling: 15,\n\tmember: 20,\n\tadmin: 30,\n\towner: 40,\n}\n\nfunction checkPermission(currentRole: string | null, requiredRole: string): boolean {\n\tif (!currentRole) return false\n\tconst currentLevel = ROLE_LEVELS[currentRole] ?? 0\n\tconst requiredLevel = ROLE_LEVELS[requiredRole] ?? 0\n\treturn currentLevel >= requiredLevel\n}\n"],"mappings":";AAAA,SAAS,eAAe,WAAW,gBAAgB;;;ACAnD,SAAS,qBAAqB;AAiC9B,IAAM,cAAc,cAAuC,IAAI;;;ADkB/D,SAAS,aAAa,EAAE,QAAQ,UAAU,SAAS,GAAoC;AACtF,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAoB,OAAO,KAAK;AAC1D,QAAM,CAAC,WAAW,YAAY,IAAI,SAAS,IAAI;AAC/C,QAAM,CAAC,WAAW,YAAY,IAAI,SAAuB,IAAI;AAG7D,YAAU,MAAM;AACf,QAAI,YAAY;AAGhB,UAAM,cAAc,OAAO,aAAa,CAAC,aAAa;AACrD,UAAI,CAAC,WAAW;AACf,iBAAS,QAAQ;AAAA,MAClB;AAAA,IACD,CAAC;AAED,WACE,WAAW,EACX,KAAK,MAAM;AACX,UAAI,CAAC,WAAW;AACf,iBAAS,OAAO,KAAK;AACrB,qBAAa,KAAK;AAAA,MACnB;AAAA,IACD,CAAC,EACA,MAAM,CAAC,UAAmB;AAC1B,UAAI,CAAC,WAAW;AACf,cAAM,MAAM,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,KAAK,CAAC;AACpE,gBAAQ,MAAM,sCAAsC,GAAG;AACvD,qBAAa,GAAG;AAChB,qBAAa,KAAK;AAAA,MACnB;AAAA,IACD,CAAC;AAEF,WAAO,MAAM;AACZ,kBAAY;AACZ,kBAAY;AAAA,IACb;AAAA,EACD,GAAG,CAAC,MAAM,CAAC;AAGX,MAAI,WAAW;AACd,WAAO;AAAA,MACN;AAAA,MACA;AAAA,QACC,OAAO,EAAE,OAAO,OAAO,SAAS,QAAQ,YAAY,YAA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SAAS,KAAK;AACb,iBAAS,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG,CAAC;AAAA,MAC1D;AAAA,IACD;AAAA,IACA,CAAC,QAAQ,OAAO,OAAO;AAAA,EACxB;AAEA,SAAO,EAAE,SAAS,WAAW,SAAS,QAAQ,cAAc,YAAY,MAAM;AAC/E;AAsBO,SAAS,cAAc,cAA+B;AAC5D,QAAM,EAAE,OAAO,IAAI,cAAc;AAEjC,QAAM,cAAcG,QAAO,gBAAgB,OAAO,YAAY,YAAY,CAAC;AAE3E,QAAM,YAAYH;AAAA,IACjB,CAAC,kBAA4C;AAC5C,aAAO,OAAO,YAAY,MAAM;AAC/B,cAAM,WAAW,gBAAgB,OAAO,YAAY,YAAY;AAChE,YAAI,aAAa,YAAY,SAAS;AACrC,sBAAY,UAAU;AACtB,wBAAc;AAAA,QACf;AAAA,MACD,CAAC;AAAA,IACF;AAAA,IACA,CAAC,QAAQ,YAAY;AAAA,EACtB;AAEA,QAAM,cAAcA,aAAY,MAAM,YAAY,SAAS,CAAC,CAAC;AAE7D,SAAOK,sBAAqB,WAAW,WAAW;AACnD;AAGA,IAAM,cAAsC;AAAA,EAC3C,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,OAAO;AACR;AAEA,SAAS,gBAAgB,aAA4B,cAA+B;AACnF,MAAI,CAAC,YAAa,QAAO;AACzB,QAAM,eAAe,YAAY,WAAW,KAAK;AACjD,QAAM,gBAAgB,YAAY,YAAY,KAAK;AACnD,SAAO,gBAAgB;AACxB;","names":["useState","useState","createContext","useCallback","useContext","useEffect","useRef","useState","useSyncExternalStore"]}
1
+ {"version":3,"sources":["../src/react/AuthProvider.tsx","../src/react/auth-context.ts","../src/react/hooks.ts","../src/react/OrgProvider.tsx","../src/react/org-hooks.ts"],"sourcesContent":["import { createElement, useEffect, useMemo, useSyncExternalStore } from 'react'\nimport type { ReactElement, ReactNode } from 'react'\nimport type { AuthClient } from '../client/auth-client'\nimport { createAuthSession } from '../bindings/create-auth-session'\nimport { AuthContext } from './auth-context'\n\ninterface AuthProviderProps {\n\tclient: AuthClient\n\tchildren: ReactNode\n\tfallback?: ReactNode\n}\n\nfunction AuthProvider({ client, children, fallback }: AuthProviderProps): ReactElement {\n\tconst session = useMemo(() => createAuthSession(client), [client])\n\n\tuseEffect(() => () => session.destroy(), [session])\n\n\tconst snapshot = useSyncExternalStore(\n\t\t(onStoreChange) => session.subscribe(onStoreChange),\n\t\t() => session.getSnapshot(),\n\t\t() => session.getSnapshot(),\n\t)\n\n\tif (snapshot.initError) {\n\t\treturn createElement(\n\t\t\t'div',\n\t\t\t{\n\t\t\t\tstyle: { color: 'red', padding: '1rem', fontFamily: 'monospace' },\n\t\t\t\trole: 'alert',\n\t\t\t},\n\t\t\tcreateElement('strong', null, 'Kora Auth initialization error: '),\n\t\t\tsnapshot.initError.message,\n\t\t)\n\t}\n\n\tif (snapshot.isLoading && fallback !== undefined) {\n\t\treturn fallback as ReactElement\n\t}\n\n\tconst contextValue = {\n\t\tclient,\n\t\tsession,\n\t\tstate: snapshot.state,\n\t\tisLoading: snapshot.isLoading,\n\t}\n\n\treturn createElement(AuthContext.Provider, { value: contextValue }, children)\n}\n\nexport { AuthProvider }\nexport type { AuthProviderProps }\n","import { createContext } from 'react'\nimport type { AuthSession } from '../bindings/create-auth-session'\nimport type { AuthClient } from '../client/auth-client'\n\n/**\n * Possible authentication states for the client.\n */\ntype AuthState = 'loading' | 'authenticated' | 'unauthenticated'\n\n/**\n * Shape of the value provided by the AuthContext.\n */\ninterface AuthContextValue {\n\tclient: AuthClient\n\tsession: AuthSession\n\tstate: AuthState\n\tisLoading: boolean\n}\n\n/**\n * React context for Kora authentication.\n */\nconst AuthContext = createContext<AuthContextValue | null>(null)\n\nexport { AuthContext }\nexport type { AuthContextValue, AuthState }\n","import { useContext, useSyncExternalStore } from 'react'\nimport type {\n\tAuthState,\n\tAuthUser,\n\tLinkedOAuthAccount,\n\tOAuthAuthorizationOptions,\n\tOAuthAuthorizationResult,\n\tOAuthCallbackParams,\n} from '../client/auth-client'\nimport { AuthContext } from './auth-context'\n\nfunction useAuthContext() {\n\tconst ctx = useContext(AuthContext)\n\tif (ctx === null) {\n\t\tthrow new Error(\n\t\t\t'useAuth / useCurrentUser / useAuthStatus must be used within an <AuthProvider>. ' +\n\t\t\t\t'Wrap your component tree with <AuthProvider client={authClient}>.',\n\t\t)\n\t}\n\treturn ctx\n}\n\ninterface UseAuthResult {\n\tuser: AuthUser | null\n\tisAuthenticated: boolean\n\tisLoading: boolean\n\tsignUp: (params: {\n\t\temail: string\n\t\tpassword: string\n\t\tname?: string\n\t\tdeviceId?: string\n\t\tdevicePublicKey?: string\n\t}) => Promise<void>\n\tsignIn: (params: {\n\t\temail: string\n\t\tpassword: string\n\t\tdeviceId?: string\n\t\tdevicePublicKey?: string\n\t}) => Promise<void>\n\tsignInWithOAuth: (\n\t\tprovider: string,\n\t\toptions?: OAuthAuthorizationOptions,\n\t) => Promise<OAuthAuthorizationResult>\n\tcompleteOAuthSignIn: (provider: string, params: OAuthCallbackParams) => Promise<void>\n\tgetOAuthAuthorizationUrl: (\n\t\tprovider: string,\n\t\toptions?: OAuthAuthorizationOptions,\n\t) => Promise<OAuthAuthorizationResult>\n\tlinkOAuth: (provider: string, params: OAuthCallbackParams) => Promise<LinkedOAuthAccount | null>\n\tlistLinkedAccounts: () => Promise<LinkedOAuthAccount[]>\n\tunlinkOAuth: (provider: string) => Promise<void>\n\tsignOut: () => Promise<void>\n\terror: string | null\n\tinitError: Error | null\n}\n\ninterface AuthStatus {\n\tstate: AuthState\n\tisAuthenticated: boolean\n\tisLoading: boolean\n}\n\nfunction useAuthSessionSnapshot() {\n\tconst { session } = useAuthContext()\n\n\treturn useSyncExternalStore(\n\t\t(onStoreChange) => session.subscribe(onStoreChange),\n\t\t() => session.getSnapshot(),\n\t\t() => session.getSnapshot(),\n\t)\n}\n\nfunction useAuth(): UseAuthResult {\n\tconst { session } = useAuthContext()\n\tconst snapshot = useAuthSessionSnapshot()\n\n\treturn {\n\t\tuser: snapshot.user,\n\t\tisAuthenticated: snapshot.isAuthenticated,\n\t\tisLoading: snapshot.isLoading,\n\t\terror: snapshot.error,\n\t\tinitError: snapshot.initError,\n\t\tsignUp: (params) => session.signUp(params),\n\t\tsignIn: (params) => session.signIn(params),\n\t\tsignInWithOAuth: (provider, options) => session.signInWithOAuth(provider, options),\n\t\tcompleteOAuthSignIn: (provider, params) => session.completeOAuthSignIn(provider, params),\n\t\tgetOAuthAuthorizationUrl: (provider, options) =>\n\t\t\tsession.getOAuthAuthorizationUrl(provider, options),\n\t\tlinkOAuth: (provider, params) => session.linkOAuth(provider, params),\n\t\tlistLinkedAccounts: () => session.listLinkedAccounts(),\n\t\tunlinkOAuth: (provider) => session.unlinkOAuth(provider),\n\t\tsignOut: () => session.signOut(),\n\t}\n}\n\nfunction useCurrentUser(): AuthUser | null {\n\treturn useAuthSessionSnapshot().user\n}\n\nfunction useAuthStatus(): AuthStatus {\n\tconst snapshot = useAuthSessionSnapshot()\n\treturn {\n\t\tstate: snapshot.state,\n\t\tisAuthenticated: snapshot.isAuthenticated,\n\t\tisLoading: snapshot.isLoading,\n\t}\n}\n\nexport { useAuth, useCurrentUser, useAuthStatus }\nexport type { UseAuthResult, AuthStatus }\n","import { useEffect, useMemo, useRef, type ReactNode } from 'react'\nimport type { OrgClient } from '../client/org-client'\nimport { createOrgSession, type OrgSession } from '../bindings/create-org-session'\nimport { OrgContext, type OrgContextValue } from './org-hooks'\n\nexport interface OrgProviderProps {\n\tclient: OrgClient\n\tchildren?: ReactNode\n}\n\n/**\n * Provides organization context for {@link useOrg}, {@link useOrgMembers}, and {@link usePermission}.\n */\nexport function OrgProvider({ client, children }: OrgProviderProps) {\n\tconst sessionRef = useRef<OrgSession | null>(null)\n\n\tif (sessionRef.current === null || sessionRef.current.client !== client) {\n\t\tsessionRef.current?.destroy()\n\t\tsessionRef.current = createOrgSession(client)\n\t}\n\n\tuseEffect(() => {\n\t\treturn () => {\n\t\t\tsessionRef.current?.destroy()\n\t\t\tsessionRef.current = null\n\t\t}\n\t}, [])\n\n\tconst value = useMemo<OrgContextValue>(\n\t\t() => ({\n\t\t\tclient,\n\t\t\tsession: sessionRef.current!,\n\t\t}),\n\t\t[client],\n\t)\n\n\treturn <OrgContext.Provider value={value}>{children}</OrgContext.Provider>\n}\n\nexport type { OrgContextValue }\n","import {\n\tcreateContext,\n\tuseCallback,\n\tuseContext,\n\tuseEffect,\n\tuseRef,\n\tuseState,\n\tuseSyncExternalStore,\n} from 'react'\nimport type {\n\tClientInvitation,\n\tClientMembership,\n\tClientOrganization,\n\tOrgClient,\n} from '../client/org-client'\nimport {\n\tcheckOrgPermission,\n\tcreateOrgMembersActions,\n\tcreateOrgSession,\n\tloadOrgMembers,\n\ttype OrgSession,\n\ttype OrgSnapshot,\n} from '../bindings/create-org-session'\n\nexport interface OrgContextValue {\n\tclient: OrgClient\n\tsession: OrgSession\n}\n\nexport const OrgContext = createContext<OrgContextValue | null>(null)\n\nfunction useOrgContext(): OrgContextValue {\n\tconst ctx = useContext(OrgContext)\n\tif (ctx === null) {\n\t\tthrow new Error(\n\t\t\t'useOrg / useOrgMembers / usePermission must be used within an <OrgProvider>. ' +\n\t\t\t\t'Wrap your component tree with <OrgProvider client={orgClient}>.',\n\t\t)\n\t}\n\treturn ctx\n}\n\nfunction useOrgSnapshot(session: OrgSession): OrgSnapshot {\n\tconst snapshotRef = useRef(session.getSnapshot())\n\n\tconst subscribe = useCallback(\n\t\t(onStoreChange: () => void): (() => void) => {\n\t\t\treturn session.subscribe(() => {\n\t\t\t\tsnapshotRef.current = session.getSnapshot()\n\t\t\t\tonStoreChange()\n\t\t\t})\n\t\t},\n\t\t[session],\n\t)\n\n\tconst getSnapshot = useCallback(() => snapshotRef.current, [])\n\n\treturn useSyncExternalStore(subscribe, getSnapshot)\n}\n\nexport interface UseOrgResult {\n\torg: ClientOrganization | null\n\trole: string | null\n\torgId: string | null\n\tswitchOrg: (orgId: string) => Promise<void>\n\tcreateOrg: (params: { name: string; slug?: string }) => Promise<ClientOrganization>\n\tleaveOrg: () => Promise<void>\n\tclearOrg: () => void\n\tlistOrgs: () => Promise<ClientOrganization[]>\n\terror: string | null\n}\n\nexport function useOrg(): UseOrgResult {\n\tconst { client, session } = useOrgContext()\n\tconst { orgId, org, role } = useOrgSnapshot(session)\n\tconst [error, setError] = useState<string | null>(null)\n\n\tconst switchOrg = useCallback(\n\t\tasync (newOrgId: string): Promise<void> => {\n\t\t\tsetError(null)\n\t\t\ttry {\n\t\t\t\tawait client.switchOrg(newOrgId)\n\t\t\t} catch (err) {\n\t\t\t\tsetError(err instanceof Error ? err.message : String(err))\n\t\t\t}\n\t\t},\n\t\t[client],\n\t)\n\n\tconst createOrg = useCallback(\n\t\tasync (params: { name: string; slug?: string }): Promise<ClientOrganization> => {\n\t\t\tsetError(null)\n\t\t\ttry {\n\t\t\t\treturn await client.createOrg(params)\n\t\t\t} catch (err) {\n\t\t\t\tconst msg = err instanceof Error ? err.message : String(err)\n\t\t\t\tsetError(msg)\n\t\t\t\tthrow err\n\t\t\t}\n\t\t},\n\t\t[client],\n\t)\n\n\tconst leaveOrg = useCallback(async (): Promise<void> => {\n\t\tif (!orgId) return\n\t\tsetError(null)\n\t\ttry {\n\t\t\tawait client.leaveOrg(orgId)\n\t\t} catch (err) {\n\t\t\tsetError(err instanceof Error ? err.message : String(err))\n\t\t}\n\t}, [client, orgId])\n\n\tconst clearOrg = useCallback((): void => {\n\t\tclient.clearActiveOrg()\n\t}, [client])\n\n\tconst listOrgs = useCallback(async (): Promise<ClientOrganization[]> => {\n\t\ttry {\n\t\t\treturn await client.listOrgs()\n\t\t} catch (err) {\n\t\t\tsetError(err instanceof Error ? err.message : String(err))\n\t\t\treturn []\n\t\t}\n\t}, [client])\n\n\treturn { org, role, orgId, switchOrg, createOrg, leaveOrg, clearOrg, listOrgs, error }\n}\n\nexport interface UseOrgMembersResult {\n\tmembers: ClientMembership[]\n\tisLoading: boolean\n\trefresh: () => Promise<void>\n\tinvite: (email: string, role: string) => Promise<ClientInvitation>\n\tremoveMember: (userId: string) => Promise<void>\n\tupdateRole: (userId: string, role: string) => Promise<void>\n\terror: string | null\n}\n\nexport function useOrgMembers(orgId: string): UseOrgMembersResult {\n\tconst { client } = useOrgContext()\n\tconst [members, setMembers] = useState<ClientMembership[]>([])\n\tconst [isLoading, setIsLoading] = useState(true)\n\tconst [error, setError] = useState<string | null>(null)\n\n\tconst refresh = useCallback(async () => {\n\t\tsetIsLoading(true)\n\t\tsetError(null)\n\t\ttry {\n\t\t\tsetMembers(await loadOrgMembers(client, orgId))\n\t\t} catch (err) {\n\t\t\tsetError(err instanceof Error ? err.message : String(err))\n\t\t} finally {\n\t\t\tsetIsLoading(false)\n\t\t}\n\t}, [client, orgId])\n\n\tuseEffect(() => {\n\t\tvoid refresh()\n\t}, [refresh])\n\n\tconst actions = createOrgMembersActions(client, orgId, setError)\n\n\tconst invite = useCallback(\n\t\tasync (email: string, role: string): Promise<ClientInvitation> => {\n\t\t\tconst result = await actions.invite(email, role)\n\t\t\tawait refresh()\n\t\t\treturn result\n\t\t},\n\t\t[actions, refresh],\n\t)\n\n\tconst removeMember = useCallback(\n\t\tasync (userId: string): Promise<void> => {\n\t\t\tawait actions.removeMember(userId)\n\t\t\tawait refresh()\n\t\t},\n\t\t[actions, refresh],\n\t)\n\n\tconst updateRole = useCallback(\n\t\tasync (userId: string, role: string): Promise<void> => {\n\t\t\tawait actions.updateRole(userId, role)\n\t\t\tawait refresh()\n\t\t},\n\t\t[actions, refresh],\n\t)\n\n\treturn { members, isLoading, refresh, invite, removeMember, updateRole, error }\n}\n\nexport function usePermission(requiredRole: string): boolean {\n\tconst { session } = useOrgContext()\n\tconst snapshotRef = useRef(session.checkPermission(requiredRole))\n\n\tconst subscribe = useCallback(\n\t\t(onStoreChange: () => void): (() => void) => {\n\t\t\treturn session.subscribe(() => {\n\t\t\t\tconst next = session.checkPermission(requiredRole)\n\t\t\t\tif (next !== snapshotRef.current) {\n\t\t\t\t\tsnapshotRef.current = next\n\t\t\t\t\tonStoreChange()\n\t\t\t\t}\n\t\t\t})\n\t\t},\n\t\t[session, requiredRole],\n\t)\n\n\tconst getSnapshot = useCallback(() => snapshotRef.current, [])\n\n\treturn useSyncExternalStore(subscribe, getSnapshot)\n}\n\nexport { checkOrgPermission }\n"],"mappings":";;;;;;;;;AAAA,SAAS,eAAe,WAAW,SAAS,4BAA4B;;;ACAxE,SAAS,qBAAqB;AAsB9B,IAAM,cAAc,cAAuC,IAAI;;;ADV/D,SAAS,aAAa,EAAE,QAAQ,UAAU,SAAS,GAAoC;AACtF,QAAM,UAAU,QAAQ,MAAM,kBAAkB,MAAM,GAAG,CAAC,MAAM,CAAC;AAEjE,YAAU,MAAM,MAAM,QAAQ,QAAQ,GAAG,CAAC,OAAO,CAAC;AAElD,QAAM,WAAW;AAAA,IAChB,CAAC,kBAAkB,QAAQ,UAAU,aAAa;AAAA,IAClD,MAAM,QAAQ,YAAY;AAAA,IAC1B,MAAM,QAAQ,YAAY;AAAA,EAC3B;AAEA,MAAI,SAAS,WAAW;AACvB,WAAO;AAAA,MACN;AAAA,MACA;AAAA,QACC,OAAO,EAAE,OAAO,OAAO,SAAS,QAAQ,YAAY,YAAY;AAAA,QAChE,MAAM;AAAA,MACP;AAAA,MACA,cAAc,UAAU,MAAM,kCAAkC;AAAA,MAChE,SAAS,UAAU;AAAA,IACpB;AAAA,EACD;AAEA,MAAI,SAAS,aAAa,aAAa,QAAW;AACjD,WAAO;AAAA,EACR;AAEA,QAAM,eAAe;AAAA,IACpB;AAAA,IACA;AAAA,IACA,OAAO,SAAS;AAAA,IAChB,WAAW,SAAS;AAAA,EACrB;AAEA,SAAO,cAAc,YAAY,UAAU,EAAE,OAAO,aAAa,GAAG,QAAQ;AAC7E;;;AE/CA,SAAS,YAAY,wBAAAA,6BAA4B;AAWjD,SAAS,iBAAiB;AACzB,QAAM,MAAM,WA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Q;AAvBD,SAAS,YAAY,EAAE,QAAQ,SAAS,GAAqB;AACnE,QAAM,aAAaE,QAA0B,IAAI;AAEjD,MAAI,WAAW,YAAY,QAAQ,WAAW,QAAQ,WAAW,QAAQ;AACxE,eAAW,SAAS,QAAQ;AAC5B,eAAW,UAAU,iBAAiB,MAAM;AAAA,EAC7C;AAEA,EAAAC,WAAU,MAAM;AACf,WAAO,MAAM;AACZ,iBAAW,SAAS,QAAQ;AAC5B,iBAAW,UAAU;AAAA,IACtB;AAAA,EACD,GAAG,CAAC,CAAC;AAEL,QAAM,QAAQC;AAAA,IACb,OAAO;AAAA,MACN;AAAA,MACA,SAAS,WAAW;AAAA,IACrB;AAAA,IACA,CAAC,MAAM;AAAA,EACR;AAEA,SAAO,oBAAC,WAAW,UAAX,EAAoB,OAAe,UAAS;AACrD;","names":["useSyncExternalStore","useSyncExternalStore","useEffect","useMemo","useRef","createContext","useContext","useEffect","useSyncExternalStore","createContext","useContext","useSyncExternalStore","useEffect","useRef","useEffect","useMemo"]}