【问题标题】:Expo AuthSession immediately resolves as "dismiss"edExpo AuthSession 立即解析为“dismiss”ed
【发布时间】:2020-04-22 15:25:14
【问题描述】:

我正在使用 Expo 的 AuthSession 模块登录 Auth0:

    let result = await AuthSession.startAsync({
      authUrl: `${auth0Domain}/authorize?` + qs.stringify({
        client_id: auth0ClientId,
        response_type: 'code',
        scope: 'openid profile email offline_access',
        redirect_uri: redirectUrl,
        code_challenge_method: 'S256',
        code_verifier: codeVerifier,
        state: oAuthState,
        audience: auth0Audience
      })
    })

    if (result.type === 'success') {
      ...
    } else if (
      result.type === 'dismiss' ||
      (result.type === 'error' && result.errorCode === 'login-declined')
    ) {
      // FIXME: alert never pops without delay here, despite the if correctly evaluating true
      // Any way to check if the window has closed, if that's the issue?
      await new Promise((resolve) => setTimeout(resolve, 5000))

      let retry = await alertAsync(
        'Authentication dismissed',
        'Cancel signing in?',
        'Try again',
        'Exit'
      )
      return retry ? this.loginWithAuth0() : false
    }
    logger.error('Login failed', result)
    throw new Error('Error signing in')
  }

在开发环境中我从来没有遇到过问题,但在已发布的应用程序中,promise 通常会立即通过{ type: dismiss } 解决,浏览器关闭之前。甚至在 AuthSession 窗口打开之前,我瞥见了一个警报 (我会尝试弹出该会话以防会话实际被解除)

如果我在弹出错误之前添加 5 秒延迟,它会在启动 AuthSession 后显示 5 秒,而不是结束。

在 Android 上测试。

我研究过迁移到 WebBrowser,但它似乎是相同的实现。

是否有一种一致的方式来实际完成await Auth 过程,还是我应该放弃这一切并编写自己的登录屏幕?

提前感谢任何输入/指导!

【问题讨论】:

  • 我只能确认我们遇到了同样的问题。您是否尝试在 GitHub 上打开 Expo 问题?
  • 还没有,我正在尝试了解有关该问题的更多信息,以便我可以制作一个可以重现它的小型演示。今天我确认使用哪个登录提供程序无关紧要,但没有任何线索说明导致它的原因。
  • github.com/expo/expo/blob/… 感觉这可能是问题所在,但我稍后将不得不使用它,除非有人以前处理过这个问题。

标签: react-native react-native-android expo auth0


【解决方案1】:

我已经把问题的详细解释和可能的解决方案https://github.com/expo/expo/issues/6679#issuecomment-570963717

作为一种临时解决方法,您可以在应用中的某处调用 AppState.currentState,也许只是为了在用户单击和启用 AuthSession 之前添加正确的侦听器而记录它(在链接的 GitHub 问题中阅读更多信息)。

请看一下并发表评论:)

【讨论】:

  • 我可以确认在工作之前阅读AppState.currentState,谢谢!如果我在使用 AuthSession 之前调用它似乎不起作用 - 看不出原因,但如果我在屏幕甚至 App.js 中调用它,则解决方法有效。
  • 是的,这可能是因为它需要足够的时间从网桥中获取信息,并且它被安排在 UI 线程回调中,因此可能需要一个周期或更长时间才能触发。我写的原始代码有一个更好的补丁似乎可以工作,我们只需要在 Expo 上发布它,敬请期待
猜你喜欢
  • 2019-12-28
  • 1970-01-01
  • 2023-02-19
  • 2021-08-08
  • 2022-12-11
  • 1970-01-01
  • 2021-10-24
  • 2011-05-30
  • 1970-01-01
相关资源
最近更新 更多