[PR #4281] [MERGED] fix(cli): simplify and correct comma insertion logic in plugin array #30890

Closed
opened 2026-04-17 21:53:18 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/4281
Author: @bytaesu
Created: 8/28/2025
Status: Merged
Merged: 8/29/2025
Merged by: @himself65

Base: canaryHead: fix/cli-generator-edge-case


📝 Commits (2)

  • 6022af1 fix: adjust add_plugin logic
  • a39a2e0 test: handle empty plugins array edge case

📊 Changes

2 files changed (+40 additions, -17 deletions)

View changed files

📝 packages/cli/src/generators/auth-config.ts (+9 -17)
📝 packages/cli/test/generate.test.ts (+31 -0)

📄 Description


This PR fixes an edge case bug by simplifying and cleaning up the plugin insertion logic.


For example:

◇  Would you like to set up plugins?
│  Yes
│
◇  Select your new plugins
│  none
│
◇  It looks like you're using NextJS. Do you want to add the next-cookies plugin? (Recommended)
│  Yes

Result:

import { nextCookies } from "better-auth/next-js";
import { betterAuth } from "better-auth";

export const auth = betterAuth({
    appName: "testing",
    plugins: [, nextCookies()],
});

Bug fix test:

before after

Summary by cubic

Fixes the CLI generator so adding a plugin never produces an empty element or stray commas in the plugins array. This prevents invalid configs like plugins: [, nextCookies()] and makes plugin insertion reliable.

  • Bug Fixes
    • Simplified plugin insertion: detect empty arrays and trailing commas, then insert with or without a comma as needed.
    • Fixed return path to use the new content directly.
    • Added a test to cover insertion into an empty plugins array.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/4281 **Author:** [@bytaesu](https://github.com/bytaesu) **Created:** 8/28/2025 **Status:** ✅ Merged **Merged:** 8/29/2025 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `fix/cli-generator-edge-case` --- ### 📝 Commits (2) - [`6022af1`](https://github.com/better-auth/better-auth/commit/6022af1eb7c35831799340b2545805f5f62514dc) fix: adjust add_plugin logic - [`a39a2e0`](https://github.com/better-auth/better-auth/commit/a39a2e0727cdb0f966352677138b15b0d531f374) test: handle empty plugins array edge case ### 📊 Changes **2 files changed** (+40 additions, -17 deletions) <details> <summary>View changed files</summary> 📝 `packages/cli/src/generators/auth-config.ts` (+9 -17) 📝 `packages/cli/test/generate.test.ts` (+31 -0) </details> ### 📄 Description --- This PR fixes an edge case bug by simplifying and cleaning up the plugin insertion logic. --- For example: ``` ◇ Would you like to set up plugins? │ Yes │ ◇ Select your new plugins │ none │ ◇ It looks like you're using NextJS. Do you want to add the next-cookies plugin? (Recommended) │ Yes ``` Result: ```ts import { nextCookies } from "better-auth/next-js"; import { betterAuth } from "better-auth"; export const auth = betterAuth({ appName: "testing", plugins: [, nextCookies()], }); ``` Bug fix test: <img width="400" alt="before" src="https://github.com/user-attachments/assets/ddcd6f09-8060-4fe5-bbd7-2c495b6612ce" /> <img width="400" alt="after" src="https://github.com/user-attachments/assets/c14fe094-77cd-413f-b0db-814ea057a903" /> <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixes the CLI generator so adding a plugin never produces an empty element or stray commas in the plugins array. This prevents invalid configs like plugins: [, nextCookies()] and makes plugin insertion reliable. - **Bug Fixes** - Simplified plugin insertion: detect empty arrays and trailing commas, then insert with or without a comma as needed. - Fixed return path to use the new content directly. - Added a test to cover insertion into an empty plugins array. <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-17 21:53:18 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#30890