Redirect to implemented
This commit is contained in:
@@ -4,7 +4,7 @@ import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useRouter, useSearchParams } from "next/navigation";
|
||||
import useLogin from "@/hooks/use-login";
|
||||
import { Loader2 } from "lucide-react";
|
||||
|
||||
@@ -16,12 +16,20 @@ export function LoginForm({
|
||||
const [password, setPassword] = useState("");
|
||||
const { login, loading, isSuccess } = useLogin();
|
||||
const router = useRouter();
|
||||
const searchParams = useSearchParams();
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
|
||||
e.preventDefault();
|
||||
try {
|
||||
const res = await login({ email, password });
|
||||
if (res.status === "Success") router.push("/dashboard");
|
||||
if (res.status === "Success") {
|
||||
const redirectTo = searchParams.get("redirectTo");
|
||||
if (redirectTo) {
|
||||
router.push(redirectTo);
|
||||
} else {
|
||||
router.push("/dashboard");
|
||||
}
|
||||
}
|
||||
console.log(res);
|
||||
} catch (err: any) {
|
||||
console.log(err.message);
|
||||
|
||||
Reference in New Issue
Block a user