Plugins

Feedback

Allow users to submit feedback about your application.

VersionDownloadsLicense

The Feedback plugin allows users to submit feedback about your application. By default, only authenticated users can submit feedback, but this can be configured.

1. Install the plugin

npm install @better-auth-kit/feedback

2. Initialize the plugin

auth.ts
import { betterAuth } from "better-auth";
import { feedback } from "@better-auth-kit/feedback";
 
export const auth = betterAuth({
  plugins: [
    feedback(),
  ],
});
auth-client.ts
import { createAuthClient } from "better-auth";
import { feedbackClient } from "@better-auth-kit/feedback/client";
 
export const authClient = createAuthClient({
  plugins: [feedbackClient()],
});

3. Run migrations

Make sure to run migrations after configuring the plugin.

npx @better-auth/cli migrate
Learn more about the migrate/generate commands here.

4. Use the plugin

// Submit feedback (requires logged-in user by default)
await authClient.feedback.submit({
  text: "This is my feedback about the application"
});

Configuration Options

You can customize the Feedback plugin with the following options:

feedback({
  /* Text length constraints */
  minLength: 10, // Minimum text length (default: 10)
  maxLength: 500, // Maximum text length (default: 500)
 
  /* User submission controls */
  feedbackLimit: 5, // Limit number of feedbacks per user (optional)
  requireAuth: true, // Whether authentication is required (default: true)
  canSubmitFeedback: (user) => {
    // To add to control who can submit feedback
    // Ex: only allow organization owners
    return user.role === "owner";
  },
 
  /* To customize schema field names */
  schema: {
    feedback: {
      modelName: "feedbackEntries", // Rename the model
      fields: {
        userId: "authorId", // Rename fields
        text: "message",
        createdAt: "submittedAt",
      },
    },
  },
 
  /* To add additional fields to the schema */
  additionalFields: {
    category: { type: "string", required: true, default: "General" },
    rating: { type: "number", required: true, default: -1 },
  },
 
  /* To add callback function that gets executed server-side when feedback is submitted */
  onFeedback: async ({ feedback, user }) => {
    console.log(
      `Feedback submitted by ${user?.email ?? "USER UNKNOWN"}: ${feedback}`
    );
 
    // Example: Send ourselves an email using Resend
    await resend.emails.send({
      from: "noreply@yourapp.com",
      to: "owner@yourapp.com",
      cc: user?.email ? [user.email] : undefined, // You can even include the user
      subject: user?.email
        ? `Feedback submitted by ${user.email}`
        : "Anonymous feedback submitted",
      html: `<h1>Feedback submitted by ${user?.email ?? "Anonymous"}:</h1><p>${feedback.text}</p>`,
    });
  },
});

Schema

Pan and zoom to explore the schema.

Fields:

  • id: Unique identifier for the feedback entry
  • userId: ID of the user who submitted the feedback (optional if requireAuth is false)
  • text: The feedback content (controlled by minLength/maxLength)
  • createdAt: Timestamp when the feedback was submitted

Shoutout

This plugin was built by zpg6's Github avatarzpg6! ❤️

On this page