|
|
|
@ -17,25 +17,32 @@ import type { NativeStackNavigationProp } from "@react-navigation/native-stack";
|
|
|
|
|
import fontSize from "../../utils/fontsizeUtils"; |
|
|
|
|
import EmailLoginModal from "./EmailLoginModal"; |
|
|
|
|
import PhoneLoginModal from "./PhoneLoginModal"; |
|
|
|
|
import { loginApi } from "../../services/api/login"; |
|
|
|
|
import { userApi } from "../../services"; |
|
|
|
|
import useUserStore from "../../store/user"; |
|
|
|
|
|
|
|
|
|
// 使用标准的ES6模块导入
|
|
|
|
|
import { GoogleSignin, GoogleSigninButton, statusCodes } from '@react-native-google-signin/google-signin'; |
|
|
|
|
// import {
|
|
|
|
|
// GoogleSignin,
|
|
|
|
|
// statusCodes,
|
|
|
|
|
// } from "@react-native-google-signin/google-signin";
|
|
|
|
|
|
|
|
|
|
const isDevelopment = __DEV__; // 开发模式检测
|
|
|
|
|
|
|
|
|
|
// 移出条件块,始终尝试配置 Google 登录
|
|
|
|
|
try { |
|
|
|
|
// 配置 Google 登录
|
|
|
|
|
GoogleSignin.configure({ |
|
|
|
|
iosClientId: "YOUR_IOS_CLIENT_ID_HERE.apps.googleusercontent.com", // iOS CLIENT_ID
|
|
|
|
|
webClientId: "449517618313-av37nffa7rqkefu0ajh5auou3pb0mt51.apps.googleusercontent.com", // <-- 更新为此 Web Client ID
|
|
|
|
|
scopes: ['profile', 'email'], |
|
|
|
|
offlineAccess: false, // <-- 确保为 false 或移除
|
|
|
|
|
forceCodeForRefreshToken: false, // <-- 确保为 false 或移除
|
|
|
|
|
}); |
|
|
|
|
} catch (error) { |
|
|
|
|
console.log('Google Sign-in模块配置错误:', error); // 稍微修改了日志信息
|
|
|
|
|
} |
|
|
|
|
// try {
|
|
|
|
|
// // 配置 Google 登录
|
|
|
|
|
// GoogleSignin.configure({
|
|
|
|
|
// iosClientId: "YOUR_IOS_CLIENT_ID_HERE.apps.googleusercontent.com", // iOS CLIENT_ID
|
|
|
|
|
// webClientId:
|
|
|
|
|
// "449517618313-av37nffa7rqkefu0ajh5auou3pb0mt51.apps.googleusercontent.com", // <-- 更新为此 Web Client ID
|
|
|
|
|
// scopes: ["profile", "email"],
|
|
|
|
|
// offlineAccess: false, // <-- 确保为 false 或移除
|
|
|
|
|
// forceCodeForRefreshToken: false, // <-- 确保为 false 或移除
|
|
|
|
|
// });
|
|
|
|
|
// } catch (error) {
|
|
|
|
|
// console.log("Google Sign-in模块配置错误:", error); // 稍微修改了日志信息
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
type RootStackParamList = { |
|
|
|
|
Login: undefined; |
|
|
|
@ -51,6 +58,7 @@ type LoginScreenProps = {
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
export const LoginScreen = ({ onClose, isModal }: LoginScreenProps) => { |
|
|
|
|
const { setUser } = useUserStore(); |
|
|
|
|
const { t } = useTranslation(); |
|
|
|
|
const navigation = |
|
|
|
|
useNavigation<NativeStackNavigationProp<RootStackParamList>>(); |
|
|
|
@ -97,63 +105,52 @@ export const LoginScreen = ({ onClose, isModal }: LoginScreenProps) => {
|
|
|
|
|
|
|
|
|
|
// 处理谷歌登录
|
|
|
|
|
const handleGoogleLogin = async () => { |
|
|
|
|
try { |
|
|
|
|
// 开发模式下的模拟登录
|
|
|
|
|
// 注释掉开发模式下的模拟登录,以便进行真实登录测试
|
|
|
|
|
/* |
|
|
|
|
if (isDevelopment) { |
|
|
|
|
console.log('开发模式:模拟Google登录成功'); |
|
|
|
|
const mockUserInfo = { |
|
|
|
|
user: { |
|
|
|
|
id: 'dev_user_123', |
|
|
|
|
name: 'Test User', |
|
|
|
|
email: 'test@example.com', |
|
|
|
|
photo: null, |
|
|
|
|
}, |
|
|
|
|
}; |
|
|
|
|
console.log('模拟用户信息:', mockUserInfo); |
|
|
|
|
|
|
|
|
|
// 这里可以处理登录成功后的逻辑
|
|
|
|
|
// 比如导航到主页面或保存用户信息
|
|
|
|
|
// navigation.navigate("MainTabs", { screen: "Home" });
|
|
|
|
|
|
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
// 生产模式下的真实Google登录 (现在开发模式也会执行)
|
|
|
|
|
if (!GoogleSignin || typeof GoogleSignin.signIn !== 'function') { |
|
|
|
|
console.log('Google Sign-in模块未正确初始化或配置失败'); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
await GoogleSignin.hasPlayServices(); |
|
|
|
|
const userInfo = await GoogleSignin.signIn(); |
|
|
|
|
console.log('Google 登录成功:', userInfo); |
|
|
|
|
|
|
|
|
|
// 这里可以处理登录成功后的逻辑
|
|
|
|
|
// 比如导航到主页面或保存用户信息
|
|
|
|
|
// navigation.navigate("MainTabs", { screen: "Home" });
|
|
|
|
|
|
|
|
|
|
} catch (error: any) { |
|
|
|
|
console.log('Google 登录错误:', error); |
|
|
|
|
|
|
|
|
|
// 开发模式下的错误处理
|
|
|
|
|
if (isDevelopment) { |
|
|
|
|
console.log('开发模式:忽略Google登录错误,但已尝试真实登录'); // 修改日志,表明已尝试真实登录
|
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (statusCodes && error.code === statusCodes.SIGN_IN_CANCELLED) { |
|
|
|
|
console.log('用户取消登录'); |
|
|
|
|
} else if (statusCodes && error.code === statusCodes.IN_PROGRESS) { |
|
|
|
|
console.log('登录正在进行中'); |
|
|
|
|
} else if (statusCodes && error.code === statusCodes.PLAY_SERVICES_NOT_AVAILABLE) { |
|
|
|
|
console.log('Play Services 不可用'); |
|
|
|
|
} else { |
|
|
|
|
console.log('其他错误:', error.message); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// try {
|
|
|
|
|
|
|
|
|
|
// if (!GoogleSignin || typeof GoogleSignin.signIn !== "function") {
|
|
|
|
|
// console.log("Google Sign-in模块未正确初始化或配置失败");
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// await GoogleSignin.hasPlayServices();
|
|
|
|
|
// const userInfo = await GoogleSignin.signIn();
|
|
|
|
|
// console.log("Google 登录成功:", userInfo);
|
|
|
|
|
// try {
|
|
|
|
|
// const res = await loginApi.googleLogin(userInfo);
|
|
|
|
|
// const user = await userApi.getProfile();
|
|
|
|
|
// setUser(user);
|
|
|
|
|
// navigation.navigate("MainTabs", { screen: "Home" });
|
|
|
|
|
// } catch (err) {
|
|
|
|
|
// console.log("Google 登录失败:", err);
|
|
|
|
|
// navigation.navigate("Login");
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// // 这里可以处理登录成功后的逻辑
|
|
|
|
|
// // 比如导航到主页面或保存用户信息
|
|
|
|
|
// // navigation.navigate("MainTabs", { screen: "Home" });
|
|
|
|
|
// } catch (error: any) {
|
|
|
|
|
// console.log("Google 登录错误:", error);
|
|
|
|
|
|
|
|
|
|
// // 开发模式下的错误处理
|
|
|
|
|
// if (isDevelopment) {
|
|
|
|
|
// console.log("开发模式:忽略Google登录错误,但已尝试真实登录"); // 修改日志,表明已尝试真实登录
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// if (statusCodes && error.code === statusCodes.SIGN_IN_CANCELLED) {
|
|
|
|
|
// console.log("用户取消登录");
|
|
|
|
|
// } else if (statusCodes && error.code === statusCodes.IN_PROGRESS) {
|
|
|
|
|
// console.log("登录正在进行中");
|
|
|
|
|
// } else if (
|
|
|
|
|
// statusCodes &&
|
|
|
|
|
// error.code === statusCodes.PLAY_SERVICES_NOT_AVAILABLE
|
|
|
|
|
// ) {
|
|
|
|
|
// console.log("Play Services 不可用");
|
|
|
|
|
// } else {
|
|
|
|
|
// console.log("其他错误:", error.message);
|
|
|
|
|
// navigation.navigate("Login");
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
// 处理Facebook登录
|
|
|
|
@ -263,7 +260,9 @@ export const LoginScreen = ({ onClose, isModal }: LoginScreenProps) => {
|
|
|
|
|
/> |
|
|
|
|
</View> |
|
|
|
|
<Text style={styles.loginButtonText}> |
|
|
|
|
{isDevelopment ? '🧪 ' + t("continueWithGoogle") + ' (测试模式)' : t("continueWithGoogle")} |
|
|
|
|
{isDevelopment |
|
|
|
|
? "🧪 " + t("continueWithGoogle") + " (测试模式)" |
|
|
|
|
: t("continueWithGoogle")} |
|
|
|
|
</Text> |
|
|
|
|
</TouchableOpacity> |
|
|
|
|
|
|
|
|
|