-
-
Notifications
You must be signed in to change notification settings - Fork 855
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
native platform fixes #951
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -160,7 +160,22 @@ export const GooglePlacesAutocomplete = forwardRef((props, ref) => { | |
const [listLoaderDisplayed, setListLoaderDisplayed] = useState(false); | ||
|
||
const inputRef = useRef(); | ||
const [sessionToken, setSessionToken] = useState(uuidv4()); | ||
|
||
const randomGenerator = useCallback(() => { | ||
const randomByteArray = []; | ||
for (let i = 0; i < 16; i++) { | ||
const rand = Math.floor(Math.random() * 256); | ||
randomByteArray.push(rand); | ||
} | ||
return randomByteArray; | ||
}); | ||
|
||
const generateSessionToken = useCallback(() => { | ||
return uuidv4({ rng: randomGenerator }); | ||
}, [randomGenerator]); | ||
|
||
const [sessionToken, setSessionToken] = useState(generateSessionToken()); | ||
|
||
useEffect(() => { | ||
setUrl(getRequestUrl(props.requestUrl)); | ||
}, [getRequestUrl, props.requestUrl]); | ||
|
@@ -337,7 +352,7 @@ export const GooglePlacesAutocomplete = forwardRef((props, ref) => { | |
fields: props.fields, | ||
}), | ||
); | ||
setSessionToken(uuidv4()); | ||
setSessionToken(generateSessionToken()); | ||
} else { | ||
request.open( | ||
'GET', | ||
|
@@ -628,6 +643,10 @@ export const GooglePlacesAutocomplete = forwardRef((props, ref) => { | |
setRequestHeaders(request, getRequestHeaders(props.requestUrl)); | ||
|
||
if (props.isNewPlacesAPI) { | ||
request.setRequestHeader( | ||
'content-type', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On Android native devices, the API request fails with the response message stating that it needs There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you help me understand why specifically this happens on android and if this is the only fix? As you stated in your App PR, adding this header causes CORS errors - I noticed this on dev too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks yeah please do, it is very strange. AFAIK that response is not coming from the server There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@rafecolton That's correct. The response comes from android native implementation as referenced in the screenshot below. Since we have stringified the request body of our POST request, android native implementation expects |
||
'application/json; charset=utf-8', | ||
); | ||
const { key, locationbias, types, ...rest } = props.query; | ||
request.send( | ||
JSON.stringify({ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we had an issue concerning usage of crypto.getRandomValues on iOS Native devices, we can use a random generator for session token generation which I think is good enough for the given scenario. This change works well on iOS devices.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't think of any reason these need to be cryptographically secure, can you? If not, this seems fine to me 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. I don't see any valid reason either to make it so secure.