Client Setup
Better Auth provides framework-specific client helpers for React, Vue, Svelte, and more. All of them point to the Strapi-hosted Better Auth API at /api/auth.
Installation
Install the Better Auth client in your front-end project:
npm install better-auth
# or
pnpm add better-auth
React
lib/auth-client.ts
import { createAuthClient } from 'better-auth/react';
export const authClient = createAuthClient({
baseURL: 'http://localhost:1337/api/auth',
});
Sign up
import { authClient } from '@/lib/auth-client';
await authClient.signUp.email({
email: 'user@example.com',
password: 'password123',
name: 'Jane Doe',
});
Sign in
await authClient.signIn.email({
email: 'user@example.com',
password: 'password123',
});
Sign out
await authClient.signOut();
Get the current session
const { data: session } = authClient.useSession();
if (session) {
console.log('Logged in as', session.user.email);
}
Vue
lib/auth-client.ts
import { createAuthClient } from 'better-auth/vue';
export const authClient = createAuthClient({
baseURL: 'http://localhost:1337/api/auth',
});
Vanilla JS / other frameworks
lib/auth-client.ts
import { createAuthClient } from 'better-auth/client';
export const authClient = createAuthClient({
baseURL: 'http://localhost:1337/api/auth',
});
API base URL
The Better Auth API is mounted at /api/auth by default. All Better Auth endpoints (e.g. /sign-in/email, /sign-up/email, /get-session) are available under this path.
| Endpoint | URL |
|---|---|
| Sign up | POST /api/auth/sign-up/email |
| Sign in | POST /api/auth/sign-in/email |
| Sign out | POST /api/auth/sign-out |
| Get session | GET /api/auth/get-session |
tip
Refer to the Better Auth documentation for the full list of endpoints and client methods available for each plugin.