fix: Improve OAuth callback URL handling in authentication flow

This commit is contained in:
wood chen 2025-02-21 21:04:46 +08:00
parent f40979b4ad
commit c176362949
2 changed files with 5 additions and 4 deletions

View File

@ -14,7 +14,6 @@ export async function POST(req: Request) {
const nonce = WordArray.random(16).toString();
let return_url = `${hostUrl}/authorize`;
// 尝试从请求中获取 return_url
try {
const body = await req.json();
if (body.return_url) {

View File

@ -25,9 +25,11 @@ export function UserAuthForm({
try {
const body: Record<string, any> = {};
const callbackUrl = searchParams?.get("callbackUrl");
if (callbackUrl) {
const decodedUrl = decodeURIComponent(callbackUrl);
body.return_url = decodedUrl;
// 如果是 OAuth 回调,则提取原始的 /oauth/authorize 部分
if (callbackUrl?.includes("/oauth/authorize")) {
const url = new URL(callbackUrl);
body.return_url = `${window.location.origin}${url.pathname}${url.search}`;
}
const response = await fetch("/api/auth/q58", {