Expo AuthSession 立即解析为 "dismiss"ed
Expo AuthSession immediately resolves as "dismiss"ed
我正在使用 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')
}
在开发环境中,我从来没有遇到过问题,但在已发布的应用程序中,承诺通常会在 { type: dismiss }
、 浏览器关闭之前立即解决。一旦我瞥见了一个警报 (我尝试弹出以防会话实际上被取消) 甚至在 AuthSession window 打开之前。
如果我在弹出错误之前添加 5 秒的延迟,它确实会在 AuthSession
开始后显示 5 秒,而不是结束。
正在 Android.
进行测试
我研究了向 WebBrowser 的迁移,但它似乎是相同的实现。
是否有一致的方法来实际 await
完成身份验证过程,或者我应该放弃这一切并编写自己的登录屏幕?
在此先感谢您的任何意见/指导!
我已经详细解释了问题和可能的解决方案https://github.com/expo/expo/issues/6679#issuecomment-570963717
作为临时解决方法,您可以在应用中的某处调用 AppState.currentState,也许记录它只是为了在用户点击之前添加正确的侦听器并启用 AuthSession(阅读链接中的更多信息 GitHub 问题)。
请观看并发表评论:)
我正在使用 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')
}
在开发环境中,我从来没有遇到过问题,但在已发布的应用程序中,承诺通常会在 { type: dismiss }
、 浏览器关闭之前立即解决。一旦我瞥见了一个警报 (我尝试弹出以防会话实际上被取消) 甚至在 AuthSession window 打开之前。
如果我在弹出错误之前添加 5 秒的延迟,它确实会在 AuthSession
开始后显示 5 秒,而不是结束。
正在 Android.
进行测试我研究了向 WebBrowser 的迁移,但它似乎是相同的实现。
是否有一致的方法来实际 await
完成身份验证过程,或者我应该放弃这一切并编写自己的登录屏幕?
在此先感谢您的任何意见/指导!
我已经详细解释了问题和可能的解决方案https://github.com/expo/expo/issues/6679#issuecomment-570963717
作为临时解决方法,您可以在应用中的某处调用 AppState.currentState,也许记录它只是为了在用户点击之前添加正确的侦听器并启用 AuthSession(阅读链接中的更多信息 GitHub 问题)。
请观看并发表评论:)