mirror of
https://github.com/LukeHagar/better-auth.git
synced 2025-12-06 04:19:20 +00:00
chore(demo): add loading state on sign in button
This commit is contained in:
@@ -17,12 +17,14 @@ import { Loader2 } from "lucide-react";
|
||||
import { signIn } from "@/lib/auth-client";
|
||||
import Link from "next/link";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { useRouter } from "next/navigation";
|
||||
|
||||
export default function SignIn() {
|
||||
const [email, setEmail] = useState("");
|
||||
const [password, setPassword] = useState("");
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [rememberMe, setRememberMe] = useState(false);
|
||||
const router = useRouter();
|
||||
|
||||
return (
|
||||
<Card className="max-w-md rounded-none">
|
||||
@@ -81,7 +83,16 @@ export default function SignIn() {
|
||||
className="w-full"
|
||||
disabled={loading}
|
||||
onClick={async () => {
|
||||
await signIn.email({ email, password });
|
||||
setLoading(true);
|
||||
await signIn.email(
|
||||
{ email, password, rememberMe: rememberMe ? true : false },
|
||||
{
|
||||
onSuccess(context) {
|
||||
router.push("/dashboard");
|
||||
},
|
||||
},
|
||||
);
|
||||
setLoading(false);
|
||||
}}
|
||||
>
|
||||
{loading ? <Loader2 size={16} className="animate-spin" /> : "Login"}
|
||||
|
||||
Reference in New Issue
Block a user