Код: Выделить всё
import { GoogleSignin, statusCodes } from '@react-native-google-signin/google-signin';
import { GoogleAuthProvider, signInWithCredential, getAuth } from 'firebase/auth';
import AsyncStorage from '@react-native-async-storage/async-storage';
import { Alert } from 'react-native';
export const configureGoogleSignIn = () => {
GoogleSignin.configure({
webClientId: '--webClientId--',
});
};
export const signInWithGoogle = async (auth, navigation) => {
try {
await GoogleSignin.signOut();
const playServices = await GoogleSignin.hasPlayServices({
showPlayServicesUpdateDialog: true,
});
console.log('3. Play Services check:', playServices);
const userInfo = await GoogleSignin.signIn();
const { idToken } = userInfo;
const credential = GoogleAuthProvider.credential(idToken);
const userCredential = await signInWithCredential(auth, credential);
const token = await userCredential.user.getIdToken();
await AsyncStorage.setItem('@accessToken', token);
navigation.navigate('Main');
} catch (error) {
if (error.code === statusCodes.SIGN_IN_CANCELLED) {
console.log('SIGN_IN_CANCELLED');
} else if (error.code === statusCodes.IN_PROGRESS) {
console.log('SIGN_IN_PROGRESS');
} else if (error.code === statusCodes.PLAY_SERVICES_NOT_AVAILABLE) {
console.log('PLAY_SERVICES_NOT_AVAILABLE');
} else {
console.error("Google Sign-In Error:", error);
Alert.alert("Sign-In Error :", error.message);
}
throw error;
}
};
Код: Выделить всё
const userInfo = await GoogleSignin.signIn({});**Среда
**
Android Studio
Уровень Android API 35
"@react-native-google-signin/google-signin": "^13.1.0"
"react-native": "^ 0.74.5"
'com.google.android.gms:play-services-auth:20.7.0'
'com.google.gms:google-services:4.4.1'
Я также очистил
кэш npm,
очистил кеш пряжи,
и попробовал ./gradlew.
Кроме того, я также попробовал @react-native-google-signin/google-signin вер. 9.0.0 и 12.1.0.
Подробнее здесь: https://stackoverflow.com/questions/792 ... ed-3-error
Мобильная версия