A sign-in form checks an email address and a password and starts a session. This guide builds a Better Auth sign-in form in Next.js with authClient.signIn.email, and shows what a wrong password looks like in the browser and in the Terminal.
The short answer: in a client component, call authClient.signIn.email({ email, password }). When the password is right, Better Auth starts a session and sets its cookie; when it’s wrong, error.message says Invalid email or password.
Syntax
const { data, error } = await authClient.signIn.email({
email: "<email address>",
password: "<password>",
rememberMe: <true or false>,
callbackURL: "<page address>",
});
emailandpassword: what the person signed up with. Required.rememberMe:trueby default. Withfalse, the person is signed out when the browser closes. Optional.callbackURL: the page to open after signing in. Optional.erroris set when it fails, with a readableerror.message.
The reference: Sign In (opens in a new tab) in the Better Auth documentation.
Prerequisites
- Better Auth set up in a Next.js app, with email and password sign-in switched on (Enable Email and Password (opens in a new tab))
- an account that signed up with an email address and a password
Step 1: Create the Sign-In Page
The example is a small bookshop app with a header that shows who’s signed in. In the app folder, create a folder named sign-in, and in it a file named page.tsx:
"use client";
import Link from "next/link";
import { useRouter } from "next/navigation";
import { type FormEvent, useState } from "react";
import { authClient } from "@/lib/auth-client";
export default function SignInPage() {
const router = useRouter();
const [errorMessage, setErrorMessage] = useState("");
const [isPending, setIsPending] = useState(false);
async function handleSubmit(event: FormEvent<HTMLFormElement>) {
event.preventDefault();
const form = new FormData(event.currentTarget);
setErrorMessage("");
setIsPending(true);
const { error } = await authClient.signIn.email({
email: String(form.get("email")),
password: String(form.get("password")),
});
setIsPending(false);
if (error) {
setErrorMessage(error.message ?? "Sign-in failed. Please try again.");
return;
}
router.push("/");
}
return (
<main className="mx-auto w-full max-w-sm flex-1 px-6 py-12">
<h1 className="text-2xl font-semibold">Sign in</h1>
<form onSubmit={handleSubmit} className="mt-6 flex flex-col gap-4">
<label className="flex flex-col gap-1 text-sm">
Email
<input
name="email"
type="email"
required
autoComplete="email"
className="rounded border border-zinc-300 px-3 py-2 dark:border-zinc-700"
/>
</label>
<label className="flex flex-col gap-1 text-sm">
Password
<input
name="password"
type="password"
required
autoComplete="current-password"
className="rounded border border-zinc-300 px-3 py-2 dark:border-zinc-700"
/>
</label>
{errorMessage && (
<p role="alert" className="text-sm text-red-600">
{errorMessage}
</p>
)}
<button
type="submit"
disabled={isPending}
className="rounded bg-zinc-900 px-4 py-2 text-white disabled:opacity-50 dark:bg-zinc-100 dark:text-zinc-900"
>
{isPending ? "Signing in…" : "Sign in"}
</button>
</form>
<p className="mt-6 text-sm">
New to the Bookshop?{" "}
<Link href="/sign-up" className="underline">
Create an account
</Link>
</p>
</main>
);
}
authClient.signIn.email(…)sends the email address and password to Better Auth.- When
erroris set, the page showserror.message. Otherwiserouter.push("/")opens the home page. autoComplete="current-password"lets the browser fill in a saved password.
Open /sign-in in your browser:

Step 2: Sign In
Enter an email address with a wrong password and click Sign in:

The Terminal running the app logs the failed attempt:
2026-11-19T04:21:16.447Z WARN [Better Auth]: Invalid password
POST /api/auth/sign-in/email 401 in 111ms (next.js: 3ms, application-code: 108ms)
Now enter the right password. The home page opens with the person signed in:

Better Auth sets a cookie named better-auth.session_token. It’s HttpOnly, so scripts in the page can’t read it, and it lasts 7 days by default.
Troubleshooting
| Message | Cause | Fix |
|---|---|---|
Invalid email or password | The password, or the email address, is wrong | Check both and try again. |
FAQ
How do I keep people signed in only until they close the browser?
Pass rememberMe: false to signIn.email.
Can people sign in with a username?
Yes, with Better Auth’s username plugin (opens in a new tab).
Conclusion
authClient.signIn.email checks the password and starts a session. Show error.message when it fails, so the person knows to try again.
Additional Resources
- Sign In (opens in a new tab) in the Better Auth documentation
- Basic usage: Sign In (opens in a new tab)
- Cookies (opens in a new tab)
Related
- Better Auth Tutorial — Part 3: Sign Up and Sign In with Email and Password, where this is one step of the full setup
Better Auth, Next.js and other names mentioned are trademarks of their respective owners. JD Bots isn’t affiliated with or endorsed by Better Auth, Inc. or Vercel.
0 comments