Skip to content

Commit 94046dd

Browse files
authored
Merge pull request #24 from corymsmith/cs/add-proxy-header-support
feat: adding support for passing headers to proxies
2 parents ef36ab1 + 2a6fba5 commit 94046dd

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ const PlaceDetailsExample = () => {
215215
| onBlur | (event: NativeSyntheticEvent<TextInputFocusEventData>) => void | No | - | Callback when input is blurred |
216216
| **Search Configuration** |
217217
| proxyUrl | string | No | - | Custom proxy URL for API requests (Required for Expo web) |
218+
| proxyHeaders | object | No | - | Headers to pass to the proxy (ex. { Authorization: 'Bearer AUTHTOKEN' } ) |
218219
| languageCode | string | No | - | Language code (e.g., 'en', 'fr') |
219220
| includedRegionCodes | string[] | No | - | Array of region codes to filter results |
220221
| types | string[] | No | [] | Array of place types to filter |
@@ -224,6 +225,7 @@ const PlaceDetailsExample = () => {
224225
| **Place Details Configuration** |
225226
| fetchDetails | boolean | No | false | Automatically fetch place details when a place is selected |
226227
| detailsProxyUrl | string | No | null | Custom proxy URL for place details requests (Required on Expo web)|
228+
| detailsProxyHeaders | object | No | - | Headers to pass to the place details proxy (ex. { Authorization: 'Bearer AUTHTOKEN' } ) |
227229
| detailsFields | string[] | No | ['displayName', 'formattedAddress', 'location', 'id'] | Array of fields to include in the place details response. see [Valid Fields](https://developers.google.com/maps/documentation/places/web-service/place-details#fieldmask) |
228230
| **UI Customization** |
229231
| showLoadingIndicator | boolean | No | true | Show loading spinner during API requests |

src/GooglePlacesTextInput.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ interface GooglePlacesTextInputProps extends TextInputInheritedProps {
100100
value?: string;
101101
placeHolderText?: string;
102102
proxyUrl?: string;
103+
proxyHeaders?: Record<string, string>;
103104
languageCode?: string;
104105
includedRegionCodes?: string[];
105106
types?: string[];
@@ -118,6 +119,7 @@ interface GooglePlacesTextInputProps extends TextInputInheritedProps {
118119
nestedScrollEnabled?: boolean;
119120
fetchDetails?: boolean;
120121
detailsProxyUrl?: string | null;
122+
detailsProxyHeaders?: Record<string, string>;
121123
detailsFields?: string[];
122124
onError?: (error: any) => void;
123125
enableDebug?: boolean;
@@ -145,6 +147,7 @@ const GooglePlacesTextInput = forwardRef<
145147
value,
146148
placeHolderText,
147149
proxyUrl,
150+
proxyHeaders = null,
148151
languageCode,
149152
includedRegionCodes,
150153
types = [],
@@ -163,6 +166,7 @@ const GooglePlacesTextInput = forwardRef<
163166
nestedScrollEnabled = true,
164167
fetchDetails = false,
165168
detailsProxyUrl = null,
169+
detailsProxyHeaders = null,
166170
detailsFields = [],
167171
onError,
168172
enableDebug = false,
@@ -271,6 +275,7 @@ const GooglePlacesTextInput = forwardRef<
271275
text,
272276
apiKey: apiKey ? '[PROVIDED]' : '[MISSING]', // ✅ Security fix
273277
proxyUrl,
278+
proxyHeaders,
274279
sessionToken,
275280
languageCode,
276281
includedRegionCodes,
@@ -294,6 +299,7 @@ const GooglePlacesTextInput = forwardRef<
294299
text,
295300
apiKey,
296301
proxyUrl,
302+
proxyHeaders,
297303
sessionToken,
298304
languageCode,
299305
includedRegionCodes,
@@ -330,6 +336,7 @@ const GooglePlacesTextInput = forwardRef<
330336
placeId,
331337
apiKey: apiKey ? '[PROVIDED]' : '[MISSING]', // ✅ Security fix
332338
detailsProxyUrl,
339+
detailsProxyHeaders,
333340
sessionToken,
334341
languageCode,
335342
detailsFields,

src/services/googlePlacesApi.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ interface FetchPredictionsParams {
66
text: string;
77
apiKey?: string;
88
proxyUrl?: string;
9+
proxyHeaders?: Record<string, string> | null;
910
sessionToken?: string | null;
1011
languageCode?: string;
1112
includedRegionCodes?: string[];
@@ -17,6 +18,7 @@ interface FetchPlaceDetailsParams {
1718
placeId: string;
1819
apiKey?: string;
1920
detailsProxyUrl?: string | null;
21+
detailsProxyHeaders?: Record<string, string> | null;
2022
sessionToken?: string | null;
2123
languageCode?: string;
2224
detailsFields?: string[];
@@ -39,6 +41,7 @@ export const fetchPredictions = async ({
3941
text,
4042
apiKey,
4143
proxyUrl,
44+
proxyHeaders,
4245
sessionToken,
4346
languageCode,
4447
includedRegionCodes,
@@ -57,6 +60,12 @@ export const fetchPredictions = async ({
5760
'Content-Type': 'application/json',
5861
};
5962

63+
if (proxyUrl && proxyHeaders) {
64+
Object.entries(proxyHeaders).forEach(([key, value]) => {
65+
headers[key] = value;
66+
});
67+
}
68+
6069
if (apiKey) {
6170
headers['X-Goog-Api-Key'] = apiKey;
6271
}
@@ -96,6 +105,7 @@ export const fetchPlaceDetails = async ({
96105
placeId,
97106
apiKey,
98107
detailsProxyUrl,
108+
detailsProxyHeaders,
99109
sessionToken,
100110
languageCode,
101111
detailsFields = [],
@@ -113,6 +123,12 @@ export const fetchPlaceDetails = async ({
113123
'Content-Type': 'application/json',
114124
};
115125

126+
if (detailsProxyUrl && detailsProxyHeaders) {
127+
Object.entries(detailsProxyHeaders).forEach(([key, value]) => {
128+
headers[key] = value;
129+
});
130+
}
131+
116132
if (apiKey) {
117133
headers['X-Goog-Api-Key'] = apiKey;
118134
}

0 commit comments

Comments
 (0)