Password-based login
A user enters an email address and password in a login form.
Better Auth · Const
Better Auth’s signIn client API supports email/password authentication through signIn.email and social authentication through signIn.social. Email sign-in accepts credentials plus optional session persistence and redirect settings.
signIn is the client authentication entry point. Use its email method with credentials and optional session behavior or redirect settings; for social authentication, use its social method with a configured provider.
await authClient.signIn.email({ email, password, rememberMe?, callbackURL? })| Name | Type | Description |
|---|---|---|
email | string, required | The account email address. |
password | string, required | The account password; 8–128 characters by default. |
rememberMe | boolean, optional | Whether the session should persist after the browser closes; defaults to true. |
callbackURL | string, optional | URL to redirect to after successful sign-in. |
The client call resolves to an object containing data and error; successful authentication returns sign-in data, while failures are represented by error.
signIn.email method.email field identifies the account that should authenticate.password field supplies the credential checked during sign-in.callbackURL when the application should redirect the user after authentication.signIn.social method.rememberMe to false makes the session end when the browser closes.import { createAuthClient } from "better-auth/client";
const authClient = createAuthClient();
const { data, error } = await authClient.signIn.email({
email: "john.doe@example.com",
password: "password1234",
rememberMe: true,
});
if (error) console.error(error);
else console.log(data);Creates a Better Auth client and signs in with an email and password, then handles either the returned error or successful data.
A user enters an email address and password in a login form.
A user authenticates through Google, GitHub, Apple, or another configured provider.
An application needs to control whether a session survives browser closure.
A login flow must send the user to a specific page after success.
Use authClient.signIn.email with an object containing the user’s email and password. The result exposes data and error, so the caller can handle authentication success or failure explicitly.
Follow-up: How would you support OAuth instead? Call authClient.signIn.social with the configured provider ID, such as google or github.
rememberMe and callbackURL control?The request accepts rememberMe; when it is false, the user is signed out after the browser closes. It also accepts an optional callbackURL for redirecting after successful sign-in.
Follow-up: What must be configured before this call can work? Enable emailAndPassword in the auth configuration and ensure the client is created against the Better Auth instance.
signIn differ for social providers?Better Auth supports client-side social sign-in through authClient.signIn.social. The call receives a provider identifier, and that provider must be configured in the auth instance’s socialProviders option.
Follow-up: How can a server initiate social sign-in? Use the corresponding auth.api.signInSocial method with the provider in its request body.
signUp.emailsignIn.socialauth.api.signInEmailauth.api.signInSocialemailAndPassword.enabledsocialProviders