Skip to content

Commit 65c8bc1

Browse files
committed
bugbot + reviewer handling
1 parent 0b9a8ff commit 65c8bc1

3 files changed

Lines changed: 20 additions & 3 deletions

File tree

‎packages/managed-auth-react/src/lib/api.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ export function submitSignInOption(
169169
export interface ManagedAuthStreamHandlers {
170170
onState: (data: ManagedAuthStateEventData) => void;
171171
onError: (error: ManagedAuthApiError) => void;
172+
/** Fires only on graceful stream end (server closed the connection). Not called after onError. */
172173
onClose: () => void;
173174
}
174175

@@ -232,7 +233,8 @@ export function streamManagedAuthEvents(
232233
let data = "";
233234
for (const line of raw.split(/\r\n|\r|\n/)) {
234235
if (line.startsWith("event: ")) eventType = line.slice(7);
235-
else if (line.startsWith("data: ")) data = line.slice(6);
236+
else if (line.startsWith("data: "))
237+
data += (data ? "\n" : "") + line.slice(6);
236238
}
237239

238240
if (eventType === "managed_auth_state" && data) {
@@ -252,7 +254,7 @@ export function streamManagedAuthEvents(
252254
} catch {
253255
/* fall through with default message */
254256
}
255-
handlers.onError(new ManagedAuthApiError(message, 500, data, true));
257+
handlers.onError(new ManagedAuthApiError(message, 0, data, true));
256258
controller.abort();
257259
return;
258260
}

‎packages/managed-auth-react/src/lib/types.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export interface ManagedAuthResponse {
8181
profile_name: string;
8282
flow_status: FlowStatus;
8383
flow_step: FlowStep;
84+
flow_type?: "LOGIN" | "REAUTH" | null;
8485
discovered_fields?: DiscoveredField[] | null;
8586
pending_sso_buttons?: SSOButton[] | null;
8687
mfa_options?: MFAOption[] | null;
@@ -90,6 +91,9 @@ export interface ManagedAuthResponse {
9091
website_error?: string | null;
9192
error_message?: string | null;
9293
error_code?: string | null;
94+
post_login_url?: string | null;
95+
live_view_url?: string | null;
96+
hosted_url?: string | null;
9397
}
9498

9599
export type UIState =

‎packages/managed-auth-react/src/session/useManagedAuthSession.ts‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useCallback, useEffect, useRef, useState } from "react";
22
import {
33
exchangeHandoffCode,
4+
ManagedAuthApiError,
45
retrieveManagedAuth,
56
streamManagedAuthEvents,
67
submitFieldValues,
@@ -55,6 +56,7 @@ function mergeStateEvent(
5556
...base,
5657
flow_status: ev.flow_status,
5758
flow_step: ev.flow_step,
59+
flow_type: ev.flow_type ?? base.flow_type ?? null,
5860
discovered_fields: ev.discovered_fields ?? null,
5961
pending_sso_buttons: ev.pending_sso_buttons ?? null,
6062
mfa_options: ev.mfa_options ?? null,
@@ -63,6 +65,9 @@ function mergeStateEvent(
6365
website_error: ev.website_error ?? null,
6466
error_message: ev.error_message ?? null,
6567
error_code: ev.error_code ?? null,
68+
post_login_url: ev.post_login_url ?? base.post_login_url ?? null,
69+
live_view_url: ev.live_view_url ?? base.live_view_url ?? null,
70+
hosted_url: ev.hosted_url ?? base.hosted_url ?? null,
6671
};
6772
}
6873

@@ -79,6 +84,7 @@ export interface ManagedAuthSessionValue {
7984
state: ManagedAuthResponse | null;
8085
uiState: UIState;
8186
isSubmitting: boolean;
87+
isReconnecting: boolean;
8288
submitError: string | null;
8389
initError: string | null;
8490
startFlow: () => void;
@@ -101,6 +107,7 @@ export function useManagedAuthSession(
101107
const [state, setState] = useState<ManagedAuthResponse | null>(null);
102108
const [uiState, setUIState] = useState<UIState>("prime");
103109
const [isSubmitting, setIsSubmitting] = useState(false);
110+
const [isReconnecting, setIsReconnecting] = useState(false);
104111
const [submitError, setSubmitError] = useState<string | null>(null);
105112
const [initError, setInitError] = useState<string | null>(null);
106113

@@ -156,6 +163,7 @@ export function useManagedAuthSession(
156163

157164
const handleStateEvent = (ev: ManagedAuthStateEventData) => {
158165
reconnectAttemptsRef.current = 0;
166+
setIsReconnecting(false);
159167
setSubmitError(null);
160168
const base = stateRef.current;
161169
if (!base) return;
@@ -186,6 +194,7 @@ export function useManagedAuthSession(
186194

187195
const scheduleReconnect = () => {
188196
if (terminalRef.current) return;
197+
setIsReconnecting(true);
189198
const attempt = reconnectAttemptsRef.current++;
190199
const delay = Math.min(
191200
RECONNECT_BASE_MS * Math.pow(2, attempt),
@@ -229,7 +238,8 @@ export function useManagedAuthSession(
229238
connectStream(t);
230239
} catch (err) {
231240
if (gen !== generationRef.current) return;
232-
const status = (err as { status?: number })?.status;
241+
const status =
242+
err instanceof ManagedAuthApiError ? err.status : undefined;
233243
if (status === 401 || status === 410) {
234244
terminalRef.current = true;
235245
setUIState("expired");
@@ -437,6 +447,7 @@ export function useManagedAuthSession(
437447
state,
438448
uiState,
439449
isSubmitting,
450+
isReconnecting,
440451
submitError,
441452
initError,
442453
startFlow,

0 commit comments

Comments
 (0)