@spooky-sync/client-solid 0.0.1-canary.260 → 0.0.1-canary.261

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.
@@ -0,0 +1,30 @@
1
+ import { createSignal, onCleanup, type Accessor } from 'solid-js';
2
+ import { useDb } from './context';
3
+ import type { ImpersonationInfo } from '@spooky-sync/core';
4
+
5
+ export interface UseImpersonation {
6
+ /** The active impersonation, or `null`. */
7
+ impersonation: Accessor<ImpersonationInfo | null>;
8
+ isImpersonating: Accessor<boolean>;
9
+ /** Return to the admin session. */
10
+ stop: () => Promise<void>;
11
+ }
12
+
13
+ /**
14
+ * Observe admin impersonation (started from the DevTools). The client already
15
+ * shows its own warning bar with a Stop button; use this for anything extra,
16
+ * such as hiding actions an admin should not take on someone's behalf.
17
+ * Must be used within a `<Sp00kyProvider>`.
18
+ */
19
+ export function useImpersonation(): UseImpersonation {
20
+ const db = useDb();
21
+ const [impersonation, setImpersonation] = createSignal<ImpersonationInfo | null>(
22
+ db.auth.impersonation
23
+ );
24
+ onCleanup(db.auth.subscribeImpersonation(setImpersonation));
25
+ return {
26
+ impersonation,
27
+ isImpersonating: () => impersonation() !== null,
28
+ stop: () => db.auth.stopImpersonating(),
29
+ };
30
+ }