-
Notifications
You must be signed in to change notification settings - Fork 212
Fix potential race condition bug in pwless login #2758
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
Changes from 2 commits
ea3b3df
dc12c4a
fc5e79e
d48e1af
c1c3804
0e89a9d
80b0bfd
86d6229
eea3677
5d705a3
6af0bca
91c722e
9f6a29c
58bbcb3
8dec3de
b0a004f
774ab91
952ef3e
1233881
874797a
db741e2
9180224
847f979
bddbfe4
443a51a
07d4e75
eaa944a
c9626da
168c9f2
c5c5756
f329e64
2ec021a
c60168e
1fd92cd
251b983
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,6 +48,7 @@ jest.mock('../util/checkout-context', () => { | |
|
|
||
| afterEach(() => { | ||
| jest.resetModules() | ||
| jest.restoreAllMocks() | ||
| }) | ||
|
|
||
| describe('passwordless and social disabled', () => { | ||
|
|
@@ -148,9 +149,11 @@ describe('passwordless enabled', () => { | |
| }) | ||
|
|
||
| test('allows passwordless login', async () => { | ||
| jest.spyOn(window, 'location', 'get').mockReturnValue({ | ||
| pathname: '/checkout' | ||
| const mockLocation = jest.spyOn(window, 'location', 'get').mockReturnValue({ | ||
| pathname: '/checkout', | ||
| origin: 'https://webhook.site' | ||
|
||
| }) | ||
|
|
||
| const {user} = renderWithProviders(<ContactInfo isPasswordlessEnabled={true} />) | ||
|
|
||
| // enter a valid email address | ||
|
|
@@ -160,7 +163,6 @@ describe('passwordless enabled', () => { | |
| const passwordlessLoginButton = screen.getByText('Secure Link') | ||
| // Click the button twice as the isPasswordlessLoginClicked state doesn't change after the first click | ||
| await user.click(passwordlessLoginButton) | ||
| await user.click(passwordlessLoginButton) | ||
| expect( | ||
| mockAuthHelperFunctions[AuthHelpers.AuthorizePasswordless].mutateAsync | ||
| ).toHaveBeenCalledWith({ | ||
|
|
@@ -177,14 +179,17 @@ describe('passwordless enabled', () => { | |
| }) | ||
|
|
||
| // resend the email | ||
| user.click(screen.getByText(/Resend Link/i)) | ||
| await user.click(screen.getByText(/Resend Link/i)) | ||
| expect( | ||
| mockAuthHelperFunctions[AuthHelpers.AuthorizePasswordless].mutateAsync | ||
| ).toHaveBeenCalledWith({ | ||
| userid: validEmail, | ||
| callbackURI: | ||
| 'https://webhook.site/27761b71-50c1-4097-a600-21a3b89a546c?redirectUrl=/checkout' | ||
| }) | ||
|
|
||
| // Cleanup mocks | ||
| mockLocation.mockRestore() | ||
| }) | ||
|
|
||
| test('allows login using password', async () => { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,7 +37,7 @@ const LoginState = ({ | |
| <Button | ||
| variant="outline" | ||
| borderColor="gray.500" | ||
| type="submit" | ||
| type="button" | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We know that pwless does not require the same flow as other flows, we can safely use type=button to avoid it go through submission and handle the flow right in the |
||
| onClick={() => { | ||
| handlePasswordlessLoginClick() | ||
| }} | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.