我已经在我的 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"
}
为您的项目配置 Web 客户端 ID:
另请参阅 google 身份平台的文档: