feat: Secure API routes with authentication checks and enhance redirect handling for unauthenticated users.
This commit is contained in:
@@ -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">
|
||||
|
||||
Reference in New Issue
Block a user