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

native platform fixes #951

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rojiphil
Copy link
Contributor

@rojiphil rojiphil commented Oct 7, 2024

Follow-up PR to this to resolve native platform issues:

  • Implement session token using random generator instead of crypto.getRandomValues which is not supported on iOS native devices.
  • Add content-type to avoid API request failure on android native devices.

});

const generateSessionToken = useCallback(() => {
return uuidv4({ rng: randomGenerator });
Copy link
Contributor Author

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.

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 👍

Copy link
Contributor Author

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

Yeah. I don't see any valid reason either to make it so secure.

@@ -628,6 +643,10 @@ export const GooglePlacesAutocomplete = forwardRef((props, ref) => {
setRequestHeaders(request, getRequestHeaders(props.requestUrl));

if (props.isNewPlacesAPI) {
request.setRequestHeader(
'content-type',
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 content-type header. Adding the header resolves the issue with Android native devices.

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The response (as shared in screenshot below) precisely pointed out this reason and so didn’t dig deeper. But your question on why specifically this happens on Android is interesting. I will take a closer look at this.

Screenshot 2024-10-09 at 1 23 01 PM

Choose a reason for hiding this comment

The 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

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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

@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 content-type to be sent. The only way to programmatically avoid this response is to avoid JSON.stringify but it does not seem to be a viable option for us.
So, It looks like we have to address the issue in desktop platform along with the content-type and we are discussing this here

Screenshot 2024-10-29 at 6 33 48 AM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants