MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / AuthProvider

Function AuthProvider

apps/cloud/src/web/auth.tsx:57–101  ·  view source on GitHub ↗
({
  children,
  initialHint,
}: {
  children: React.ReactNode;
  initialHint?: AuthHint | null;
})

Source from the content-addressed store, hash-verified

55// ── Provider ───────────────────────────────────────────────────────────────
56
57export const AuthProvider = ({
58 children,
59 initialHint,
60}: {
61 children: React.ReactNode;
62 initialHint?: AuthHint | null;
63}) => {
64 const posthog = usePostHog();
65
66 const onIdentify = React.useCallback<IdentifyFn>(
67 (state) => {
68 // Record the org this browser is verifiably viewing: onIdentify fires
69 // only on resolved `/account/me` answers (never hint optimism), and that
70 // call is URL-scoped, so `state.organization` IS the org of the current
71 // tab. The cookie makes the next bare entry (`/`) and the next login
72 // land here instead of the session's login-time org — see
73 // ../auth/last-org-cookie.ts. Deliberately not cleared on signout: the
74 // preference is the point of surviving the session.
75 if (state.status === "authenticated" && state.organization) {
76 writeLastOrgCookie(state.organization.slug);
77 }
78 if (!posthog) return;
79 if (state.status === "authenticated") {
80 posthog.identify(state.user.id, {
81 email: state.user.email,
82 name: state.user.name,
83 });
84 if (state.organization) {
85 posthog.group("organization", state.organization.id, {
86 name: state.organization.name,
87 });
88 }
89 } else {
90 posthog.reset();
91 }
92 },
93 [posthog],
94 );
95
96 return (
97 <SharedAuthProvider onIdentify={onIdentify} initialHint={initialHint}>
98 {children}
99 </SharedAuthProvider>
100 );
101};

Callers

nothing calls this directly

Calls 2

writeLastOrgCookieFunction · 0.90
groupMethod · 0.80

Tested by

no test coverage detected