Search code examples
androidiosreact-nativereact-native-webview

How to pass jwt token in request header of react-native-webview?


How to pass jwt token in request header of react-native-webview to display protected webpages content.

The below code is not working :

 <WebView
 
    source={{
      uri: 'website url',
      headers: {
        Authorization:
          'Bearer'+'eyJ0eX...........',
      },
    }}

  /> 

Solution

  • Solution: Use below code

    <>
          <ActivityIndicator visible={isLoading} />
          <WebView
            source={{
              uri: 'https://.....', headers: {
                Authorization: `Bearer ${token}`,
              },
            }}
            onLoadStart={() => setIsLoading(false)}
          />
        </>

    and then set the cookie from backend