Elevate API Call Permissions

The Wix CLI is in Developer Preview and is subject to change.

CLI Documentation Notice

You're viewing documentation for the new Wix CLI, which we recommend for all new projects.

In workflows that use mostly site visitor, site member, or Wix user authentication, you may occasionally need to make calls with elevated permissions. You can use the JavaScript SDK to provide specific calls with Wix app authentication.

The process involves 2 steps:

  1. Set up your project's backend code to handle elevated requests.
  2. Send an authenticated call from your frontend code to your project's backend.

You can make calls from your frontend code to your project's backend using Astro's server endpoints feature.

Important: Exposed elevated function calls create a security risk for privilege escalation attacks. Make sure to protect your exposed function calls with the appropriate logic.

Step 1 | Set up the endpoint in your project's backend

Set up your project's backend to handle requests for elevated function calls from your frontend.

To set up your backend:

  1. Set up an Astro server endpoint.
  2. In the file that defines your endpoint, import the auth submodule from @wix/essentials as well as the module containing the function that you want to make elevated calls to.
    Copy
  3. Expose an endpoint that calls the function you need. Wrap the function with auth.elevate() before calling it.
    Copy

Step 2 | Send authenticated requests from your frontend

Send authenticated requests from your project's frontend code to your backend endpoint.

To send requests:

  1. Import the httpClient submodule from the @wix/essentials package.
    This submodule includes a function called fetchWithAuth. This function automatically signs API calls with an authorization header that identifies the current site visitor, site member, or Wix user.
    Copy
  2. Call your project's Astro server endpoint using fetchWithAuth().
    Copy

Example

Copy
Copy

See also

Did this help?