mirror of
https://github.com/woodchen-ink/Q58Connect.git
synced 2025-07-18 14:01:55 +08:00
feat: Enhance OAuth redirect with dynamic callback URL preservation
This commit is contained in:
parent
2f0d1aee47
commit
1edfc035e2
@ -1,6 +1,8 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
|
import { useEffect } from "react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
|
import { useRouter, useSearchParams } from "next/navigation";
|
||||||
import { MessageCircleCode } from "lucide-react";
|
import { MessageCircleCode } from "lucide-react";
|
||||||
|
|
||||||
import { UserAuthorize } from "@/components/auth/user-authorize";
|
import { UserAuthorize } from "@/components/auth/user-authorize";
|
||||||
@ -10,6 +12,16 @@ type Props = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default function AuthPage({ searchParams }: Props) {
|
export default function AuthPage({ searchParams }: Props) {
|
||||||
|
const router = useRouter();
|
||||||
|
const urlSearchParams = useSearchParams();
|
||||||
|
const callbackUrl = urlSearchParams.get("callbackUrl");
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (callbackUrl) {
|
||||||
|
router.replace(callbackUrl);
|
||||||
|
}
|
||||||
|
}, [callbackUrl, router]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="mx-auto flex w-full flex-col justify-center space-y-6 sm:w-[350px]">
|
<div className="mx-auto flex w-full flex-col justify-center space-y-6 sm:w-[350px]">
|
||||||
<div className="flex flex-col space-y-2 text-center">
|
<div className="flex flex-col space-y-2 text-center">
|
||||||
|
@ -21,7 +21,17 @@ export default async function OAuthAuthorization({
|
|||||||
// 检查用户是否已登录
|
// 检查用户是否已登录
|
||||||
const user = await getCurrentUser();
|
const user = await getCurrentUser();
|
||||||
if (!user?.id) {
|
if (!user?.id) {
|
||||||
redirect("/sign-in");
|
// 构建当前 URL 作为回调地址
|
||||||
|
const currentUrl = new URL(
|
||||||
|
"/oauth/authorize",
|
||||||
|
process.env.NEXT_PUBLIC_HOST_URL,
|
||||||
|
);
|
||||||
|
Object.entries(searchParams).forEach(([key, value]) => {
|
||||||
|
if (value) currentUrl.searchParams.append(key, value.toString());
|
||||||
|
});
|
||||||
|
redirect(
|
||||||
|
`/sign-in?callbackUrl=${encodeURIComponent(currentUrl.toString())}`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 验证必要的参数
|
// 验证必要的参数
|
||||||
|
Loading…
x
Reference in New Issue
Block a user