expo: AuthSession.useAuthRequest never loads request due to rejected promise from getRandomBytesAsync

🐛 Bug Report

Summary of Issue

I am trying to implement social logins (starting with Facebook) by making use of AuthSession. According to the documentation, it is supposed to return a AuthRequest object once it has been loaded. This never happens due to a unhandled rejected promise with this error: TypeError: null is not an object (evaluating '_ExpoRandom.default.getRandomBytesAsync')

Environment - output of expo diagnostics & the platform(s) you’re targeting

System: OS: Linux 5.4 Ubuntu 20.04.1 LTS (Focal Fossa) Shell: 5.0.17 - /bin/bash Binaries: Node: 14.4.0 - ~/.nvm/versions/node/v14.4.0/bin/node npm: 6.14.7 - ~/.nvm/versions/node/v14.4.0/bin/npm npmPackages: expo: ~38.0.8 => 38.0.8 react: ~16.11.0 => 16.11.0 react-dom: ~16.11.0 => 16.11.0 react-native: ~0.62.2 => 0.62.2 react-native-web: ~0.11.7 => 0.11.7 react-navigation: ^4.4.0 => 4.4.0 npmGlobalPackages: expo-cli: 3.24.2

Steps to Reproduce

  1. Initialize a new bare expo project with expo init
  2. Install dependencies: expo install expo-auth-session
  3. Call useAuthRequest function like so: const [request, response, promptAsync] = useAuthRequest( { clientId: "<my Facebook app id>", scopes: ["public_profile", "user_likes"], redirectUri: makeRedirectUri({ native: "fb<my Facebook app id>://authorize", }), }, { authorizationEndpoint: "https://www.facebook.com/v6.0/dialog/oauth", tokenEndpoint: "https://graph.facebook.com/v6.0/oauth/access_token", } );

Expected Behavior vs Actual Behavior

I expected useAuthRequest to eventually load the request object so I can prompt the user for access.

What happens instead is that useAuthRequest never succesfully loads the request. It appears that some internal part of the function relies on Expo random getBytesAsync() and for some reason that is null when used inside useAuthRequest.

Note: I have no issues manually using the getRandomBytesAsync function manually in an isolated environment.

This is my first Github issue so forgive me if I am forgetting something. I will keep a close eye here and update according to eventual comments.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 2
  • Comments: 19 (5 by maintainers)

Most upvoted comments

My above concern seems to be fixed by @brentvatne latest comment.

I did yarn remove expo-auth-session && expo install expo-auth-session.

Seems this happened because the version of expo-auth-session I published earlier today was using @next versions of expo-crypto and expo-random which caused them to be installed in node_modules/expo-auth-session/node_modules/* instead of node_modules/* which is why the native module wasn’t registered.

I just republished with the lower versions yarn add expo-auth-session@~1.5.1 should solve the problem for now.

Pro Tip: You can use “yarn resolutions” to force the version of expo-random to be the same across all packages. If you get blocked on an issue like this in the future this can help unblock you for a bit!

@gsanguinetti - try following @santiripper’s suggestion above. install expo-random into your project with yarn add expo-random

I’m having the same error message as originally described and the command yarn remove expo-auth-session && expo install expo-auth-session did not work for me. Is there anything else I should try??

Also, I am on SDK 39.