File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed
Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -120,6 +120,9 @@ export function usePollMessages() {
120120 signal : AbortSignal . timeout ( 5_000 ) ,
121121 } )
122122 if ( ! response . ok ) {
123+ if ( response . status === 401 ) {
124+ useConnectionStore . getState ( ) . disconnect ( )
125+ }
123126 return
124127 }
125128 const payload = ( await response . json ( ) ) as {
Original file line number Diff line number Diff line change @@ -68,10 +68,20 @@ export const useConnectionStore = create<ConnectionStore>()(
6868 const tempSdk = new TelagentSdk ( { baseUrl : nodeUrl } )
6969 const result = await tempSdk . unlockSession ( { passphrase } )
7070
71- // 3. Create authenticated SDK with session token
71+ // 3. Create authenticated SDK with session token.
72+ // Wrap fetch to detect 401 responses and auto-disconnect so
73+ // ProtectedRoute redirects back to /connect without relying on
74+ // every catch-block to re-throw the error.
7275 const sdk = new TelagentSdk ( {
7376 baseUrl : nodeUrl ,
7477 accessToken : result . sessionToken ,
78+ fetchImpl : ( input , init ) =>
79+ fetch ( input , init ) . then ( ( res ) => {
80+ if ( res . status === 401 ) {
81+ get ( ) . disconnect ( )
82+ }
83+ return res
84+ } ) ,
7585 } )
7686 set ( {
7787 nodeUrl,
@@ -119,6 +129,13 @@ export const useConnectionStore = create<ConnectionStore>()(
119129 sdk : new TelagentSdk ( {
120130 baseUrl : nodeUrl ,
121131 accessToken : sessionToken ,
132+ fetchImpl : ( input , init ) =>
133+ fetch ( input , init ) . then ( ( res ) => {
134+ if ( res . status === 401 ) {
135+ get ( ) . disconnect ( )
136+ }
137+ return res
138+ } ) ,
122139 } ) ,
123140 status : "connected" ,
124141 error : undefined ,
You can’t perform that action at this time.
0 commit comments