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

Function useOAuthPopupFlow

packages/react/src/plugins/oauth-sign-in.tsx:143–418  ·  view source on GitHub ↗
(options: {
  readonly popupName: string;
  readonly callbackPath?: string;
  readonly noAuthorizationUrlMessage?: string;
  readonly popupBlockedMessage?: string;
  readonly popupClosedMessage?: string;
  readonly detectPopupClosed?: boolean;
  readonly startErrorMessage?: string;
})

Source from the content-addressed store, hash-verified

141}
142
143export function useOAuthPopupFlow<
144 TPayload extends OAuthCompletionPayload = OAuthCompletionPayload,
145>(options: {
146 readonly popupName: string;
147 readonly callbackPath?: string;
148 readonly noAuthorizationUrlMessage?: string;
149 readonly popupBlockedMessage?: string;
150 readonly popupClosedMessage?: string;
151 readonly detectPopupClosed?: boolean;
152 readonly startErrorMessage?: string;
153}) {
154 const {
155 detectPopupClosed = true,
156 callbackPath,
157 noAuthorizationUrlMessage,
158 popupBlockedMessage,
159 popupClosedMessage,
160 popupName,
161 startErrorMessage,
162 } = options;
163 const doStartOAuth = useAtomSet(startOAuth, { mode: "promiseExit" });
164 const doCancelOAuth = useAtomSet(cancelOAuth, { mode: "promiseExit" });
165 const doOAuthConnectionCompleted = useAtomSet(oauthConnectionCompleted, { mode: "promiseExit" });
166 const reportHandledError = useReportHandledError();
167 const [busy, setBusy] = useState(false);
168 const [error, setError] = useState<string | null>(null);
169 const cleanupRef = useRef<(() => void) | null>(null);
170 const sessionRef = useRef<{ readonly state: string } | null>(null);
171
172 const cancelSession = useCallback(
173 (state: string) => {
174 void doCancelOAuth({ payload: { state: OAuthState.make(state) } });
175 },
176 [doCancelOAuth],
177 );
178
179 const cancel = useCallback(() => {
180 const session = sessionRef.current;
181 cleanupRef.current?.();
182 cleanupRef.current = null;
183 sessionRef.current = null;
184 if (session) cancelSession(session.state);
185 setBusy(false);
186 }, [cancelSession]);
187
188 useEffect(
189 () => () => {
190 const session = sessionRef.current;
191 cleanupRef.current?.();
192 cleanupRef.current = null;
193 sessionRef.current = null;
194 if (session) cancelSession(session.state);
195 },
196 [cancelSession],
197 );
198
199 const openAuthorization = useCallback(
200 async (input: StartOAuthAuthorizationInput<TPayload>) => {

Callers 3

OwnerAccountsFunction · 0.90
AddAccountModalViewFunction · 0.90
GraphqlSignInButtonFunction · 0.90

Calls 12

useReportHandledErrorFunction · 0.90
reserveOAuthPopupFunction · 0.90
trackEventFunction · 0.90
messageFromUnknownFunction · 0.90
messageFromExitFunction · 0.90
openOAuthSystemBrowserFunction · 0.90
openOAuthPopupFunction · 0.90
getDesktopBridgeFunction · 0.85
oauthCallbackUrlFunction · 0.85
handleResultFunction · 0.70
closeMethod · 0.65
cancelFunction · 0.50

Tested by

no test coverage detected