Add the invite client plugin to your Better Auth client configuration:
client.ts
import { createAuthClient } from "better-auth/client";import { inviteClient } from "better-auth/client/plugins";export const authClient = createAuthClient({ baseURL: "http://localhost:3000", // Your API base URL plugins: [inviteClient()],});
The invite client plugin provides full type inference based on your server configuration:
import type { InferServerPlugin } from "better-auth/client";import type { invite } from "better-auth/plugins";// Your client methods are fully typedtype InvitePlugin = InferServerPlugin<typeof invite>;
The client plugin automatically infers available endpoints and their request/response types from your server configuration.
For invitation links (callback flow), you can use the activation callback endpoint directly:
// The user clicks a link like:// https://yourapp.com/api/auth/invite/TOKEN?callbackURL=/dashboard// Better Auth automatically handles this and redirects the user// to the callbackURL with the token in a cookie
If you need to activate programmatically after the user follows a link:
// In your page componentconst searchParams = new URLSearchParams(window.location.search);const token = searchParams.get("token");if (token) { const result = await authClient.invite.activate({ token, callbackURL: window.location.pathname, }); if (result.action === "SIGN_IN_UP_REQUIRED") { // Redirect user to sign in/up page window.location.href = result.redirectTo; } else { // User is logged in, redirect to dashboard window.location.href = result.redirectTo; }}