Skip to content

refactor(client): migrate captcha flow to betterCaptcha adapter model#3442

Open
lizheming wants to merge 19 commits intomainfrom
codex/refactor-@waline/client-to-use-better-captcha
Open

refactor(client): migrate captcha flow to betterCaptcha adapter model#3442
lizheming wants to merge 19 commits intomainfrom
codex/refactor-@waline/client-to-use-better-captcha

Conversation

@lizheming
Copy link
Copy Markdown
Collaborator

@lizheming lizheming commented Feb 26, 2026

fix #1829

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9820d8d660

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/client/src/utils/config.ts Outdated
@Mister-Hope
Copy link
Copy Markdown
Member

Mister-Hope commented Feb 26, 2026

I am confused why this is called betterCaptcha, not just captcha?

The better prefix seeks meaningless for option design

@doudou0720
Copy link
Copy Markdown

doudou0720 commented Feb 26, 2026

I am confused why this is called betterCaptcha, not just captcha?

See #3441,Cause the library was called Better Captcha

@lizheming lizheming marked this pull request as draft February 26, 2026 15:26
@Mister-Hope
Copy link
Copy Markdown
Member

Users do NOT care what libraries are behind the sense, in short, as long as the options are not "favored", shorter name with no confusion shall be always preferred. And we are now in the case.

@Mister-Hope
Copy link
Copy Markdown
Member

Also I would suggest leaving this as drafts till the package becomes stable or at least api solid

@lizheming
Copy link
Copy Markdown
Collaborator Author

@Mister-Hope I had AI initialize the relevant changes for this PR. Currently, the PR is still in draft. I will add you to the CR after I have made the necessary revisions and completed the testing.

