Authenticate on behalf of a Wix User

Your app can authenticate on behalf of a Wix user to access site data and perform actions, combining the permissions of the app and the user. Wix users may have different user roles, resulting in different permissions granted to your app for each user.

On behalf of user authentication is supported for dashboard pages, which facilitate user site and business management. It allows your app to recognize requests aligned with the permissions of the Wix user within the dashboard.

This article explains how to authenticate on behalf of a Wix user using the Javascript SDK as well as the React SDK. The SDK manages the OAuth process for you behind the scenes. This functionality isn't currently supported using the REST API.

Important: This authentication strategy is currently only supported for dashboard pages.

Javascript SDK

To authenticate your app on behalf of a Wix user using the JavaScript SDK:

  1. Install the SDK:

    Copy
    1

    The SDK module is used to communicate with the Wix platform from JavaScript code by providing a client for making authenticated calls to Wix APIs.

  2. Install the Dashboard SDK:

    Copy
    1

    The Dashboard SDK allows code in custom dashboard components to interact with the Wix dashboard. This includes features like navigating users, displaying modals, and sending alerts and updates.

  3. Create a WixClient instance with the dashboard host and authentication strategy:

    Copy
    1

    The dashboard authentication strategy considers the Wix user in context, providing an app access token with combined app and user permissions.

  4. Make an API request. Behind the scenes, the client makes a request to obtain an access token and incorporates it into the Authorization request header. For example:

    Copy
    1

    Tip: If a REST API isn't available in the SDK, you can still access it using the fetch() method.

React SDK

To authenticate your app on behalf of a Wix user using the React SDK:

  1. Install the React SDK:

    Copy
    1

    The React SDK enables the integration of Wix JavaScript SDK APIs within React components.

  2. Install the Dashboard React SDK:

    Copy
    1

    The Dashboard React SDK is a collection of React utilites, components, and hooks that you can use to build Wix dashboard extensions with React.

  3. Wrap your code with the withDashboard() higher-order component:

    Copy
    1

    When you wrap a component with withDashboard(), a WixProvider component is initialized with the dashboard host and authentication strategy. This allows you to use useWixModules() to call JavaScript SDK APIs.

    The dashboard authentication strategy considers the Wix user in context, providing an app access token with combined app and user permissions.

  4. Make an API request. Behind the scenes, the client makes a request to obtain an access token and incorporates it into the Authorization request header. For example:

    Copy
    1

    Tip: If a REST API isn't available in the SDK, you can still access it using the useWixFetchWithAuth() hook.

See also

Was this helpful?
Yes
No