forked from 77media/video-flow
紧急回滚
This commit is contained in:
parent
ca4408f5df
commit
735d90bbd7
@ -13,11 +13,11 @@ export async function POST(request: NextRequest) {
|
|||||||
// 验证必需参数
|
// 验证必需参数
|
||||||
if (!code || !state) {
|
if (!code || !state) {
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{
|
{
|
||||||
success: false,
|
success: false,
|
||||||
message: 'Missing required parameters: code and state'
|
message: 'Missing required parameters: code and state'
|
||||||
},
|
},
|
||||||
{ status: 400 }
|
{ status: 400 }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,11 +72,11 @@ export async function POST(request: NextRequest) {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn('无法解析state参数:', state);
|
console.warn('无法解析state参数:', state);
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{
|
{
|
||||||
success: false,
|
success: false,
|
||||||
message: 'Invalid state parameter'
|
message: 'Invalid state parameter'
|
||||||
},
|
},
|
||||||
{ status: 400 }
|
{ status: 400 }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,11 +93,11 @@ export async function POST(request: NextRequest) {
|
|||||||
if (!googleClientSecret) {
|
if (!googleClientSecret) {
|
||||||
console.error('Google Client Secret未配置');
|
console.error('Google Client Secret未配置');
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{
|
{
|
||||||
success: false,
|
success: false,
|
||||||
message: 'Google Client Secret not configured'
|
message: 'Google Client Secret not configured'
|
||||||
},
|
},
|
||||||
{ status: 500 }
|
{ status: 500 }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,11 +129,11 @@ export async function POST(request: NextRequest) {
|
|||||||
// 如果是超时错误,提供更友好的错误信息
|
// 如果是超时错误,提供更友好的错误信息
|
||||||
if (fetchError.name === 'TimeoutError' || fetchError.code === 'UND_ERR_CONNECT_TIMEOUT') {
|
if (fetchError.name === 'TimeoutError' || fetchError.code === 'UND_ERR_CONNECT_TIMEOUT') {
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{
|
{
|
||||||
success: false,
|
success: false,
|
||||||
message: 'Google authentication service is temporarily unavailable. Please check your network connection and try again.'
|
message: 'Google authentication service is temporarily unavailable. Please check your network connection and try again.'
|
||||||
},
|
},
|
||||||
{ status: 503 }
|
{ status: 503 }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,11 +146,11 @@ export async function POST(request: NextRequest) {
|
|||||||
const errorText = await tokenResponse.text();
|
const errorText = await tokenResponse.text();
|
||||||
console.error('Google token exchange failed:', errorText);
|
console.error('Google token exchange failed:', errorText);
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{
|
{
|
||||||
success: false,
|
success: false,
|
||||||
message: 'Failed to exchange authorization code for tokens'
|
message: 'Failed to exchange authorization code for tokens'
|
||||||
},
|
},
|
||||||
{ status: 400 }
|
{ status: 400 }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,85 +161,57 @@ export async function POST(request: NextRequest) {
|
|||||||
if (!id_token) {
|
if (!id_token) {
|
||||||
console.error('No id_token received from Google');
|
console.error('No id_token received from Google');
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{
|
{
|
||||||
success: false,
|
success: false,
|
||||||
message: 'No id_token received from Google'
|
message: 'No id_token received from Google'
|
||||||
},
|
},
|
||||||
{ status: 400 }
|
{ status: 400 }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 第二步:使用id_token调用smartvideo-server的register_with_invite接口
|
// 第二步:使用id_token调用Java后端
|
||||||
const smartvideoBaseUrl = process.env.NEXT_PUBLIC_SMARTVIDEO_URL;
|
const javaBaseUrl = process.env.NEXT_PUBLIC_JAVA_URL || 'https://auth.test.movieflow.ai';
|
||||||
console.log('开始调用smartvideo-server后端:', smartvideoBaseUrl);
|
console.log('开始调用Java后端:', javaBaseUrl);
|
||||||
|
|
||||||
// 从Google ID Token中解析用户信息(简单解析,仅用于获取email等基本信息)
|
const backendResponse = await fetch(`${javaBaseUrl}/api/auth/google/login`, {
|
||||||
let googleUserInfo: any = {};
|
|
||||||
try {
|
|
||||||
// 解码Google ID Token的payload部分(注意:这里只是为了获取基本信息,真正的验证在后端进行)
|
|
||||||
const tokenParts = id_token.split('.');
|
|
||||||
if (tokenParts.length === 3) {
|
|
||||||
const payload = JSON.parse(atob(tokenParts[1]));
|
|
||||||
googleUserInfo = {
|
|
||||||
email: payload.email,
|
|
||||||
name: payload.name,
|
|
||||||
given_name: payload.given_name,
|
|
||||||
family_name: payload.family_name
|
|
||||||
};
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.warn('解析Google ID Token失败,使用空的用户信息:', e);
|
|
||||||
}
|
|
||||||
|
|
||||||
const backendResponse = await fetch(`${smartvideoBaseUrl}/api/user_fission/register_with_invite`, {
|
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Accept': 'application/json',
|
'Accept': 'application/json',
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
email: googleUserInfo.email, // 从Google Token中获取的邮箱
|
idToken: id_token, // 使用从Google获取的id_token
|
||||||
name: googleUserInfo.name, // 从Google Token中获取的姓名
|
action: 'auto', // 自动判断登录或注册
|
||||||
google_id_token: id_token, // Google ID Token
|
inviteCode: inviteCode || stateData.inviteCode || undefined
|
||||||
auth_type: 'GOOGLE', // 标识为Google OAuth注册
|
|
||||||
invite_code: inviteCode || stateData.inviteCode || undefined
|
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log('smartvideo-server后端响应状态:', backendResponse.status);
|
console.log('Java后端响应状态:', backendResponse.status);
|
||||||
const backendResult = await backendResponse.json();
|
const backendResult = await backendResponse.json();
|
||||||
|
|
||||||
if (!backendResponse.ok || !backendResult.successful) {
|
if (!backendResponse.ok || !backendResult.success) {
|
||||||
console.error('smartvideo-server处理Google OAuth失败:', backendResult);
|
console.error('Java后端处理Google OAuth失败:', backendResult);
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{
|
{
|
||||||
success: false,
|
success: false,
|
||||||
message: backendResult.message || 'Google authentication failed'
|
message: backendResult.message || 'Google authentication failed'
|
||||||
},
|
},
|
||||||
{ status: backendResponse.status || 500 }
|
{ status: backendResponse.status || 500 }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('Google OAuth认证成功:', {
|
console.log('Google OAuth认证成功:', {
|
||||||
userId: backendResult.data?.user_id,
|
userId: backendResult.data?.user?.userId,
|
||||||
email: backendResult.data?.email
|
email: backendResult.data?.user?.email
|
||||||
});
|
});
|
||||||
|
|
||||||
// 返回成功结果,格式与原有保持一致以确保前端兼容性
|
// 返回成功结果
|
||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
success: true,
|
success: true,
|
||||||
data: {
|
data: {
|
||||||
// 包含token以支持前端认证
|
|
||||||
token: backendResult.data.token,
|
token: backendResult.data.token,
|
||||||
user: {
|
user: backendResult.data.userInfo || backendResult.data.user,
|
||||||
userId: backendResult.data.user_id,
|
message: 'Google authentication successful'
|
||||||
userName: backendResult.data.name,
|
|
||||||
name: backendResult.data.name,
|
|
||||||
email: backendResult.data.email,
|
|
||||||
authType: backendResult.data.auth_type,
|
|
||||||
isNewUser: true // 通过register_with_invite接口的都是新用户或首次OAuth绑定
|
|
||||||
},
|
|
||||||
message: 'Google OAuth registration successful with credit rewards'
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -250,20 +222,20 @@ export async function POST(request: NextRequest) {
|
|||||||
if (error.code === 'ECONNREFUSED' || error.message?.includes('fetch failed')) {
|
if (error.code === 'ECONNREFUSED' || error.message?.includes('fetch failed')) {
|
||||||
console.error('网络连接失败,可能是Java后端服务不可用');
|
console.error('网络连接失败,可能是Java后端服务不可用');
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{
|
{
|
||||||
success: false,
|
success: false,
|
||||||
message: 'Backend service unavailable. Please try again later.'
|
message: 'Backend service unavailable. Please try again later.'
|
||||||
},
|
},
|
||||||
{ status: 503 }
|
{ status: 503 }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{
|
{
|
||||||
success: false,
|
success: false,
|
||||||
message: error.message || 'Internal server error during Google OAuth callback'
|
message: error.message || 'Internal server error during Google OAuth callback'
|
||||||
},
|
},
|
||||||
{ status: 500 }
|
{ status: 500 }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -299,11 +271,11 @@ export async function GET(request: NextRequest) {
|
|||||||
|
|
||||||
if (!code || !state) {
|
if (!code || !state) {
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{
|
{
|
||||||
success: false,
|
success: false,
|
||||||
message: 'Missing required parameters: code and state'
|
message: 'Missing required parameters: code and state'
|
||||||
},
|
},
|
||||||
{ status: 400 }
|
{ status: 400 }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user