-
Notifications
You must be signed in to change notification settings - Fork 1
Auth
GitHub Action edited this page Jul 31, 2025
·
1 revision
This project now includes user authentication using Better Auth with Drizzle ORM adapter.
- Email/Password Authentication: Users can sign up and sign in with email and password
- Session Management: Sessions persist for 7 days with refresh every 24 hours
- Database Integration: User data is stored in PostgreSQL using Drizzle ORM
- Type Safety: Full TypeScript support with Better Auth types
The following tables have been added to support authentication:
-
user- Stores user information (id, name, email, emailVerified, image, createdAt, updatedAt) -
session- Stores user sessions (id, userId, token, expiresAt, ipAddress, userAgent, createdAt, updatedAt) -
account- Stores account information for different providers -
verification- Stores email verification tokens
Better Auth provides the following endpoints:
-
GET /api/auth/ok- Health check endpoint -
POST /api/auth/sign-up/email- Create new user account -
POST /api/auth/sign-in/email- Sign in existing user -
POST /api/auth/sign-out- Sign out current user -
GET /api/auth/session- Get current session information
-
/auth?mode=signup- Sign up page -
/auth?mode=signin- Sign in page -
/auth/signout- Sign out action (POST)
import { signIn, signUp, signOut, useSession } from "~/lib/auth-client";
// Sign up new user
await signUp.email({
email: "user@example.com",
password: "password123",
name: "John Doe"
});
// Sign in existing user
await signIn.email({
email: "user@example.com",
password: "password123"
});
// Sign out
await signOut();
// Get session in React components
const { data: session } = useSession();import { auth } from "../../auth.js";
export async function loader({ request }) {
const session = await auth.api.getSession({
headers: request.headers,
});
if (session) {
// User is authenticated
console.log(session.user.email);
}
}The auth configuration is in /auth.ts:
- Database connection using Drizzle adapter
- Email/password authentication enabled
- No email verification required (for development)
- 7-day session expiration
- 24-hour session refresh
- Secure session token generation
- Password hashing
- CSRF protection
- Rate limiting (configurable)
- Secure cookie settings in production
You can extend the authentication system by:
- Adding email verification
- Implementing password reset
- Adding OAuth providers (Google, GitHub, etc.)
- Adding two-factor authentication
- Implementing role-based access control
- Adding user profile management