update google

This commit is contained in:
Zixin Zhou 2025-09-22 11:59:23 +08:00
commit 946a6c1d90
2 changed files with 28 additions and 2 deletions

View File

@ -16,7 +16,13 @@ export default function OAuthCallback() {
useEffect(() => { useEffect(() => {
const handleOAuthCallback = async () => { const handleOAuthCallback = async () => {
try { try {
console.log('OAuth回调页面开始处理...'); console.log('🎯 Google OAuth 回调页面开始处理...');
console.log('📍 回调页面调试信息:');
console.log(' - 完整回调 URL:', window.location.href);
console.log(' - 回调域名:', window.location.hostname);
console.log(' - 回调协议:', window.location.protocol);
console.log(' - 回调路径:', window.location.pathname);
console.log(' - URL 查询参数:', window.location.search);
// 获取URL参数 // 获取URL参数
const params: OAuthCallbackParams = { const params: OAuthCallbackParams = {
@ -26,7 +32,7 @@ export default function OAuthCallback() {
error_description: searchParams.get("error_description") || undefined, error_description: searchParams.get("error_description") || undefined,
}; };
console.log('获取到的URL参数:', params); console.log('📦 获取到的URL参数:', params);
// 检查是否有错误 // 检查是否有错误
if (params.error) { if (params.error) {

View File

@ -263,6 +263,16 @@ export const signInWithGoogle = async (inviteCode?: string): Promise<void> => {
envClientId: process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID, envClientId: process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID,
envRedirectUri: process.env.NEXT_PUBLIC_GOOGLE_REDIRECT_URI envRedirectUri: process.env.NEXT_PUBLIC_GOOGLE_REDIRECT_URI
}); });
// 详细的调试日志
console.log('🔍 Google OAuth 调试信息:');
console.log(' - 当前域名:', window.location.hostname);
console.log(' - 当前协议:', window.location.protocol);
console.log(' - 当前端口:', window.location.port);
console.log(' - 完整 origin:', window.location.origin);
console.log(' - 环境变量 NEXT_PUBLIC_GOOGLE_REDIRECT_URI:', process.env.NEXT_PUBLIC_GOOGLE_REDIRECT_URI);
console.log(' - 最终使用的 redirect_uri:', redirectUri);
console.log(' - Google Client ID:', GOOGLE_CLIENT_ID);
// 构建Google OAuth2授权URL // 构建Google OAuth2授权URL
const authParams = new URLSearchParams({ const authParams = new URLSearchParams({
@ -281,6 +291,16 @@ export const signInWithGoogle = async (inviteCode?: string): Promise<void> => {
console.log('跳转到Google授权页面:', authUrl); console.log('跳转到Google授权页面:', authUrl);
console.log('🔍 调试信息 - 授权URL中的redirect_uri:', authParams.get('redirect_uri')); console.log('🔍 调试信息 - 授权URL中的redirect_uri:', authParams.get('redirect_uri'));
console.log('🔍 调试信息 - 当前页面域名:', window.location.origin); console.log('🔍 调试信息 - 当前页面域名:', window.location.origin);
console.log('📤 发送给 Google 的完整授权 URL:');
console.log(authUrl);
console.log('📋 URL 参数解析:');
authParams.forEach((value, key) => {
if (key === 'state') {
console.log(` - ${key}: ${JSON.stringify(JSON.parse(value), null, 2)}`);
} else {
console.log(` - ${key}: ${value}`);
}
});
// 保存state到sessionStorage用于验证 // 保存state到sessionStorage用于验证
sessionStorage.setItem('google_oauth_state', JSON.stringify({ sessionStorage.setItem('google_oauth_state', JSON.stringify({