Я столкнулся с проблемой входа в Google в моем проекте React Native. Недавно функция входа в Google перестала работать на устройствах Android. Раньше он работал правильно, но теперь, когда пользователи пытаются войти в систему с помощью Google, появляется всплывающее окно для выбора учетной записи Google, но после выбора учетной записи ничего не происходит. Стоит отметить, что вход в Google продолжает работать должным образом на устройствах iOS.
Ниже я предоставил соответствующий фрагмент кода из файла GoogleLogin.js вместе с подробностями проекта. Будем очень признательны за любую помощь в решении этой проблемы.
Репозиторий с кодом, воспроизводящим проблему.
Я столкнулся с проблемой при использовании Google Sign. На Android в моем проекте React Native. Ниже приведен фрагмент кода из моего файла GoogleLogin.js.
Код: Выделить всё
// GoogleLogin.js
import { StyleSheet, Text, View, Image, TouchableOpacity, ActivityIndicator, Platform } from "react-native";
import React from "react";
import { COLORS } from "../../theme";
import {
GoogleSignin,
statusCodes,
} from '@react-native-google-signin/google-signin';
import { setAccessToken } from "../../store/slices/generalSlice";
import { useDispatch } from "react-redux";
import { useNavigation } from "@react-navigation/native";
import axios from "axios";
import { API_URL } from "../../config/constants";
import { useLoginUserMutation, useSignUpUserMutation } from "../../store/api/api";
import { useToast } from "react-native-toast-notifications";
export default function GoogleLogin() {
const toast = useToast();
const [gSignIn, setGSignIn] = React.useState()
const dispatch = useDispatch()
const navigation = useNavigation()
const [signUpUser, { isLoading }] = useSignUpUserMutation()
const [loginUser, { isLoading: loginLoading }] = useLoginUserMutation();
const handleLogin = async (body) => {
try {
const res = await loginUser(body)
if (res?.error) {
toast.show("Identifiants de connexion invalides", {
type: "warning",
placement: "bottom",
duration: 4000,
offset: 30,
animationType: "slide-in",
});
}
if (res.data?.access_token) {
dispatch(setAccessToken(res.data?.access_token))
navigation.popToTop()
}
} catch (e) {
// Handle error
}
};
const handleSignUp = async (body, loginSeq) => {
try {
const res = await signUpUser(body)
if (res?.error) {
// Handle error
}
// Handle success cases
} catch (e) {
// Handle error
}
}
const checkSocialUser = async (props) => {
const response = await axios.get(`${API_URL}verifySocialUserId`, { params: props })
return response.data
}
const SignIn = async () => {
try {
GoogleSignin.configure({
webClientId: "xxx.apps.googleusercontent.com",
androidClientId: "xxx-xxx.apps.googleusercontent.com",
iosClientId: "xxx-xxx.apps.googleusercontent.com"
})
await GoogleSignin.hasPlayServices();
const userInfo = await GoogleSignin.signIn();
setGSignIn(userInfo);
if (userInfo.user) {
const isGoogleUser = await checkSocialUser({ google_user_id: userInfo.user.id })
if (isGoogleUser && !isGoogleUser.status) {
handleSignUp({ email: userInfo.user.email, first_name: userInfo.user.givenName, last_name: userInfo.user.familyName, password: userInfo.user.familyName+userInfo.user.id, google_user_id: userInfo.user.id, register_medium: 'google' }, ()=>handleLogin({ email: userInfo.user.email, password: userInfo.user.familyName+userInfo.user.id }))
} else if (isGoogleUser.status) {
handleLogin({ email: userInfo.user.email, password: userInfo.user.familyName+userInfo.user.id })
} else {
alert("Some error occurred");
}
}
} catch (error) {
// Handle error
}
};
return (
{(isLoading || loginLoading) ? : { SignIn() }}>
Connecter avec Google
}
);
}
const styles = StyleSheet.create({
...
},
});
Я ожидал, что вход в Google будет работать без проблем как на устройствах Android, так и на iOS.
Фактическое поведение
Вход в Google не работает на устройствах Android. Когда пользователи нажимают «Войти через Google», появляется всплывающее окно с выбором учетной записи Google, но после выбора учетной записи ничего не происходит.
Среда
версия реакции: 0.72.6
@react-native-google-signin/версия google-signin: 11.0.1
Экспо-версия: ~49.0.6
Пожалуйста, дайте мне знать, если вы нужна дополнительная информация. Спасибо!
Подробнее здесь: https://stackoverflow.com/questions/784 ... act-native
Мобильная версия