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:
-
Install the SDK:
Copy1The SDK module is used to communicate with the Wix platform from JavaScript code by providing a client for making authenticated calls to Wix APIs.
-
Install the Dashboard SDK:
Copy1The 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.
-
Create a
WixClient
instance with the dashboard host and authentication strategy:Copy1The dashboard authentication strategy considers the Wix user in context, providing an app access token with combined app and user permissions.
-
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:Copy1Tip: 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:
-
Install the React SDK:
Copy1The React SDK enables the integration of Wix JavaScript SDK APIs within React components.
-
Install the Dashboard React SDK:
Copy1The Dashboard React SDK is a collection of React utilites, components, and hooks that you can use to build Wix dashboard extensions with React.
-
Wrap your code with the
withDashboard()
higher-order component:Copy1When you wrap a component with
withDashboard()
, aWixProvider
component is initialized with the dashboard host and authentication strategy. This allows you to useuseWixModules()
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.
-
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:Copy1Tip: If a REST API isn't available in the SDK, you can still access it using the
useWixFetchWithAuth()
hook.