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

  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.

Issue Analytics

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

github_iconTop GitHub Comments

3reactions
zwasscommented, Sep 14, 2020

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

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

3reactions
EvanBaconcommented, Sep 14, 2020

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!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Request not being completed with Expo authSession
(Error message is: [Unhandled promise rejection: Error: Cannot prompt to authenticate until the request has finished loading.]).
Read more >
AuthSession - Expo Documentation
request - An instance of AuthRequest that can be used to prompt the user for authorization. This will be null until the auth...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found