【问题标题】:Expo web AuthSession error: TypeError: Cannot read property 'startsWith' of undefinedExpo web AuthSession错误:TypeError:无法读取未定义的属性“startsWith”
【发布时间】:2020-06-05 08:59:16
【问题描述】:

我在我的 React Native Expo 应用程序中使用 AuthSession 以使用 auth0 (following this example) 登录。

async mobileLogin(){
    const redirectUrl = AuthSession.getRedirectUrl();
    ...
}

登录在 Android 和 iOS 上都可以正常工作,当我在 Web 上使用它时,AuthSession 模块会中断:

bundle.js:19465 Uncaught (in promise) TypeError: Cannot read property 'startsWith' of undefined

深入 AuthSession Expo 模块,代码在第 150 行中断 (link to source code on github)。 在expo documentation AuthSession 中应该支持Web,但是对于它的依赖项之一expo-app-auth

计划添加网络支持

我的猜测是,由于 Web 不支持 expo-app-auth,因此从 Web 使用 AuthSession 会中断(而在移动设备上工作)。这是真的?我是否应该在我的 React Native 应用程序中从网络上寻找另一种使用 auth0 登录的方法?有什么建议吗?

【问题讨论】:

    标签: react-native expo auth0


    【解决方案1】:

    很遗憾地通知您,AuthSession 实际上不适用于 Web。 Check the doc page again 在“平台兼容性”下。

    目前,您最好的选择是AppAuth。是currently being ported to the web,建议大家多多关注。

    【讨论】:

    • 好的,谢谢,难道没有一些hacky解决方法吗?喜欢在某些if (Platform.OS === "web") 条件之外使用react auth0 库“react-auth0-spa”?我是 RN/React n00b,所以我不太熟悉
    • 没试过,但我不认为你能做到这一点......但。所以你现在必须依赖Platform
    • 依赖Platform是什么意思?
    • 我的意思是,你现在必须通过检查平台来禁用这个网络功能。
    • 是的,我的大部分功能都是这样做的,问题是这是“登录”功能,所以如果我禁用此功能意味着我不能支持 RN Web 应用程序并放弃 Expo for React : C
    猜你喜欢
    • 2022-12-04
    • 2020-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-24
    • 2023-02-26
    • 2017-05-05
    相关资源
    最近更新 更多