forked from 77media/video-flow
updates google login
This commit is contained in:
parent
946a6c1d90
commit
f71c46883e
@ -281,5 +281,17 @@ export async function GET(request: NextRequest) {
|
||||
|
||||
// 重定向到页面路由,让页面处理OAuth回调
|
||||
const callbackUrl = `/users/oauth/callback?code=${encodeURIComponent(code)}&state=${encodeURIComponent(state)}`;
|
||||
return NextResponse.redirect(new URL(callbackUrl, request.url));
|
||||
|
||||
// 修复:确保使用正确的域名进行重定向
|
||||
const host = request.headers.get('host') || 'www.movieflow.net';
|
||||
const protocol = request.headers.get('x-forwarded-proto') || 'https';
|
||||
const fullCallbackUrl = `${protocol}://${host}${callbackUrl}`;
|
||||
|
||||
console.log('🔍 前端API重定向调试:');
|
||||
console.log(' - request.url:', request.url);
|
||||
console.log(' - host header:', host);
|
||||
console.log(' - protocol:', protocol);
|
||||
console.log(' - 重定向到:', fullCallbackUrl);
|
||||
|
||||
return NextResponse.redirect(fullCallbackUrl);
|
||||
}
|
||||
|
||||
11
lib/auth.ts
11
lib/auth.ts
@ -237,13 +237,7 @@ export const signInWithGoogle = async (inviteCode?: string): Promise<void> => {
|
||||
// 从环境变量获取配置(临时硬编码确保正确)
|
||||
const clientId = process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID || '847079918888-o1nne8d3ij80dn20qurivo987pv07225.apps.googleusercontent.com';
|
||||
const redirectUri = process.env.NEXT_PUBLIC_GOOGLE_REDIRECT_URI || 'https://www.movieflow.net/api/auth/google/callback';
|
||||
|
||||
// 根据当前域名选择正确的redirect_uri
|
||||
const isLocalhost = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1';
|
||||
const actualRedirectUri = isLocalhost
|
||||
? 'http://localhost:3000/api/auth/google/callback' // 本地开发
|
||||
: redirectUri; // 使用环境变量配置
|
||||
|
||||
|
||||
// 生成随机nonce用于安全验证
|
||||
const nonce = Array.from(crypto.getRandomValues(new Uint8Array(32)))
|
||||
.map(b => b.toString(16).padStart(2, '0')).join('');
|
||||
@ -259,7 +253,6 @@ export const signInWithGoogle = async (inviteCode?: string): Promise<void> => {
|
||||
console.log('使用的配置:', {
|
||||
clientId,
|
||||
redirectUri,
|
||||
actualRedirectUri,
|
||||
envClientId: process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID,
|
||||
envRedirectUri: process.env.NEXT_PUBLIC_GOOGLE_REDIRECT_URI
|
||||
});
|
||||
@ -279,7 +272,7 @@ export const signInWithGoogle = async (inviteCode?: string): Promise<void> => {
|
||||
access_type: 'online',
|
||||
client_id: clientId,
|
||||
nonce: nonce,
|
||||
redirect_uri: actualRedirectUri, // 使用强制修复的URI
|
||||
redirect_uri: redirectUri,
|
||||
response_type: 'code', // 使用授权码模式
|
||||
scope: 'email openid profile',
|
||||
state: JSON.stringify(stateData),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user