Skip to content

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

@andrijanovakovic

Description

@andrijanovakovic

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions