expo / expo

An open-source framework for making universal native apps with React. Expo runs on Android, iOS, and the web.
https://docs.expo.dev
MIT License
34.51k stars 5.53k forks source link

WebBrowser.maybeCompleteAuthSession Fails with Strava Provider #18736

Closed michaelangeloio closed 1 year ago

michaelangeloio commented 2 years ago

Summary

Hi Expo Team! Unsure if this is the appropriate place to post this issue; Let me know if there is a better thread to use.

I am receiving the following error when using the Strava example for expo-auth-session (located here):


 1 of 1 unhandled error

Unhandled Runtime Error
TypeError: Cannot read properties of undefined (reading 'remove')

Call Stack
dismissPopup
../../node_modules/expo-web-browser/build/ExpoWebBrowser.web.js (33:54)
appStateListener
../../node_modules/expo-web-browser/build/ExpoWebBrowser.web.js (175:12)
HTMLDocument.callback
../../node_modules/react-native-web/dist/exports/AppState/index.js (37:17)

This is for the Brave Browser, the same issue is occurring on Chrome.

The following error happens on safari (which seems to be related).

Unhandled Runtime Error
TypeError: undefined is not an object (evaluating 'appStateSubscription.remove')

In the compiled build files for ExpoWebBrowser.web.js (which seems to handle the redirect logic for web), the errors seem to be occuring on lines 17-28, particularly at:

        appStateSubscription.remove();

That seems like a native object to determine the platform, but I could be wrong.

The redirect works; however, it seems that maybeCompleteAuthSession fails when parsing the window object info?

What platform(s) does this occur on?

Web

Environment

T

  expo-env-info 1.0.5 environment info:
    System:
      OS: macOS 12.5
      Shell: 3.5.0 - /usr/local/bin/fish
    Binaries:
      Node: 16.16.0 - ~/.nvm/versions/node/v16.16.0/bin/node
      Yarn: 1.22.19 - ~/.nvm/versions/node/v16.16.0/bin/yarn
      npm: 8.11.0 - ~/.nvm/versions/node/v16.16.0/bin/npm
    Managers:
      CocoaPods: 1.11.3 - /opt/homebrew/bin/pod
    SDKs:
      iOS SDK:
        Platforms: DriverKit 21.4, iOS 15.5, macOS 12.3, tvOS 15.4, watchOS 8.5
    IDEs:
      Android Studio: 2021.2 AI-212.5712.43.2112.8815526
      Xcode: 13.4.1/13F100 - /usr/bin/xcodebuild
    npmGlobalPackages:
      eas-cli: 0.58.0
      expo-cli: 6.0.1
    Expo Workflow: managed

Minimal reproducible example

The code is virtually identical to the example, however, I'm not sure if any other extraneous config (or lack thereof) is causing the issue.

import * as React from 'react'
import * as WebBrowser from 'expo-web-browser'
import { makeRedirectUri, useAuthRequest } from 'expo-auth-session'
import { Button } from 'native-base'

WebBrowser.maybeCompleteAuthSession({skipRedirectCheck: true})

// Endpoint
const discovery = {
  authorizationEndpoint: 'https://www.strava.com/oauth/mobile/authorize',
  tokenEndpoint: 'https://www.strava.com/oauth/token',
  revocationEndpoint: 'https://www.strava.com/oauth/deauthorize',
  skipRedirectCheck: true 
}

export default function StravaLogin() {
  const [request, response, promptAsync] = useAuthRequest(
    {
      clientId: process.env.NEXT_PUBLIC_STRAVA_CLIENT_ID || '',
      scopes: [process.env.NEXT_PUBLIC_STRAVA_APP_SCOPES || ''],
      // redirectUri: 'http://localhost:3000/onboard'
      redirectUri: makeRedirectUri({
        // For usage in bare and standalone
        // the "redirect" must match your "Authorization Callback Domain" in the Strava dev console.
        // native: 'https://auth.expo.io/@bagelhouse/activitystreak-local',
        // native: 'http://localhost:3000'
        preferLocalhost: true,
        path: '/onboard',
      }),
    },
    discovery
  )

  React.useEffect(() => {
    if (response?.type === 'success') {
      const { code } = response.params
    }
  }, [response])

  return (<>
    <Button disabled={!request}
      onPress={() => {
        promptAsync()
      }}> Login with Strava</Button>
  </>
  )
}
TalhaBlueEast commented 2 years ago

I am also facing the same issue as

Uncaught TypeError: Cannot read properties of undefined (reading 'remove') at dismissPopup (ExpoWebBrowser.web.ts:33:1) at listener (ExpoWebBrowser.web.ts:158:1) at sentryWrapped (helpers.js:74:1)

TalhaBlueEast commented 2 years ago

I am also facing the same issue as

Uncaught TypeError: Cannot read properties of undefined (reading 'remove') at dismissPopup (ExpoWebBrowser.web.ts:33:1) at listener (ExpoWebBrowser.web.ts:158:1) at sentryWrapped (helpers.js:74:1)

My Issue was resolved by upgrading my expo version from 44 to 45 by applying expo upgrade @45.0.0

github-actions[bot] commented 1 year ago

This issue is stale because it has been open for 60 days with no activity. If there is no activity in the next 7 days, the issue will be closed.

github-actions[bot] commented 1 year ago

This issue was closed because it has been inactive for 7 days since being marked as stale. Please open a new issue if you believe you are encountering a related problem.