-
Notifications
You must be signed in to change notification settings - Fork 597
refactor(client): migrate captcha flow to betterCaptcha adapter model #3442
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lizheming
wants to merge
19
commits into
main
Choose a base branch
from
codex/refactor-@waline/client-to-use-better-captcha
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
9820d8d
refactor(client): unify captcha handling with betterCaptcha config
lizheming 51a6e67
refactor(admin): align captcha flow with betterCaptcha config
lizheming 83ae92f
chore: refactor with better-captcha module
lizheming 192669b
chore: use @better-captcha/react refact admin captcha
lizheming 93bde2a
chore: update config
lizheming 8ccf581
chore: update better-captcha config key
lizheming ad807af
chore: update admin react component
lizheming 02bd8f5
chore: remove log
lizheming fe488d0
chore: remove unused var
lizheming 92a2c81
chore: udpate captcah
lizheming 1532132
chore: update type
lizheming 774d235
chore: close some lint rule
lizheming a58e09e
Update packages/server/src/middleware/dashboard.js
lizheming 9889300
Update packages/client/src/components/CommentBox.vue
lizheming d51f3ff
fix: add @better-captcha/vue to external and promote to runtime depen…
Copilot 8a946d2
Merge branch 'codex/refactor-@waline/client-to-use-better-captcha' of…
lizheming 6b92f6c
fix: fix lint
lizheming be9449e
chore: update lock file
lizheming f984a53
Merge branch 'main' into codex/refactor-@waline/client-to-use-better-…
lizheming File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| import { useScriptTag } from '@vueuse/core'; | ||
|
|
||
| interface ReCaptchaWindow { | ||
| ready: (fn: () => void) => void; | ||
| execute: (siteKey: string, options: { action: string }) => Promise<string>; | ||
| } | ||
|
|
||
| interface TurnstileOptions { | ||
| sitekey: string; | ||
| action?: string; | ||
| size?: 'normal' | 'compact'; | ||
| callback?: (token: string) => void; | ||
| } | ||
|
|
||
| interface TurnstileWindow { | ||
| ready: (fn: () => void) => void; | ||
| render: (selector: string, options?: TurnstileOptions) => void; | ||
| } | ||
|
|
||
| declare global { | ||
| interface Window { | ||
| grecaptcha?: ReCaptchaWindow; | ||
| turnstile?: TurnstileWindow; | ||
| } | ||
| } | ||
|
|
||
| export interface CaptchaResult { | ||
| provider: string; | ||
| token: string; | ||
| } | ||
|
|
||
| export interface CaptchaAdapter { | ||
| execute: (action: string) => Promise<CaptchaResult>; | ||
| } | ||
|
|
||
| const recaptchaScriptStore: Record<string, Promise<void>> = {}; | ||
|
|
||
| const loadRecaptcha = (siteKey: string): Promise<void> => | ||
| (recaptchaScriptStore[siteKey] ??= (async () => { | ||
| const { load } = useScriptTag( | ||
| `https://recaptcha.net/recaptcha/api.js?render=${siteKey}`, | ||
| undefined, | ||
| { async: true }, | ||
| ); | ||
|
|
||
| await load(); | ||
| })()); | ||
|
|
||
| export const createRecaptchaAdapter = (siteKey: string): CaptchaAdapter => ({ | ||
| execute: async (action: string) => { | ||
| await loadRecaptcha(siteKey); | ||
|
|
||
| return new Promise((resolve, reject) => { | ||
| window.grecaptcha?.ready(() => { | ||
| void window.grecaptcha | ||
| ?.execute(siteKey, { action }) | ||
| .then((token) => { | ||
| resolve({ provider: 'recaptchaV3', token }); | ||
| }) | ||
| .catch((err: unknown) => { | ||
| reject(err); | ||
| }); | ||
| }); | ||
|
|
||
| if (!window.grecaptcha) | ||
| reject(new Error('Recaptcha script is not available, please check your site key.')); | ||
| }); | ||
| }, | ||
| }); | ||
|
|
||
| export const createTurnstileAdapter = (siteKey: string): CaptchaAdapter => ({ | ||
| execute: async (action: string) => { | ||
| const { load } = useScriptTag( | ||
| 'https://challenges.cloudflare.com/turnstile/v0/api.js', | ||
| undefined, | ||
| { async: false }, | ||
| ); | ||
|
|
||
| await load(); | ||
|
|
||
| return new Promise((resolve, reject) => { | ||
| window.turnstile?.ready(() => { | ||
| window.turnstile?.render('.wl-captcha-container', { | ||
| sitekey: siteKey, | ||
| action, | ||
| size: 'compact', | ||
| callback: (token) => { | ||
| resolve({ provider: 'turnstile', token }); | ||
| }, | ||
| }); | ||
| }); | ||
|
|
||
| if (!window.turnstile) | ||
| reject(new Error('Turnstile script is not available, please check your site key.')); | ||
| }); | ||
| }, | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,5 @@ | ||
| export * from './inputs.js'; | ||
| export * from './like.js'; | ||
| export * from './reaction.js'; | ||
| export * from './recaptchaV3.js'; | ||
| export * from './turnstile.js'; | ||
| export * from './captcha.js'; | ||
| export * from './userInfo.js'; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@better-captcha/vueis now a runtime import in the slim/components builds, but it isn’t listed inexternal. This will bundle the captcha adapter intoslim.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/vuetoexternal(and ensure it’s a proper dependency/peerDependency).There was a problem hiding this comment.
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