React Native调用react-native-app-auth的authorize函数报错求助
Stack Overflow上的类似问题未能解决我的问题,特在此求助:
当我尝试调用react-native-app-auth库中的authorize函数时,出现错误:TypeError: Cannot read properties of undefined (reading 'authorize')。
最小复现代码
import React, { useState } from "react"; import { Text, View, Button, Linking } from "react-native"; import { authorize } from 'react-native-app-auth'; export default function App() { const config = { issuer: 'https://accounts.google.com', clientId: 'GOOGLE_OAUTH_APP_GUID.apps.googleusercontent.com', redirectUrl: 'com.googleusercontent.apps.GOOGLE_OAUTH_APP_GUID:/oauth2redirect/google', scopes: ['openid', 'profile', 'email'], }; const handleLogin = async () => { try { console.log(authorize); // 此行打印显示函数确实存在 const result = await authorize(config); // 错误触发于此行 console.log('Authorization Response', result); } catch (error) { console.error('Hey! Theres an authorization error', error); } }; return ( <View> <Button title={"google"} onPress={() => handleLogin()} key={"google"} /> </View> ); }
已执行操作与排查信息
- 已完成
npm install react-native-app-auth安装 - 使用
npm run web启动项目,错误来自handleLogin函数内的authorize调用 - 打印
authorize确认函数存在,输出内容片段:
f authorize(_ref4) { var issuer = _ref4.issuer, redirectUrl = _ref4.redirectUrl, clientId = _ref4.clientId, clientSecret = _ref4.clientSecret, scopes = _ref4.scopes, _ref4$useNonc…
- 尝试在config中添加
clientSecret字段,问题未解决
包版本
"react": "18.2.0", "react-native": "^0.72.6", "react-native-app-auth": "^7.1.0", "react-native-web": "~0.19.6",
如需其他信息,我会补充提供,谢谢!
内容的提问来源于stack exchange,提问作者proof-of-correctness
相关产品推荐
相关产品推荐

