错误:RNGoogleSignin:离线使用需要服务器Web ClientID,js引擎:hermes

问题描述 投票:0回答:1

我已经在我的 Firebase 中实现了 Google 登录以及 facebook 登录,但在启动应用程序时出现错误:RNGoogleSignin:离线使用需要服务器 Web ClientID、js 引擎:hermes。它在我的 @react-native-google-signin 节点模块中给了我错误。

GoogleSignin.ts 的以下部分存在错误

 configure(options: ConfigureParams = {}): void {
    if (options.offlineAccess && !options.webClientId) {
      throw new Error('RNGoogleSignin: offline use requires server web ClientID');
    }

GoogleSignin.ts

import { NativeModules, Platform } from 'react-native';
import type {
  AddScopesParams,
  SignInParams,
  ConfigureParams,
  HasPlayServicesParams,
  User,
} from './types';

const { RNGoogleSignin } = NativeModules;

const IS_IOS = Platform.OS === 'ios';

class GoogleSignin {
  configPromise?: Promise<void>;

  constructor() {
    if (__DEV__ && !RNGoogleSignin) {
      console.error(
        `RN GoogleSignin native module is not correctly linked. Please read the readme, setup and troubleshooting instructions carefully or try manual linking.`,
      );
    }
  }

  async signIn(options: SignInParams = {}): Promise<User> {
    await this.configPromise;
    return await RNGoogleSignin.signIn(options);
  }

  async hasPlayServices(
    options: HasPlayServicesParams = { showPlayServicesUpdateDialog: true },
  ): Promise<boolean> {
    if (IS_IOS) {
      return true;
    } else {
      if (options && options.showPlayServicesUpdateDialog === undefined) {
        throw new Error(
          'RNGoogleSignin: Missing property `showPlayServicesUpdateDialog` in options object for `hasPlayServices`',
        );
      }
      return RNGoogleSignin.playServicesAvailable(options.showPlayServicesUpdateDialog);
    }
  }

  configure(options: ConfigureParams = {}): void {
    if (options.offlineAccess && !options.webClientId) {
      throw new Error('RNGoogleSignin: offline use requires server web ClientID');
    }

    this.configPromise = RNGoogleSignin.configure(options);
  }

  async addScopes(options: AddScopesParams): Promise<User | null> {
    const isSignedIn = await this.isSignedIn();
    if (!isSignedIn) {
      return null;
    }
    return IS_IOS ? RNGoogleSignin.addScopes(options) : RNGoogleSignin.getCurrentUser();
  }

  async signInSilently(): Promise<User> {
    await this.configPromise;
    return RNGoogleSignin.signInSilently();
  }

  async signOut(): Promise<null> {
    return RNGoogleSignin.signOut();
  }

  async revokeAccess(): Promise<null> {
    return RNGoogleSignin.revokeAccess();
  }

  async isSignedIn(): Promise<boolean> {
    return RNGoogleSignin.isSignedIn();
  }

  async getCurrentUser(): Promise<User | null> {
    return RNGoogleSignin.getCurrentUser();
  }

  async clearCachedAccessToken(tokenString: string): Promise<null> {
    if (!tokenString || typeof tokenString !== 'string') {
      return Promise.reject('GoogleSignIn: clearCachedAccessToken() expects a string token.');
    }
    return IS_IOS ? null : await RNGoogleSignin.clearCachedAccessToken(tokenString);
  }

  async getTokens(): Promise<{ idToken: string; accessToken: string }> {
    if (IS_IOS) {
      const tokens = await RNGoogleSignin.getTokens();
      return tokens;
    } else {
      const userObject = await RNGoogleSignin.getTokens();
      return {
        idToken: userObject.idToken,
        accessToken: userObject.accessToken,
      };
    }
  }
}

export const GoogleSigninSingleton = new GoogleSignin();

export const statusCodes = {
  SIGN_IN_CANCELLED: RNGoogleSignin.SIGN_IN_CANCELLED as string,
  IN_PROGRESS: RNGoogleSignin.IN_PROGRESS as string,
  PLAY_SERVICES_NOT_AVAILABLE: RNGoogleSignin.PLAY_SERVICES_NOT_AVAILABLE as string,
  SIGN_IN_REQUIRED: RNGoogleSignin.SIGN_IN_REQUIRED as string,
} as const;

google-services.json

{
  "project_info": {
    "project_number": "969785011148",
    "project_id": "hutouch-e43b5",
    "storage_bucket": "hutouch-e43b5.appspot.com"
  },
  "client": [
    {
      "client_info": {
        "mobilesdk_app_id": "1:969785011148:android:eaa0a07577ed8c31ee4b69",
        "android_client_info": {
          "package_name": "hutouch.niiti.dev"
        }
      },
      "oauth_client": [
        {
          "client_id": "969785011148-261eg09nn69oi5dbsou3gsieh5ngpkl9.apps.googleusercontent.com",
          "client_type": 1,
          "android_info": {
            "package_name": "hutouch.niiti.dev",
            "certificate_hash": "0cd297b50c37da9c17a6b5ea6627e8dc42b398a1"
          }
        },
        {
          "client_id": "969785011148-hq119bljaie8f0g4albl1mqsqj98d3sl.apps.googleusercontent.com",
          "client_type": 3
        }
      ],
      "api_key": [
        {
          "current_key": "AIzaSyB8Tasf8KUnvFvYV-Wnk7dU8TSHklGKDtU"
        }
      ],
      "services": {
        "appinvite_service": {
          "other_platform_oauth_client": [
            {
              "client_id": "969785011148-3vkq5dsug6gt0cfa8pe01ar22iddencg.apps.googleusercontent.com",
              "client_type": 3
            }
          ]
        }
      }
    }
  ],
  "configuration_version": "1"
}
javascript reactjs firebase react-native google-signin
1个回答
0
投票

为您的项目配置 Web 客户端 ID:

  1. 转至 Google-Cloud 控制台:https://console.cloud.google.com
  2. 选择您的项目。
  3. 在页面底部的“快速访问”部分中,访问“API 和服务”。
  4. 在左侧导航菜单中,访问“凭据”。
  5. 在凭据窗格中,使用现有凭据的 clientID 或使用页面顶部的“创建凭据”来创建新凭据。

另请参阅 google 身份平台的文档:

https://cloud.google.com/identity-platform/docs/web/google

© www.soinside.com 2019 - 2024. All rights reserved.