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

fix: handle NPE when no popup is available #888

Merged
merged 2 commits into from
Mar 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions __tests__/Auth0Client/loginWithPopup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,16 @@ describe('Auth0Client', () => {
).rejects.toThrowError('Timeout');
});

it('throws an error if no popup could be opened', async () => {
const auth0 = setup();

// Use auth0.loginWithPopup directly here, which doesn't set up
// windowMock and returns null by default (as opposed to using the `loginWithPopup` helper)
await expect(auth0.loginWithPopup()).rejects.toThrowError(
/unable to open a popup/i
);
});

it('uses a custom popup specified in the configuration and redirect', async () => {
const auth0 = setup();
const popup = {
Expand Down
72 changes: 38 additions & 34 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/Auth0Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,12 @@ export default class Auth0Client {

if (!config.popup) {
config.popup = openPopup('');

if (!config.popup) {
throw new Error(
'Unable to open a popup for loginWithPopup - window.open returned `null`'
);
}
}

const { ...authorizeOptions } = options;
Expand Down