@@ -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 */
@@ -109,6 +123,13 @@ type StartConnectOpts = {
109123 * @param err - The error that occurred during the connection.
110124 */
111125 onError ?: ( err : ConnectError ) => void ;
126+
127+ /**
128+ * Callback function to be called when the Connect iFrame is closed.
129+ *
130+ * @param status - The status of the connection when closed.
131+ */
132+ onClose ?: ( status : ConnectStatus ) => void ;
112133} ;
113134
114135/**
@@ -223,22 +244,37 @@ export class BrowserClient extends BaseClient {
223244 * onError: (err) => {
224245 * console.error("Connection error:", err);
225246 * },
247+ * onClose: (status) => {
248+ * if (!status.successful) {
249+ * console.log("User closed without connecting");
250+ * }
251+ * },
226252 * });
227253 * ```
228254 */
229255 public async connectAccount ( opts : StartConnectOpts ) {
256+ let connectionSuccessful = false ;
257+ let connectionCompleted = false ;
258+
230259 const onMessage = ( e : MessageEvent ) => {
231260 switch ( e . data ?. type ) {
232261 case "success" :
262+ connectionSuccessful = true ;
263+ connectionCompleted = true ;
233264 opts . onSuccess ?.( {
234265 id : e . data ?. authProvisionId ,
235266 } ) ;
236267 break ;
237268 case "error" :
269+ connectionCompleted = true ;
238270 opts . onError ?.( new ConnectError ( e . data . error ) ) ;
239271 break ;
240272 case "close" :
241273 this . cleanup ( onMessage ) ;
274+ opts . onClose ?.( {
275+ successful : connectionSuccessful ,
276+ completed : connectionCompleted ,
277+ } ) ;
242278 break ;
243279 default :
244280 break ;
0 commit comments