Skip to content

Module - Better-Auth

The easiest way to get it today is to create a remult project with the cli and select better-auth as the auth provider. remult - Creating a project

Terminal window
npm init remult@latest

Then, you can take the ./src/demo/auth folder and copy it to your own project.

I suggest to put it in a ./src/modules folder.

When you use the mail module, you can use the sendVerificationEmail function to send a verification email.

src/modules/auth/server/auth.ts
export const auth = betterAuth({
database: remultAdapter(remult, {
authEntities,
usePlural: true,
}),
emailAndPassword: {
enabled: true,
requireEmailVerification: true,
},
emailVerification: {
autoSignInAfterVerification: true,
async sendVerificationEmail(data) {
const { user, url } = data
remult.context.sendMail?.('sendVerificationEmail', {
to: user.email,
subject: 'Welcome to our app!',
sections: [{ html: 'Verify your email', cta: { html: 'Verify', link: url } }],
})
},
},
})