You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native调用react-native-app-auth的authorize函数报错求助

调用react-native-app-auth的authorize函数时触发TypeError错误

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 17:15:02