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

Possible unhandled promise rejection (id: 0): TypeError: Network request failed #1

Closed
dijarvrella opened this issue Apr 13, 2024 · 4 comments

Comments

@dijarvrella
Copy link

Hi @rbrki07,

First of all great work. Really inspiring!

Can you please provide some guidance as I can't make this run successfully.

It fails on with the following: Possible unhandled promise rejection (id: 0): TypeError: Network request failed and I believe that is due to useAutoDiscovery function not returning a valid discovery object of interface DiscoveryDocument.

Then if I try to type Sign in button I get Possible unhandled promise rejection (id: 5): Error: Cannot prompt to authenticate until the request has finished loading.

Fastest way to replicate the problem is:

  1. clone your repo,
    git clone git@github.com:rbrki07/rn-expo-oauth-authorization-code-flow-pkce-keycloak.git
  2. run the keycloak:
    docker run --name keycloak --detach --publish 11111:8080 --env KEYCLOAK_ADMIN=admin --env KEYCLOAK_ADMIN_PASSWORD=admin quay.io/keycloak/keycloak:latest start-dev

I have configured keycloak same as you have it shown in your blog but I am attaching the realm export ran using:
docker exec -it keycloak /opt/keycloak/bin/kc.sh export --file /tmp/realm-export.json --realm test --users realm_file
realm-export.json
4. run npx expo start
5. Scan the QR code from Android/iOS
6. Possible unhandled promise rejection (id: 0): TypeError: Network request failed pops out

@rbrki07
Copy link
Owner

rbrki07 commented Apr 13, 2024

Hi @dijarvrella,
sounds like a network issue. Are you running the Expo app on a real device? If yes, the app won't find Keycloak running on http://localhost:11111/ on your development computer.

@dijarvrella
Copy link
Author

dijarvrella commented Apr 13, 2024

Hi @rbrki07, thanks for the quick response.

I am running Expo app on my local machine. The Keycloak is also running on my local machine.

I made it all work I hardcoded discovery object as follows:

const discovery = {
    authorizationEndpoint:
      'http://192.168.0.87:11111/realms/test/protocol/openid-connect/auth',
    tokenEndpoint:
      'http://192.168.0.87:11111/realms/test/protocol/openid-connect/token',
    revocationEndpoint:
      'http://192.168.0.87:11111/realms/test/protocol/openid-connect/revoke',
    endSessionEndpoint:
      'http://192.168.0.87:11111/realms/test/protocol/openid-connect/logout',
    userInfoEndpoint:
      'http://192.168.0.87:11111/realms/test/protocol/openid-connect/userinfo',
  }

It looks to me the problem seems to be related with this useAutoDiscovery function.

the IP address there is my private IP on my localmachine but due to running expo app now with @expo/ngrok tunnel

@rbrki07
Copy link
Owner

rbrki07 commented Apr 13, 2024

Well, that's strange. I will try to reproduce your problem using the latest Expo SDK and module version.

@dijarvrella
Copy link
Author

alright, I was able to resolve this by doing the following:

  1. Update the env to use the IP of the interface rather than localhostEXPO_PUBLIC_KEYCLOAK_URL='http://<interface_IP>:<keycloak_port>/realms/<realm_name>''

Thanks for all the help and making this available for all.

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

No branches or pull requests

2 participants