AuthSession in production


#1

Hey Folks,
I built an app that uses Expo.AuthSession.startAsync to authenticate to an oauth service. It works in development. I built the app for android expo build:android and installed the resulting apk. However, the sign in button does nothing when pressed. Have I made a simple mistake? And what’s the best way to troubleshoot production bugs?

Here is my signIn function (working in development)

  signIn = async () => {
    try {
      let redirectUrl = Expo.AuthSession.getRedirectUrl();
      const result = await Expo.AuthSession.startAsync({
        authUrl:
          `https://memair.com/oauth/authorize?` +
          `&client_id=foo` +
          `&redirect_uri=${encodeURIComponent(redirectUrl)}` +
          `&response_type=code` +
         `&scope=location_read+location_write`
      });

      if (result.type === "success") {
        var body =
          `grant_type=authorization_code` +
          `&client_id=foo` +
          `&client_secret=bar` +
          `&code=${result.params.code}` +
          `&redirect_uri=${encodeURIComponent(redirectUrl)}`

        fetch('https://memair.com/oauth/token', {
          method: 'POST',
          headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
          },
          body: body
        })
        .then((response) => {
          return response.json()
        })
        .then((data) => {
          this.setState({
            accessToken: data['access_token'],
            signedIn: true
          })
        });
        console.log("logged in")
      } else {
        console.log("cancelled")
      }
    } catch (e) {
      console.log("error", e)
    }
  }

Cheers Team!


closed #2

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.