diff --git a/native/input/input-state-container.react.js b/native/input/input-state-container.react.js --- a/native/input/input-state-container.react.js +++ b/native/input/input-state-container.react.js @@ -19,6 +19,7 @@ updateMultimediaMessageMediaActionType, useBlobServiceUpload, } from 'lib/actions/upload-actions.js'; +import { useInvalidCSATLogOut } from 'lib/actions/user-actions.js'; import { type SendMultimediaMessagePayload, useInputStateContainerSendMultimediaMessage, @@ -158,6 +159,7 @@ ) => Promise, +newThickThread: (request: NewThickThreadRequest) => Promise, +textMessageCreationSideEffectsFunc: CreationSideEffectsFunc, + +invalidTokenLogOut: () => Promise, }; type State = { +pendingUploads: PendingMultimediaUploads, @@ -392,6 +394,9 @@ return result; } catch (e) { const exceptionMessage = getMessageForException(e) ?? ''; + if (exceptionMessage === 'invalid_csat') { + void this.props.invalidTokenLogOut(); + } throw new SendMessageError( `Exception when sending multimedia message: ${exceptionMessage}`, localID, @@ -915,6 +920,10 @@ mediaMissionResult = { success: true }; } catch (e) { uploadExceptionMessage = getMessageForException(e); + if (uploadExceptionMessage === 'invalid_csat') { + void this.props.invalidTokenLogOut(); + return undefined; + } onUploadFailed('upload failed'); mediaMissionResult = { success: false, @@ -1709,6 +1718,7 @@ const staffCanSee = useStaffCanSee(); const textMessageCreationSideEffectsFunc = useMessageCreationSideEffectsFunc(messageTypes.TEXT); + const callInvalidTokenLogOut = useInvalidCSATLogOut(); return ( ); }); diff --git a/web/input/input-state-container.react.js b/web/input/input-state-container.react.js --- a/web/input/input-state-container.react.js +++ b/web/input/input-state-container.react.js @@ -24,6 +24,7 @@ useBlobServiceUpload, useDeleteUpload, } from 'lib/actions/upload-actions.js'; +import { useInvalidCSATLogOut } from 'lib/actions/user-actions.js'; import { type PushModal, useModalContext, @@ -157,6 +158,7 @@ +unregisterSendCallback: (() => mixed) => void, +textMessageCreationSideEffectsFunc: CreationSideEffectsFunc, +identityContext: ?IdentityClientContextType, + +invalidTokenLogOut: () => Promise, }; type WritableState = { pendingUploads: { @@ -558,6 +560,9 @@ return result; } catch (e) { const exceptionMessage = getMessageForException(e) ?? ''; + if (exceptionMessage === 'invalid_csat') { + void this.props.invalidTokenLogOut(); + } throw new SendMessageError( `Exception while sending multimedia message: ${exceptionMessage}`, localID, @@ -931,6 +936,10 @@ }); } catch (e) { uploadExceptionMessage = getMessageForException(e); + if (uploadExceptionMessage === 'invalid_csat') { + void this.props.invalidTokenLogOut(); + return; + } this.handleUploadFailure(threadID, localID); } userTime = Date.now() - selectTime; @@ -1203,7 +1212,7 @@ }); } if (isBlobServiceURI(pendingUpload.uri)) { - const identityContext = this.props.identityContext; + const { invalidTokenLogOut, identityContext } = this.props; invariant(identityContext, 'Identity context should be set'); invariant( pendingUpload.blobHolder, @@ -1215,7 +1224,13 @@ const authMetadata = await identityContext.getAuthMetadata(); const defaultHeaders = createDefaultHTTPRequestHeaders(authMetadata); - await removeBlobHolder({ blobHash, holder }, defaultHeaders); + const result = await removeBlobHolder( + { blobHash, holder }, + defaultHeaders, + ); + if (!result.success && result.reason === 'INVALID_CSAT') { + void invalidTokenLogOut(); + } })(); } } @@ -1664,6 +1679,7 @@ const dispatchActionPromise = useDispatchActionPromise(); const modalContext = useModalContext(); const identityContext = React.useContext(IdentityClientContext); + const callInvalidTokenLogOut = useInvalidCSATLogOut(); const [sendCallbacks, setSendCallbacks] = React.useState< $ReadOnlyArray<() => mixed>, @@ -1705,6 +1721,7 @@ unregisterSendCallback={unregisterSendCallback} textMessageCreationSideEffectsFunc={textMessageCreationSideEffectsFunc} identityContext={identityContext} + invalidTokenLogOut={callInvalidTokenLogOut} /> ); });