Get Started
Installation
Learn how to configure the invite plugin in your project.
Install the package
Start by adding the invite plugin to your project:
npm install better-auth-invite-pluginAdd the plugin to your auth config
Add the invite plugin to your auth configuration, make sure you also have the plugin admin.
import { betterAuth } from "better-auth"
import { admin } from "better-auth/plugins"
import { invite } from "better-auth-invite-plugin"
export const auth = betterAuth({
// ... other config options
plugins: [
admin({
ac,
roles: { user, admin },
defaultRole: "user",
})
invite({
defaultMaxUses: 1, // Default max uses for public invites
defaultRedirectAfterUpgrade: "/auth/invited", // Show the user their new role or account
async sendUserInvitation({ email, role, url, token, newAccount }) {
if (newAccount)
void sendInvitationEmail(role as RoleType, email, url);
void sendRoleUpgradeEmail(role as RoleType, email, url);
},
})
]
}) Migrate the database
Run the migration or generate the schema to add the necessary fields and tables to the database.
npx @better-auth/cli migratenpx @better-auth/cli generateSee the Schema section to add the fields manually.
Add the client plugin
Add the client plugin to your better auth client.
import { createAuthClient } from "better-auth/client";
import { adminClient } from "better-auth/client/plugins"
import { inviteClient } from "better-auth-invite-plugin";
const authClient = createAuthClient({
//... other options
plugins: [
adminClient(),
inviteClient()
],
}); How is this guide?
Last updated on