【发布时间】: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