Plugins

Feedback

Allow users to submit feedback about your application

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({
      minLength: 10,           // Minimum feedback text length
      maxLength: 500,          // Maximum feedback text length
      feedbackLimit: 5,        // Optional: limit user to 5 feedbacks
      requireAuth: true,       // Optional: require authentication (default)
      canSubmitFeedback: (user) => user.role === 'owner', // Optional: control who can submit
      // Optional: customize schema and add additional fields
    }),
  ],
});
auth-client.ts
import { createAuthClient } from "better-auth";
import { feedbackClient } from "@better-auth-kit/feedback/client";
 
export const authClient = createAuthClient({
  plugins: [feedbackClient()],
});

3. Use the plugin

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

What does it do?

The Feedback plugin provides a way for users to submit feedback about your application. It stores:

  • The feedback text (with configurable min/max length)
  • The ID of the user who submitted the feedback (optional if requireAuth is false)
  • The timestamp when the feedback was submitted

This allows you to collect user feedback directly within your application, without requiring external tools or services.

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 control
  feedbackLimit: 5, // Limit number of feedbacks per user (optional)
  requireAuth: true, // Whether authentication is required (default: true)
  canSubmitFeedback: (user) => {
    // Function to control who can submit feedback
    return user.role === "owner";
  },
 
  // Customize schema field names
  schema: {
    feedback: {
      modelName: "feedbackEntries", // Rename the model
      fields: {
        userId: "authorId", // Rename fields
        text: "message",
        createdAt: "submittedAt",
      },
    },
  },
 
  // Add additional fields to the schema
  additionalFields: {
    category: { type: "string", required: true },
    rating: { type: "number", required: true },
  },
});

Schema

Table: feedback

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

Shoutout

This plugin was built by @zpg6. ❤️

On this page