Create a file named auth.server.ts in one of these locations:
Project root
lib/ folder
utils/ folder
You can also nest any of these folders under app/ folder. (e.g. app/lib/auth.server.ts)
And in this file, import Better Auth and create your instance.
Make sure to export the auth instance with the variable name auth or as a default export.
app/lib/auth.server.ts
import { betterAuth } from "better-auth"export const auth = betterAuth({ database: { provider: "postgres", //change this to your database provider url: process.env.DATABASE_URL, // path to your database or connection string }})
Create a client instance. Here we are creating auth.client.ts file inside the lib/ directory.
app/lib/auth.client.ts
import { createAuthClient } from "better-auth/react" // make sure to import from better-auth/reactexport const authClient = createAuthClient({ //you can pass client configuration here})
Once you have created the client, you can use it to sign up, sign in, and perform other actions.