AuthSession.useAuthRequest never loads request due to rejected promise from getRandomBytesAsync
See original GitHub issue🐛 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
- Initialize a new bare expo project with
expo init - Install dependencies:
expo install expo-auth-session - 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.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:19 (5 by maintainers)
Top Related StackOverflow Question
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-sessionI published earlier today was using@nextversions ofexpo-cryptoandexpo-randomwhich caused them to be installed innode_modules/expo-auth-session/node_modules/*instead ofnode_modules/*which is why the native module wasn’t registered.I just republished with the lower versions
yarn add expo-auth-session@~1.5.1should solve the problem for now.Pro Tip: You can use “yarn resolutions” to force the version of
expo-randomto 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!