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

[wasm] loginWithPopup is not working #535

Open
6 tasks done
shovelmn12 opened this issue Mar 12, 2025 · 6 comments
Open
6 tasks done

[wasm] loginWithPopup is not working #535

shovelmn12 opened this issue Mar 12, 2025 · 6 comments
Labels
bug This points to a verified bug in the code web

Comments

@shovelmn12
Copy link

shovelmn12 commented Mar 12, 2025

Checklist

Description

When passing String params to the SDK it fails to login as String is not a JSAny.

obj.setProperty(key.toJS,value as JSAny);

This line should be changed to value.toJS

Also because of your defenition of params the funcationaddCustomParams<T extends JSObject>(final T obj, final Map<String, dynamic> params) should use final Map<String, String> params and not final Map<String, dynamic> params

After fixing this error loginWithPopup still did not work, I am getting error cancelled: Popup closed

I tried removing parameters and I am still getting the same error error cancelled: Popup closed

Reproduction

Pass String params to loginWithPopup and you will get an error Type 'String' is not a subtype of type 'JSValue' in type cast

if this is fixed then the next error you will get is error cancelled: Popup closed

Additional context

No response

auth0_flutter version

1.9.0

Flutter version

3.29.1

Platform

Web

Platform version(s)

wasm

@shovelmn12 shovelmn12 changed the title [wasm] String params are not supported [wasm] login is not working when passing params Mar 12, 2025
@shovelmn12 shovelmn12 changed the title [wasm] login is not working when passing params [wasm] loginWithPopup is not working Mar 12, 2025
@pmathew92
Copy link
Contributor

Hi @shovelmn12 , Thanks for bringing this to our notice. We will take a look and address this issue

@shovelmn12
Copy link
Author

@pmathew92 I checked the popup's console and I am getting the following:

{type: "authorization_response",response: {"error":"invalid_request","error_description":"authorization request parameter organization must be an organization id","state":"MVBMMHlvfmVSbHJBVzF1OW1icC5RZWJUUEpWWXowd0Jack1wbU5iTXJ3RQ=="}};

I am not setting any organizationId from flutter ... we dont use organizations

@shovelmn12
Copy link
Author

shovelmn12 commented Mar 14, 2025

@pmathew92 ok after further investigation I figured out the pop window thats opened is marked as closed on open.

popup opened 
Window {window: Window, self: Window, document: document, name: 'auth0:authorize:popup', location: Location,
blur: ƒ blur()
close: ƒ close()
closed: true,
...}

I added the following lines to .js SDK:

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

      console.log('popup opened', config.popup); // print popup

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

https://github.com/auth0/auth0-spa-js/blob/8b1609d3b91a96dbded37039913e3c5e72a5c78c/src/Auth0Client.ts#L361

therefore I am always getting Popup closed error ...

Edit: Aha!

https://developer.mozilla.org/en-US/docs/Web/API/Window/open#same-origin_policy

https://stackoverflow.com/questions/50143828/window-closed-is-always-true

Take into account, that [window.closed](https://developer.mozilla.org/en-US/docs/Web/API/Window/closed) always returns true, if the newly opened URL isn't from the same origin / domain as it is opened from

Edit 2: Both including null values in the URL and window.closed being true are issues, couldnt figure out how to solve the window.closed when developing. I guess when I run it on the same domin it will work because of cors

@pmathew92
Copy link
Contributor

Hi @shovelmn12 , for the organizationId issue you can skip passing that parameter.
On the window.closed error, we did spent sometime to debug this for a proper fix. Will revert here
cc @tusharpandey13

@shovelmn12
Copy link
Author

shovelmn12 commented Mar 14, 2025

@pmathew92 thats the thing, I am NOT passing any org... check the reference js issue (auth0/auth0-spa-js#1349)

@shovelmn12
Copy link
Author

shovelmn12 commented Mar 14, 2025

@pmathew92 the funny thing is that this works when not runnin flutter in wasm ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This points to a verified bug in the code web
Projects
None yet
Development

No branches or pull requests

2 participants