worldwide-asset-exchange / waxjs

Javascript API for integration with the WAX Cloud Wallet.
MIT License
127 stars 103 forks source link

Cant login in WAX account with waxjs #170

Closed f2re closed 1 year ago

f2re commented 1 year ago

Im update waxjs version because old version alert "You need to update version to use WAX". After update, Im trying to login to WAX as this:

const wax = new waxjs.WaxJS({ 
      rpcEndpoint:  'https://wax.greymass.com', 
      userAccount: network.account,
      tryAutoLogin: true,
      pubKeys: network.keys
     })
const userAccount = await wax.login()

but I have 422 error:

XHRGET
https://idm-api.mycloudwallet.com/v1/accounts/auto-accept/login
[HTTP/2 422  215ms]

GET
    https://idm-api.mycloudwallet.com/v1/accounts/auto-accept/login
Status
422
Referrer policystrict-origin-when-cross-origin

    access-control-allow-credentials
        true
    access-control-allow-origin
        http://localhost:8080
    cache-control
        no-cache, private
    cf-cache-status
        DYNAMIC
    cf-ray
        81828d1ffa2f16db-DME
    content-language
        ru
    content-type
        application/json
    date
        Wed, 18 Oct 2023 17:37:47 GMT
    server
        cloudflare
    vary
        Origin
    X-Firefox-Spdy
        h2

    Accept
        */*
    Accept-Encoding
        gzip, deflate, br
    Accept-Language
        ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3
    Connection
        keep-alive
    Host
        idm-api.mycloudwallet.com
    Origin
        http://localhost:8080
    Referer
        http://localhost:8080/
    Sec-Fetch-Dest
        empty
    Sec-Fetch-Mode
        cors
    Sec-Fetch-Site
        cross-site
    TE
        trailers

and responce content:

errors  [ {…} ]
0   Object { error_type: "Request validation error", message: "Session token required in header", error_code: "0" }

How to resolve this error?

niksad8 commented 1 year ago

are you running this in a browser? cause wax.login() should open a window to ask the user to login to the system

f2re commented 1 year ago

are you running this in a browser? cause wax.login() should open a window to ask the user to login to the system

Yea, in browser. Its not open window, it send request and got error 422. For user nothing happend.

f2re commented 1 year ago

Maybe it help - im testing on localhost. But in previous version it works normally on localhost too.

niksad8 commented 1 year ago

422 is normal for a login call, because by default it will try to auto log you in that is what the 422 error is coming from after this there should be a popup coming up with login dialog can you check if there are any console errors?

f2re commented 1 year ago

What I found also:

Uncaught (in promise) ReferenceError: Buffer is not defined
    loginViaWindow WaxSigningApi.js:124
    __awaiter WaxSigningApi.js:8
    __awaiter WaxSigningApi.js:4
    loginViaWindow WaxSigningApi.js:118
    login WaxSigningApi.js:40
    __awaiter WaxSigningApi.js:8
    __awaiter WaxSigningApi.js:4
    login WaxSigningApi.js:37
    login index.js:81
    __awaiter index.js:8
    __awaiter index.js:4
    login index.js:79
    login wax.js:37
    loginProvider App.vue:480
    didOpen App.vue:306
    didOpen App.vue:303
    Ze vue-sweetalert.umd.js:1
    setTimeout handler*Ze vue-sweetalert.umd.js:1
    Vo vue-sweetalert.umd.js:1
    Vo vue-sweetalert.umd.js:1
    _main vue-sweetalert.umd.js:1
    _main vue-sweetalert.umd.js:1
    qo vue-sweetalert.umd.js:1
    e vue-sweetalert.umd.js:1
    _n vue-sweetalert.umd.js:1
    showLogin App.vue:291
    mounted App.vue:545
    VueJS 2
    click Login.vue:54
    VueJS 33
WaxSigningApi.js:124

this error in @waxio/waxjs/dist/WaxSigningApi.js:

loginViaWindow() {
        return __awaiter(this, void 0, void 0, function* () {
            const url = new URL(`${this.waxSigningURL}/cloud-wallet/login`);
            if (this.returnTempAccount) {
                url.searchParams.append("returnTemp", "true");
            }
            if (version_1.version) {
                url.searchParams.append("v", Buffer.from(version_1.version).toString("base64"));
            }
            if (this.nonce) {
                url.searchParams.append("n", Buffer.from(this.nonce).toString("base64"));
            }
            const confirmationWindow = yield this.waxEventSource.openEventSource(url.toString());
            return this.waxEventSource.onceEvent(confirmationWindow, this.waxSigningURL, this.receiveLogin.bind(this), undefined);
        });
    }

Buffer is not defined and not included in @waxio/waxjs/dist/WaxSigningApi.d.ts

niksad8 commented 1 year ago

https://stackoverflow.com/questions/68707553/uncaught-referenceerror-buffer-is-not-defined, try this

f2re commented 1 year ago

Thanks, I see this too, but Im using vue-cli loader, and all instructions from stackoverflow not working. Maybe you can say how I can include Buffer in .ts file? or anything else....

f2re commented 1 year ago

Hey, Im insert next code in main.js and it works! Thank you very much!

import Buffer from "vue-buffer";
// @ts-ignore
window.Buffer = Buffer;
vnleona92 commented 10 months ago

341742