Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Custom image headers (AKA imageHeadersProvider in Stream Chat Android SDK) #2990

Open
andrijanovakovic opened this issue Mar 3, 2025 · 0 comments

Comments

@andrijanovakovic
Copy link

andrijanovakovic commented Mar 3, 2025

Summary:
This request is for a feature that already exists in Stream Chat Android SDK - imageHeadersProvider (more info on that: https://getstream.io/chat/docs/sdk/android/ui/general-customization/chatui/#adding-extra-headers-to-image-requests)

Background:
We host user avatars on our own CDN that requires a valid Authorization header in order to serve images. Although the Android SDK provides the ability to add extra headers via imageHeadersProvider, the React Native SDK currently does not offer an equivalent feature. This forces us to override channel avatars, message avatars, group avatars, reply avatars and so on...

Using ImageComponent prop on <Chat /> component does not help us because the image source is overriden by your Avatar, MessageAvatar, ... (see more in the snippet below)

Code snippet from Stream Chat Avatar.tsx:

        <ImageComponent
          accessibilityLabel={testID || 'Avatar Image'}
          onError={() => setLoadingImageError(true)}
          source={{

            // Even if our custom ImageComponent has a `headers` key in the image source,
            // it is being overriden here. 

            uri:
              !imageProp ||
              imageProp.includes(randomImageBaseUrl) ||
              imageProp.includes(randomSvgBaseUrl)
                ? imageProp?.includes(streamCDN)
                  ? imageProp
                  : `${randomImageBaseUrl}${
                      name ? `?name=${getInitials(name)}&size=${size}` : ''
                    }`
                : getResizedImageUrl({
                    height: size,
                    resizableCDNHosts,
                    url: imageProp,
                    width: size,
                  }),
          }}
          style={[
            image,
            size
              ? {
                  backgroundColor: '#ececec',
                  borderRadius: size / 2,
                  height: size,
                  width: size,
                }
              : {},
            imageStyle,
          ]}
          testID={testID || 'avatar-image'}
        />

Proposed solution
Introduce an imageHeadersProvider (or similar mechanism) in the React Native SDK that mirrors the functionality available in the Android SDK. This feature should allow developers to supply a function or object that provides custom headers for every image request made by the SDK, ensuring that headers like Authorization are consistently applied across all components. If the SDK supported an imageHeadersProvider, we could easily inject headers (e.g., { Authorization: 'Bearer <token>' }) into every image request.

Acceptance criteria

  • Developers can pass an imageHeadersProvider as a prop on the Chat component.
  • The headers returned by the imageHeadersProvider are automatically applied to all image requests, including those in subcomponents such as MessageAvatar, ChannelAvatar, ... OR consider applying the imageHeadersProvider only if the image source IS NOT a stream chat URL (I would like my JWT token to be sent only to my own servers).
  • The provider accepts either a static header object or a function returning a header object, accommodating dynamic tokens.
  • Existing implementations without imageHeadersProvider remain unaffected.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant