@@ -70,6 +70,20 @@ type ConnectResult = {
7070 id : string ;
7171} ;
7272
73+ /**
74+ * The status when the Connect dialog is closed.
75+ */
76+ type ConnectStatus = {
77+ /**
78+ * Whether the connection was successful (account was connected).
79+ */
80+ successful : boolean ;
81+ /**
82+ * Whether the connection process was completed (vs user closing early).
83+ */
84+ completed : boolean ;
85+ } ;
86+
7387/**
7488 * Custom error class for handling connection errors.
7589 */
@@ -112,14 +126,10 @@ type StartConnectOpts = {
112126
113127 /**
114128 * Callback function to be called when the Connect iFrame is closed.
129+ *
130+ * @param status - The status of the connection when closed.
115131 */
116- onClose ?: ( ) => void ;
117-
118- /**
119- * Callback function to be called when the user cancels/closes the Connect
120- * iFrame without successfully connecting an account.
121- */
122- onCancel ?: ( ) => void ;
132+ onClose ?: ( status : ConnectStatus ) => void ;
123133} ;
124134
125135/**
@@ -234,36 +244,37 @@ export class BrowserClient extends BaseClient {
234244 * onError: (err) => {
235245 * console.error("Connection error:", err);
236246 * },
237- * onClose: () => {
238- * console.log("Connect iFrame closed");
239- * },
240- * onCancel: () => {
241- * console.log("User cancelled without connecting");
247+ * onClose: (status) => {
248+ * if (!status.successful) {
249+ * console.log("User closed without connecting");
250+ * }
242251 * },
243252 * });
244253 * ```
245254 */
246255 public async connectAccount ( opts : StartConnectOpts ) {
247256 let connectionSuccessful = false ;
257+ let connectionCompleted = false ;
248258
249259 const onMessage = ( e : MessageEvent ) => {
250260 switch ( e . data ?. type ) {
251261 case "success" :
252262 connectionSuccessful = true ;
263+ connectionCompleted = true ;
253264 opts . onSuccess ?.( {
254265 id : e . data ?. authProvisionId ,
255266 } ) ;
256267 break ;
257268 case "error" :
269+ connectionCompleted = true ;
258270 opts . onError ?.( new ConnectError ( e . data . error ) ) ;
259271 break ;
260272 case "close" :
261273 this . cleanup ( onMessage ) ;
262- opts . onClose ?.( ) ;
263- // Call onCancel if the connection wasn't successful
264- if ( ! connectionSuccessful ) {
265- opts . onCancel ?.( ) ;
266- }
274+ opts . onClose ?.( {
275+ successful : connectionSuccessful ,
276+ completed : connectionCompleted ,
277+ } ) ;
267278 break ;
268279 default :
269280 break ;
0 commit comments