Comment thread packages/server/src/logic/base.js Fixed
@lizheming lizheming marked this pull request as ready for review March 1, 2026 13:33
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 92a2c815fb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/admin/src/utils/getCaptchaConfig.js
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors Waline’s captcha integration to use the @better-captcha/* adapter model, introducing a unified captcha config (and request field) while deprecating the legacy recaptchaV3Key / turnstileKey flow. It addresses #1829 by making the client/admin captcha layer more extensible.

Changes:

  • Add captcha configuration to client typings/config and wire comment submission to send comment.captcha.
  • Replace admin login/register captcha UI with @better-captcha/react providers and send captcha in auth requests.
  • Add server-side compatibility by accepting captcha in BaseLogic.useCaptchaCheck().

Reviewed changes

Copilot reviewed 26 out of 27 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
pnpm-lock.yaml Adds @better-captcha/react / @better-captcha/vue and removes recaptcha-v3.
packages/server/src/middleware/dashboard.js Exposes captcha configuration to admin UI via window.*.
packages/server/src/logic/base.js Accepts captcha token as an alternative to turnstile / recaptchaV3.
packages/client/template/init.html Updates example config to reflect new captcha configuration direction.
packages/client/src/utils/config.ts Adds captcha to normalized config and maps legacy keys into captcha.
packages/client/src/typings/waline.ts Adds captcha prop and deprecates legacy captcha keys in typings.
packages/client/src/typings/index.ts Re-exports new captcha typings.
packages/client/src/typings/captcha.ts Introduces captcha provider option typings (based on @better-captcha/vue).
packages/client/src/composables/index.ts Removes old recaptcha/turnstile composables exports.
packages/client/src/components/CommentBox.vue Integrates @better-captcha/vue and sends captcha response with comment submit.
packages/client/src/components/Captcha.ts Adds provider-to-component mapping for client captcha rendering.
packages/client/rollup.config.ts Updates externals list (but currently does not account for @better-captcha/vue).
packages/client/package.json Adds @better-captcha/vue (currently in devDependencies).
packages/admin/src/utils/getCaptchaConfig.js Centralizes admin captcha config derivation.
packages/admin/src/store/user.js Adds captcha to login action payload.
packages/admin/src/services/auth.js Sends captcha field to server token endpoint.
packages/admin/src/pages/register/index.jsx Renders captcha provider component and submits captcha token.
packages/admin/src/pages/login/index.jsx Renders captcha provider component and submits captcha token.
packages/admin/src/components/Captcha.js Adds provider-to-component mapping for admin captcha rendering.
packages/admin/package.json Adds @better-captcha/react.
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported
Comments suppressed due to low confidence (2)

packages/client/src/components/CommentBox.vue:224

  • comment is typed as WalineCommentData, but later you assign comment.captcha (line 293). WalineCommentData from @waline/api currently only defines recaptchaV3 / turnstile and has no captcha field, which will break .d.ts generation/type-checking. Update the API typings to include captcha?: string (or extend the local type) so this assignment is type-safe.
  const { serverURL, lang, login, wordLimit, requiredMeta, captcha } = config.value;

  const comment: WalineCommentData = {
    comment: content.value,
    nick: userMeta.value.nick,
    mail: userMeta.value.mail,
    link: userMeta.value.link,
    url: config.value.path,
    ua: await userAgent(),
  };

packages/client/package.json:88

  • @better-captcha/vue is imported at runtime (e.g. in CommentBox.vue / Captcha.ts) and its types are referenced from the exported typings. Keeping it in devDependencies means downstream TypeScript consumers may fail to resolve the generated .d.ts imports. Move it to dependencies (or peerDependencies + dependenciesMeta), consistent with other runtime deps.
  "dependencies": {
    "@vueuse/core": "^14.2.1",
    "@waline/api": "workspace:*",
    "autosize": "^6.0.1",
    "marked": "^17.0.2",
    "marked-highlight": "^2.2.3",
    "vue": "^3.5.28"
  },
  "devDependencies": {
    "@babel/core": "7.29.0",
    "@babel/preset-env": "7.29.0",
    "@better-captcha/vue": "^0.5.6",
    "@giphy/js-types": "5.1.0",
    "@types/autosize": "4.0.3",
    "@vitejs/plugin-vue": "6.0.4",
    "vite": "7.3.1"
  },

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/admin/src/pages/login/index.jsx
Comment thread packages/admin/src/pages/register/index.jsx
Comment thread packages/client/src/components/CommentBox.vue Outdated
Comment thread packages/client/src/components/CommentBox.vue
Comment thread packages/client/src/typings/captcha.ts
Comment thread packages/server/src/middleware/dashboard.js Outdated
Comment on lines 96 to 99
],
treeshake: 'smallest',
external: [
'@vueuse/core',
'@waline/api',
'autosize',
'marked',
'marked-highlight',
'recaptcha-v3',
'vue',
],
external: ['@vueuse/core', '@waline/api', 'autosize', 'marked', 'marked-highlight', 'vue'],
},
Copy link

Copilot AI Mar 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@better-captcha/vue is now a runtime import in the slim/components builds, but it isn’t listed in external. This will bundle the captcha adapter into slim.js/component.js, which is inconsistent with how other runtime deps are treated here and may increase bundle size / duplicate dependencies. Consider adding @better-captcha/vue to external (and ensure it’s a proper dependency/peerDependency).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot open a new pull request to apply changes based on this feedback

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 1, 2026

@lizheming I've opened a new pull request, #3455, to work on those changes. Once the pull request is ready, I'll request review from you.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
lizheming and others added 5 commits March 1, 2026 22:08
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…dency (#3455)

* Initial plan

* fix: add @better-captcha/vue to external and move to dependencies

Co-authored-by: lizheming <424491+lizheming@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: lizheming <424491+lizheming@users.noreply.github.com>
Co-authored-by: Austin Lee <i@imnerd.org>
… github.com:walinejs/waline into codex/refactor-@waline/client-to-use-better-captcha
@lizheming
Copy link
Copy Markdown
Collaborator Author

@Mister-Hope the pr has been ready. You can code review it in your free time now.

@Mister-Hope
Copy link
Copy Markdown
Member

Mister-Hope commented Mar 1, 2026

{425A1883-E47A-4AD7-BA39-3CF536114370}

The notice seems dangerous to me; I am not sure we should merge a package with such a notice.

I would expect the package to be more stable. Though the api interface might not be changed, the core packages are still being heavily refactored in the past month, so at least that gives me the signal that the project is still in the development stage.

I would suggest delaying merging this PR.

@lizheming
Copy link
Copy Markdown
Collaborator Author

Yes, I agree it. It will be merged after I check more captcha service later. It won't be soon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: 如何添加极验等captcha?

6 participants