65 lines
2.2 KiB
JavaScript
65 lines
2.2 KiB
JavaScript
#!/usr/bin/env node
|
||
|
||
// OAuth 调试脚本
|
||
console.log("=== OAuth 配置调试 ===");
|
||
|
||
// 模拟服务器环境变量
|
||
const envVars = {
|
||
NEXTAUTH_URL: "https://recorder.zyj.best",
|
||
GOOGLE_CLIENT_ID:
|
||
"1060072115182-l5u59vrbs2lmcpg7pnn72bc8h37eolff.apps.googleusercontent.com",
|
||
GOOGLE_CLIENT_SECRET: "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",
|
||
};
|
||
|
||
console.log("\n=== 环境变量检查 ===");
|
||
Object.entries(envVars).forEach(([key, value]) => {
|
||
console.log(`✅ ${key}: ${value.substring(0, 30)}...`);
|
||
});
|
||
|
||
console.log("\n=== 重定向 URI 分析 ===");
|
||
const nextAuthUrl = envVars.NEXTAUTH_URL;
|
||
const expectedRedirectUri = `${nextAuthUrl}/api/auth/callback/google`;
|
||
|
||
console.log(`NEXTAUTH_URL: ${nextAuthUrl}`);
|
||
console.log(`预期的重定向 URI: ${expectedRedirectUri}`);
|
||
|
||
// 验证 URL 格式
|
||
try {
|
||
new URL(nextAuthUrl);
|
||
console.log("✅ NEXTAUTH_URL 格式有效");
|
||
} catch (error) {
|
||
console.log(`❌ NEXTAUTH_URL 格式无效: ${error.message}`);
|
||
}
|
||
|
||
try {
|
||
new URL(expectedRedirectUri);
|
||
console.log("✅ 重定向 URI 格式有效");
|
||
} catch (error) {
|
||
console.log(`❌ 重定向 URI 格式无效: ${error.message}`);
|
||
}
|
||
|
||
console.log("\n=== Google Cloud Console 配置检查 ===");
|
||
console.log("请在 Google Cloud Console 中验证以下配置:");
|
||
console.log("1. 项目 ID: 检查你的 Google Cloud 项目");
|
||
console.log(
|
||
"2. OAuth 2.0 客户端 ID: 1060072115182-l5u59vrbs2lmcpg7pnn72bc8h37eolff.apps.googleusercontent.com"
|
||
);
|
||
console.log("3. 授权重定向 URI 应包含:");
|
||
console.log(` - ${expectedRedirectUri}`);
|
||
|
||
console.log("\n=== 常见问题排查 ===");
|
||
console.log("1. 确保 Google Cloud Console 中的重定向 URI 完全匹配");
|
||
console.log("2. 检查是否有额外的空格或引号");
|
||
console.log("3. 确保协议是 https(不是 http)");
|
||
console.log("4. 检查域名是否正确(recorder.zyj.best)");
|
||
|
||
console.log("\n=== 测试步骤 ===");
|
||
console.log("1. 访问: https://recorder.zyj.best/login");
|
||
console.log("2. 点击 '使用 Google 登录'");
|
||
console.log("3. 观察浏览器地址栏的重定向 URL");
|
||
console.log("4. 检查是否与 Google Cloud Console 中的配置匹配");
|
||
|
||
console.log("\n=== 调试命令 ===");
|
||
console.log("在服务器上运行以下命令查看应用日志:");
|
||
console.log("docker logs recorder-app --tail 50");
|