Configure Authentication
Email & Password
Set up email and password authentication with email verification, password reset, and customizable validation.
Email and password is the most common authentication method. Banata Auth provides a complete implementation with email verification, password reset, configurable validation rules, and automatic audit logging.
Enabling Email & Password
From the Dashboard
- Go to Authentication > Methods in your project.
- Toggle on Email & Password.
- Configure an email provider under Emails > Providers (required for verification and password reset emails).
- Customize email templates under Email Templates if needed.
From the SDK
await banata.configuration.saveDashboardConfig({
authMethods: {
emailPassword: true,
},
emailPassword: {
requireEmailVerification: true,
autoSignIn: true,
minPasswordLength: 8,
maxPasswordLength: 128,
},
});Configuration Options
| Option | Default | Description |
|---|---|---|
requireEmailVerification | true | Users must verify their email before signing in |
autoSignIn | true | Automatically create a session after sign-up |
minPasswordLength | 8 | Minimum password length |
maxPasswordLength | 128 | Maximum password length |
Sign Up
Use the auth client to create a new account:
import { authClient } from "@/lib/auth-client";
const { data, error } = await authClient.signUp.email({
email: "jane@example.com",
password: "securePassword123",
name: "Jane Doe",
});
if (error) {
console.error(error.message);
// Possible errors:
// - "User already exists" (409)
// - "Invalid email" (422)
// - "Password too short" (422)
} else {
console.log(data.user); // { id, email, name, ... }
console.log(data.session); // { id, token, expiresAt, ... }
}If email verification is enabled, the user receives a verification email after signing up. If autoSignIn is enabled, they also get a session immediately (but some features may be restricted until verification).
Using the Pre-Built Form
import { SignUpForm } from "@banata-auth/react";
import { authClient } from "@/lib/auth-client";
export default function SignUpPage() {
return (
<SignUpForm
authClient={authClient}
callbackURL="/dashboard"
onError={(error) => console.error(error.message)}
/>
);
}Sign In
const { data, error } = await authClient.signIn.email({
email: "jane@example.com",
password: "securePassword123",
});
if (error) {
console.error(error.message);
// Possible errors:
// - "Invalid email or password" (401)
// - "Email not verified" (403)
// - "Account is banned" (403)
// - "Too many attempts" (429)
} else {
window.location.href = "/dashboard";
}Using the Pre-Built Form
import { SignInForm } from "@banata-auth/react";
import { authClient } from "@/lib/auth-client";
export default function SignInPage() {
return (
<SignInForm
authClient={authClient}
callbackURL="/dashboard"
onError={(error) => console.error(error.message)}
/>
);
}Sign Out
await authClient.signOut();
window.location.href = "/sign-in";Password Reset
Step 1: Request a Reset Link
The user enters their email address and Banata sends a password reset email:
const { error } = await authClient.forgetPassword({
email: "jane@example.com",
redirectTo: "/reset-password",
});
if (!error) {
// Show "Check your email" message
}Step 2: Reset the Password
On the /reset-password page, extract the token from the URL and submit the new password:
const token = new URLSearchParams(window.location.search).get("token");
const { error } = await authClient.resetPassword({
newPassword: "newSecurePassword456",
token: token!,
});
if (!error) {
window.location.href = "/sign-in";
}Email Verification
Email verification happens automatically when the user clicks the link in the verification email. The link hits /api/auth/verify-email with the token, and Banata handles the rest.
To resend the verification email:
await authClient.sendVerificationEmail({
email: "jane@example.com",
callbackURL: "/dashboard",
});Server-Side User Management
Use the admin SDK to manage users from your backend:
import { BanataAuth } from "@banata-auth/sdk";
const banata = new BanataAuth({
apiKey: process.env.BANATA_API_KEY!,
baseUrl: "https://auth.banata.dev",
});
// List users
const { data, listMetadata } = await banata.userManagement.listUsers({ limit: 20 });
// Create a user programmatically
await banata.userManagement.createUser({
email: "admin@example.com",
password: "securePassword123",
name: "Admin User",
role: "admin",
});
// Update a user
await banata.userManagement.updateUser({
userId: "usr_01...",
name: "Updated Name",
metadata: { plan: "pro" },
});
// Ban a user
await banata.userManagement.banUser({ userId: "usr_01..." });
// Delete a user
await banata.userManagement.deleteUser({ userId: "usr_01..." });Password Validation
Passwords are validated on both sign-up and password reset:
| Rule | Default |
|---|---|
| Minimum length | 8 characters |
| Maximum length | 128 characters |
If a password doesn't meet the requirements, a ValidationError (422) is returned. You can add custom client-side validation in your forms for additional rules (uppercase, numbers, special characters) before calling the API.
Rate Limits
| Endpoint | Limit |
|---|---|
| Sign in | 30 requests per minute |
| Sign up | 10 requests per minute |
Rate limits are project-scoped and identifier-aware for email-based endpoints.
Error Reference
| Error | Status | Cause |
|---|---|---|
AuthenticationError | 401 | Invalid email or password |
ForbiddenError | 403 | Email not verified, or account banned |
ConflictError | 409 | Email already registered |
ValidationError | 422 | Invalid email format or password too short/long |
RateLimitError | 429 | Too many sign-in or sign-up attempts |
Security Best Practices
- Enable email verification — prevents sign-up with someone else's email address.
- Use HTTPS in production — session cookies are
Secure-flagged. - Set a strong
BETTER_AUTH_SECRET— useopenssl rand -base64 32to generate one. - Don't disable rate limiting — the defaults prevent brute force attacks.
Next Steps
- Social OAuth — Add Google, GitHub, and more alongside email/password
- Magic Links — Offer passwordless sign-in via email
- Multi-Factor Auth — Add TOTP-based two-factor authentication
- Organizations — Multi-tenant workspaces