fix: Improve OAuth callback URL parsing and handling

This commit is contained in:
wood chen 2025-02-21 21:25:27 +08:00
parent b9ace034bf
commit 2c94af2b91

View File

@ -29,22 +29,22 @@ export function UserAuthForm({
console.log("Original callbackUrl:", callbackUrl);
// 如果是 OAuth 回调,则提取原始的 /oauth/authorize 部分
// 如果是 OAuth 回调,则保留完整的 OAuth 参数
if (callbackUrl?.includes("/oauth/authorize")) {
try {
// 先解码一次 URL
const decodedUrl = decodeURIComponent(callbackUrl);
console.log("Decoded URL:", decodedUrl);
// 提取 /oauth/authorize 部分
const match = decodedUrl.match(/\/oauth\/authorize[^&]*/);
if (match) {
body.return_url = `${window.location.origin}${match[0]}`;
// 解析 URL 并保留所有参数
const url = new URL(decodedUrl);
if (url.pathname === "/oauth/authorize") {
body.return_url = `${window.location.origin}${url.pathname}${url.search}`;
console.log("Extracted return_url:", body.return_url);
}
} catch (e) {
console.error("URL 处理错误:", e);
body.return_url = `${window.location.origin}/oauth/authorize`;
body.return_url = `${window.location.origin}/authorize`;
}
}