Skip to content
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

Avoid potential multiple invocations of loginWithRedirect #311

Merged
merged 3 commits into from
Dec 23, 2021

Conversation

kweiberth
Copy link
Contributor

Resolves #309

claimCheck = (): boolean => true,

// We used to default to empty object here w/ `loginOptions = {}`, but
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you remove this comment and instead add a regression test to with-authentication-required.test.tsx

Something like:

it('should only call login once when parent state changes', async () => {
    mockClient.getUser.mockResolvedValue(undefined);
    const MyComponent = (): JSX.Element => <>Private</>;
    const WrappedComponent = withAuthenticationRequired(MyComponent);
    const App = ({ foo }: { foo: number }): JSX.Element => (
      <div>
        {foo}
        <Auth0Provider clientId="__test_client_id__" domain="__test_domain__">
          <WrappedComponent />
        </Auth0Provider>
      </div>
    );
    const { rerender } = render(<App foo={1} />);
    await waitFor(() =>
      expect(mockClient.loginWithRedirect).toHaveBeenCalled()
    );
    mockClient.loginWithRedirect.mockClear();
    rerender(<App foo={2} />);
    await waitFor(() =>
      expect(mockClient.loginWithRedirect).not.toHaveBeenCalled()
    );
  });

@adamjmcgrath
Copy link
Contributor

Thanks @kweiberth! Will do put up a release straight after the holidays

@adamjmcgrath adamjmcgrath merged commit 1f46070 into auth0:master Dec 23, 2021
@kweiberth
Copy link
Contributor Author

Thank you @adamjmcgrath! And thanks for writing out the test. All sounds good, happy holidays!

@adamjmcgrath adamjmcgrath mentioned this pull request Jan 14, 2022
@GautamGupta
Copy link

Thanks!

@kevin19940627
Copy link

Hi there, withAuthenticationRequired seems to be invoking login multiple times with React 18 create react app. issues seem to appear when we use the new createRoot() API. is anyone experiencing the same issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

withAuthenticationRequired invokes loginWithRedirect multiple times
4 participants