Invitation email

I probably missed something but in the doc, I don't understand how the invitation email is actually sent. We can read this:
await authClient.organization.inviteMember({
role: "admin", //this can also be an array for multiple roles (e.g. ["admin", "sale"])
})
await authClient.organization.inviteMember({
role: "admin", //this can also be an array for multiple roles (e.g. ["admin", "sale"])
})
No email is sent as obviously, better-auth doesn't know how to send an email.
My stack: - Sveltekit - Drizzle + Zod - Better-auth Here is my config
{
baseURL: "http://localhost:5173",
secret: AUTH_SECRET || "your-secret-key-at-least-32-characters",
database: drizzleAdapter(db, {
provider: "pg",
schema: schema,
}),
user: {
additionalFields: {
firstName: {
type: "string",
required: true,
input: true
},
lastName: {
type: "string",
required: true,
input: true
},
role: {
type: "string",
required: true,
input: false
}
}
},
emailAndPassword: {
enabled: true,
fromEmail: "[email protected]"
},
socialProviders: {
google: {
clientId: GOOGLE_CLIENT_ID,
clientSecret: GOOGLE_CLIENT_SECRET,
},
},
plugins: [
organization(),
admin()
],

debug: process.env.NODE_ENV !== 'production',
}
{
baseURL: "http://localhost:5173",
secret: AUTH_SECRET || "your-secret-key-at-least-32-characters",
database: drizzleAdapter(db, {
provider: "pg",
schema: schema,
}),
user: {
additionalFields: {
firstName: {
type: "string",
required: true,
input: true
},
lastName: {
type: "string",
required: true,
input: true
},
role: {
type: "string",
required: true,
input: false
}
}
},
emailAndPassword: {
enabled: true,
fromEmail: "[email protected]"
},
socialProviders: {
google: {
clientId: GOOGLE_CLIENT_ID,
clientSecret: GOOGLE_CLIENT_SECRET,
},
},
plugins: [
organization(),
admin()
],

debug: process.env.NODE_ENV !== 'production',
}
Can anyone point me in the right direction?
4 Replies
Jonas Dautel
Jonas Dautel•5d ago
hey @DarkZelus , check out this part of the docs : https://www.better-auth.com/docs/plugins/organization#setup-invitation-email Here is the example from there
import { betterAuth } from "better-auth"
import { organization } from "better-auth/plugins"
import { sendOrganizationInvitation } from "./email"
export const auth = betterAuth({
plugins: [
organization({
async sendInvitationEmail(data) {
const inviteLink = `https://example.com/accept-invitation/${data.id}`
sendOrganizationInvitation({
email: data.email,
invitedByUsername: data.inviter.user.name,
invitedByEmail: data.inviter.user.email,
teamName: data.organization.name,
inviteLink
})
},
}),
],
});
import { betterAuth } from "better-auth"
import { organization } from "better-auth/plugins"
import { sendOrganizationInvitation } from "./email"
export const auth = betterAuth({
plugins: [
organization({
async sendInvitationEmail(data) {
const inviteLink = `https://example.com/accept-invitation/${data.id}`
sendOrganizationInvitation({
email: data.email,
invitedByUsername: data.inviter.user.name,
invitedByEmail: data.inviter.user.email,
teamName: data.organization.name,
inviteLink
})
},
}),
],
});
where then sendOrganizationInvitation is a function you create to use a email provider of your choice
Organization | Better Auth
The organization plugin allows you to manage your organization's members and teams.
DarkZelus
DarkZelusOP•5d ago
Ohhhh how could I miss that? Thanks a lot @Jonas Dautel
Jonas Dautel
Jonas Dautel•5d ago
no worries 🙂 i have been there xD
DarkZelus
DarkZelusOP•5d ago
Ah ah ok 😉 Take care

Did you find this page helpful?