#Auth Error Calling appInstances.getAppInstance in Custom Panels

11 messages · Page 1 of 1 (latest)

round birch
#

Backend functions using appInstances.getAppInstance work fine when called from widget code, but fail with authentication error when called from settings panel code.

Error Message

json{
  "message": "Missing authentication information",
  "details": {
    "applicationError": {
      "description": "Missing authentication information",
      "code": 400
    }
  }
}```

**Backend Code**
```js

import { appInstances } from "@wix/app-management";
import { auth } from "@wix/essentials";
import { Permissions, webMethod } from "@wix/web-methods";

export const getInstanceFunction = webMethod(Permissions.Anyone, async () => {
    const elevatedGetInstance = auth.elevate(appInstances.getAppInstance);
    try {
        const instance = await elevatedGetInstance();
        return instance;
    } catch (error) {
        console.error(error);
        sendError(error?.stack || error?.message || error, "getInstanceFN", `N/A`);
        throw error;
    }
});

Calling From Widget Works Fine
Calling From Custom Panels Fail

What I Tried

Changed Permissions.Anyone to Permissions.Admin
Changed to Permissions.SiteOwner
Created separate function without webMethod
All produce same authentication error

Important Notes
Other backend functions (database/server calls) work fine from settings panel
Only functions using appInstances.getAppInstance fail in settings panel context
Widget code (even in editor preview) works perfectly

eager sage
#

The SDK for getting app instance seems to be very buggy within blocks. Would recommend using the Velo version 🙂

round birch
#

Ahhh okay, that makes sense.

Velo version unfortunatley is buggy on our end. We have some users where vendorProductId is returning null despite users being premium (ongoing wix dev inspection)

Going to go with the direct fetch api call approach to https://www.wixapis.com/apps/v1/instance with an access token then now for time being.

Question though, do you know if SDK is safe to use widget side. We are working on a new update of our app. Have been using the fetch api call as backup check along side the wixApplications approach due to the bug we are facing.

Is it risky to rely on SDK approach for the widget side. Is working fine on my test sites for widget (not panels)

#

Didnt like the current workaround as its extra calls which can cause potentially make things slower. So wanted to migrate to SDK to fix

fringe pike
#

It does not work properly in dashboard for the record 😉

eager sage
round birch
# eager sage Also now widgets 😉

Ahhh thats unfortunate...

Does seem to work on my test sites but thinking I should just stick with the REST approach to be safe...

The REST approach, do you guys know if thats reliable. Would it get rate limited by any chance if for example a website has a lot of traffic > widget loads many times and has to get access token plenty of times and make the rest call?
@eager sage @fringe pike

fringe pike
#

I'm not sure, but you could cache the call to your webmethod which would prevent overusage

round birch
fringe pike
#

seek web module caching in the doc 🙂