-
Notifications
You must be signed in to change notification settings - Fork 27
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
Asub 8192/captcha2 login #1978
Asub 8192/captcha2 login #1978
Conversation
const { Identity, isInitialized } = useIdentity(); | ||
const { Sales } = useSales(); | ||
const [siteKey, setSiteKey] = useState(); | ||
console.log('siteKey', siteKey) |
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.
remove consoleLog
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.
Looks like some attributes are not being used: error, setError, isAdmin, phrases, ...
Is this PR a WIP, or is it ready for review? There's no test instructions, description, or linked ticket. The large amount of changes to our localization files is also concerning, was all of the code up to date before the |
@vgalatro I just put this up for Laura to take a look for now. Once she approves, I was going to ask for a review from the Themes team. I figured that we would do the same thing as how we did it for the 2.0 migration, where the subs team would review functionality, and the themes team would look at things specific to themes. |
@@ -0,0 +1,34 @@ | |||
import { useState } from "react"; |
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.
useIdentity was defined inside arc-themes-component project. I think it's worth defining this hook there too.
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.
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.
@edwardcho1231 Now It can be removed
|
||
useEffect(() => { | ||
const checkCaptcha = async () => { | ||
const config = await Identity.getConfig(); |
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.
@edwardcho1231 I think you can move L23-L25 into if
on L27, thus you call config from identity or sales, depending on challengeIn
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.
@LauraPinilla Don't we have to call Identity.config
even when the challengeIn === 'checkout'
since we need the recaptchaSiteKey?
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.
good point @edwardcho1231 I missed that. Yep for checkout we need to call both
This will need to go into 2.3.0 once the branch is created, as we're launching 2.2.1 soon with security hotfixes. |
@@ -1273,5 +1273,20 @@ | |||
"vi": "Tên người dùng", | |||
"zh-CN": "用户名", | |||
"zh-TW": "使用者名稱" | |||
}, | |||
"identity-block.bot-protection-error": { |
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.
Hi @edwardcho1231 , As part of the designs we have an additional reCaptcha state when it expires.
|
||
const onChange = (value) => { | ||
setCaptchaToken(value); | ||
localStorage.setItem('captchaToken', captchaToken); |
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.
@edwardcho1231 do you mind to use a different cookie name. One less common, something like ArcXP_captchaToken
or something like this. We want to avoid another app could overwrite this value
<section className={`${className}__bot-protection-section`} data-testid="bot-challege-protection-container"> | ||
{!!siteKey && <ReCAPTCHA | ||
sitekey={siteKey} | ||
onChange={onChange} |
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.
Checking the reCaptcha documentation if you include onExpired
, you will be able to see the error "Verification expired, Check the checkbox again" after two minutes the challenge was completed, once the token is expired
<ReCAPTCHA
sitekey={siteKey}
onChange={onChange}
onExpired
/>
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.
@vgalatro this ticket LGTM now. In case you want to start to take a look.
Thanks @edwardcho1231 for all these changes.
Only thing I see is the package.json and package-lock.json have some conflicts with the new base branch. The versions of those files in |
The changes look good now, but there's one last issue. There are failing tests that will prevent the block from being published. Please check them with |
…' into ASUB-8192/captcha2_login
@edwardcho1231 , the unit test check is still not passing due to low coverage:
It looks like the new |
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.
Changes look good, and the test/lint action is passing, approved!
@edwardcho1231 , I'll go ahead and merge this in since I'm not sure you'll be able to. |
ff21f40
into
arc-themes-release-version-2.3.0
If you have not filled out the checklist below, the pr is not ready for review.
Description
Create a new component to handle reCaptcha V2 for
signup
,signin
,magicLink
, andcheckout
Add reCaptcha V2 component to login block
Jira Ticket
https://arcpublishing.atlassian.net/browse/ASUB-8192
Acceptance Criteria
Update BotChallengeProtection component in identity-block
BotChallengeProtection will accept a challengeIn attribute. This attribute could be one of:
'signup' || ‘signin’ || ‘magiclink’ || ‘checkout’
IF !!`${challengeIn}Recaptcha && recaptchaScore between 0 - 1 &&!!recaptchaSiteKey
THEN render reCaptchaV3. reCaptchaV3 should be initialized by passing the recaptchaSiteKey
Every time you grab a response token from reCAPTCHA component, store the response in localStorage.
The BotChallengeProtection should be part of the Login block, and the reCaptcha token should be sent during the call to Identity.login();
User should be successfully Logged In when reCaptcha v3 is enabled for signin.
Write the integration tests required to check login is working as expected when signinRechaptcha (reCaptchaV3) is enabled/disabled.
Test Steps
git checkout {branch name}
npx fusion start -f -l @wpmedia/identity-block
login
block or visit a site with login blockEffect Of Changes
Before
Login block does not contain recaptcha box even when it's enabled for the org/site
After
reCaptcha box should be visible if enabled and required to pass before logging in.
Dependencies or Side Effects
Examples of dependencies or side effects are:
Author Checklist
The author of the PR should fill out the following sections to ensure this PR is ready for review.
npm run lint
to check for errors. Often,npm run lint:fix
will fix those errors and warnings.npm run test:coverage
to see your progress.npm run test
, made sure all tests are passingplease explain why (so that we can fix it whenever it gets refactored).
Reviewer Checklist
The reviewer of the PR should copy-paste this template into the review comments on review.