feat: Secure API routes with authentication checks and enhance redirect handling for unauthenticated users.

This commit is contained in:
2026-02-03 18:51:16 +00:00
parent 7c6d1cd681
commit be7db36126
9 changed files with 90 additions and 13 deletions

View File

@@ -3,11 +3,13 @@
import { SignIn } from "@/components/auth/SignIn";
import { Authenticated, Unauthenticated, useQuery } from "convex/react";
import { api } from "@/convex/_generated/api";
import { useRouter } from "next/navigation";
import { useRouter, useSearchParams } from "next/navigation";
import { useEffect } from "react";
export default function AuthPage() {
const router = useRouter();
const searchParams = useSearchParams();
const nextPath = searchParams.get("next");
return (
<div className="min-h-screen flex items-center justify-center bg-background">
@@ -15,17 +17,17 @@ export default function AuthPage() {
<SignIn />
</Unauthenticated>
<Authenticated>
<RedirectToDashboard />
<RedirectToDashboard nextPath={nextPath} />
</Authenticated>
</div>
);
}
function RedirectToDashboard() {
function RedirectToDashboard({ nextPath }: { nextPath: string | null }) {
const router = useRouter();
useEffect(() => {
router.push("/dashboard");
}, [router]);
router.push(nextPath || "/dashboard");
}, [router, nextPath]);
return (
<div className="text-center">