React-native-app-auth: authorize promise never resolves/rejects

Created on 9 Feb 2021  路  4Comments  路  Source: FormidableLabs/react-native-app-auth

Issue

I have a simple app where I want to use Spotify as a way to register/log in. I followed the setup steps and implemented the authorization logic like this:

const openSpotify = async () => {
    const spotifyAuthConfig = {
      clientId: SPOTIFY_APP_CLIENT_ID,
      redirectUrl: 'org.example.app://callback',
      scopes: ['user-read-email'],
      serviceConfiguration: {
        authorizationEndpoint: 'https://accounts.spotify.com/authorize',
        tokenEndpoint: 'https://accounts.spotify.com/api/token',
      },
    };
    try {
      const result = await authorize(spotifyAuthConfig); // this promise hangs forever
      console.log(JSON.stringify(result)); // this never runs
      return result;
    } catch (error) {
      console.error(JSON.stringify(error)); // this never runs
    }
  };

  return (
    <View style={styles.container}>
      <Button title={t('LOGIN_BUTTON')} onPress={openSpotify} />
    </View>
  );

When I click on my login button, the message "ExampleApp Wants to Use spotify.com to Sign In" pops, and then I can sign in with my spotify account, press allow and the window dissapears but nothing happens. The authorize() promise stays pending even though the process went through. Any ideas what can I be doing wrong?


Environment

  • Your Identity Provider: Spotify OAuth
  • Platform that you're experiencing the issue on: iOS
  • Are you using Expo? No

Most helpful comment

Had a similar issue and discovered it was due to a missing trailing slash on the redirect url.

Change your redirectUrl from org.example.app://callback to org.example.app://callback/

See https://github.com/FormidableLabs/react-native-app-auth/issues/380#issuecomment-581517451

All 4 comments

The browser window closes for me and I鈥檓 back to my app and the promise still won鈥檛 resolve...

I ran into the same issue when starting a new project.

Turns out I was missing Step 3 of the installation:
https://github.com/FormidableLabs/react-native-app-auth#define-openurl-callback-in-appdelegate

Had a similar issue and discovered it was due to a missing trailing slash on the redirect url.

Change your redirectUrl from org.example.app://callback to org.example.app://callback/

See https://github.com/FormidableLabs/react-native-app-auth/issues/380#issuecomment-581517451

Thanks @badsyntax . You save my day.

Was this page helpful?
0 / 5 - 0 ratings