elevate( )
Allows a site visitor to call a function without the required permissions.
Description
Warning: The
elevate()
function enables site visitors to call functions without the required permissions. Exercise caution when using this function to prevent security vulnerabilities.
The elevate()
function receives a function requiring permissions and returns an instance of the same function that any site visitor can run.
Some functions require specific roles and permissions to run.
Other functions may limit functionality depending on the the visitor's roles and permissions.
Using elevate()
bypasses the permissions by elevating the site visitor's permissions to the highest level.
For example, the wix-bookings-backend
function confirmBooking()
requires Bookings Admin permissions.
Use elevate()
to allow any visitor to run confirmBooking()
.
javascript | Copy Codeconst myElevatedConfirmBooking = elevate(bookings.confirmBooking);
Notes:
- The
elevate()
function can only be used in the backend.- Some functions have a
suppressAuth
option for overriding permissions. For these functions, usesuppressAuth
instead ofelevate()
. Check your function's reference documentation to see whethersuppressAuth
orelevate()
is supported.
Syntax
function elevate(sourceFunction: Function): Function
elevate Parameters
NAME
TYPE
DESCRIPTION
Function of which to create an instance with elevated permissions.
Returns
Specified function with elevated permissions.
Return Type:
Was this helpful?
1import { bookings } from 'wix-bookings-backend';2import * as wixAuth from 'wix-auth';34// Sample bookingId value: '001c0674-d7c9-4c77-acb5-b492b427b201'56export async function myElevatedConfirmBookingFunction(bookingId) {7 const elevatedConfirmBooking = wixAuth.elevate(bookings.confirmBooking);89 try {10 const confirmedBookingId = await elevatedConfirmBooking(bookingId);1112 console.log('Success! Confirmed booking:', confirmedBookingId);13 return confirmedBookingId;14 } catch (error) {15 console.error(error);16 // Handle error17 }18}1920/* Returns:21 * "001c0674-d7c9-4c77-acb5-b492b427b201"22 */
1import { contacts } from 'wix-crm-backend';2import * as wixAuth from 'wix-auth';34// Sample contactId value: 'bc0ae72b-3285-485b-b0ad-c32c769a4daf'56export async function myElevatedGetContactFunction(contactId) {7 const elevatedGetContact = wixAuth.elevate(contacts.getContact);89 try {10 const myContact = await elevatedGetContact(contactId);1112 const id = myContact._id;13 const firstName = myContact.info.name.first;14 const lastName = myContact.info.name.last;1516 console.log('Success! Got contact:', myContact);17 return myContact;18 } catch (error) {19 console.error(error);20 // Handle error21 }22}2324/* Returns:25 * {26 * "_id": "bc0ae72b-3285-485b-b0ad-c32c769a4daf",27 * "_createdDate": "2021-03-30T13:12:39.650Z",28 * "_updatedDate": "2021-03-30T13:12:39.650Z",29 * "revision": 0,30 * "info": {31 * "name": {32 * "first": "Gene",33 * "last": "Lopez"34 * },35 * "birthdate": "1981-11-02",36 * "company": "Borer and Sons, Attorneys at Law",37 * "jobTitle": "Senior Staff Attorney",38 * "labelKeys": [39 * "custom.white-glove-treatment",40 * "contacts.contacted-me",41 * "custom.new-lead"42 * ],43 * "locale": "en-us",44 * "emails": [45 * {46 * "_id": "5bdcce4a-37c2-46ed-b49c-d562c6e3c4ce",47 * "tag": "HOME",48 * "email": "gene.lopez.at.home@example.com",49 * "primary": true50 * },51 * {52 * "_id": "78e5f398-e148-448d-b490-7c0b7d2ab336",53 * "tag": "WORK",54 * "email": "gene.lopez@example.com",55 * "primary": false56 * }57 * ],58 * "phones": [59 * {60 * "_id": "820e4640-ffe0-4980-a097-62a715e73135",61 * "tag": "MOBILE",62 * "countryCode": "US",63 * "phone": "(722)-138-3099",64 * "primary": true65 * },66 * {67 * "_id": "8506549e-e4f8-42f6-b6fc-9db155b582ef",68 * "tag": "HOME",69 * "countryCode": "US",70 * "phone": "(704)-454-1233",71 * "e164Phone": "+17044541233",72 * "primary": false73 * }74 * ],75 * "addresses": [76 * {77 * "address": {78 * "formatted": "9834 Bollinger Rd\nEl Cajon, WY 97766\nUS",79 * "location": {80 * "latitude": 84.1048,81 * "longitude": -116.883682 * },83 * "city": "El Cajon",84 * "subdivision": "US-WY",85 * "country": "US",86 * "postalCode": "97766",87 * "streetAddress": {88 * "name": "Bollinger Rd",89 * "number": "9834",90 * "apt": ""91 * }92 * },93 * "_id": "8532051f-91f2-42d9-9a97-9f2c39e64f7a",94 * "tag": "HOME"95 * }96 * ],97 * "profilePicture": "https://randomuser.me/api/portraits/men/0.jpg",98 * "extendedFields": {99 * "contacts.displayByLastName": "Lopez Gene",100 * "emailSubscriptions.deliverabilityStatus": "NOT_SET",101 * "emailSubscriptions.subscriptionStatus": "NOT_SET",102 * "custom.event-we-met-at": "LegalBigData",103 * "emailSubscriptions.effectiveEmail": "gene.lopez.at.home@example.com",104 * "contacts.displayByFirstName": "Gene Lopez"105 * }106 * },107 * "lastActivity": {108 * "activityDate": "2021-03-30T13:12:39.649Z",109 * "activityType": "CONTACT_CREATED"110 * },111 * "primaryInfo": {112 * "email": "gene.lopez.at.home@example.com",113 * "phone": "(722)-138-3099"114 * },115 * "source": {116 * "sourceType": "OTHER"117 * }118 * }119 */
1import { proGallery } from 'wix-pro-gallery-backend';2import * as wixAuth from 'wix-auth';34// Sample cloneFromGalleryId value: '10874ccf-5867-4225-9550-3885079bad66'56export async function myCreateGalleryFunction(cloneFromGalleryId){7 const elevatedCreateGallery = wixAuth.elevate(proGallery.createGallery);89 try {10 const newGallery = await elevatedCreateGallery({cloneFromGalleryId});1112 const id = newGallery._id;13 const name = newGallery.name;14 const items = newGallery.items;15 const firstItemTitle = newGallery.items[0].title;1617 console.log('Success! Created a new gallery:', newGallery);18 return newGallery;19 } catch (error) {20 console.error(error);21 // Handle the error22 }23}2425/* Returns:26 * {27 * "gallery": {28 * "_createdDate": "Sun Jul 10 2022 07:23:47,29 * "_id":"d4960668-a1f9-421b-99ed-974b632107c0",30 * "items": [31 * {32 * "_createdDate": Sun Jul 10 2022 07:23:47,33 * "_id": "229265c7-0f61-45ve-b433-791nncadf4c5",34 * "_updatedDate": Sun Jul 10 2022 07:23:47,35 * "description": "This is the first item in my gallery.",36 * "sortOrder": 1657439075188,37 * "title": "Item 1",38 * "type": "IMAGE",39 * "image": {40 * "imageInfo": "wix:image://v1/38939f9568z222d6avc6285c9ac1e9129.jpg/38939f9568z222d6avc6285c9ac1e9129.jpg#originWidth=200&originHeight=199"41 * }42 * },43 * {44 * "_createdDate": Sun Jul 10 2022 07:29:27,45 * "_id": "4507a07b-ab93-4326-a222-6d0bd8da0625",46 * "_updatedDate": Sun Jul 10 2022 07:29:27,47 * "description": "This is the second item in my gallery.",48 * "sortOrder": 1857439076244,49 * "title": "Item 2",50 * "type": "IMAGE",51 * "image": {52 * "imageInfo": "wix:image://v1/25139f9568b74d8aac6286c9ac1e8186.jpg/25139f9568b74d8aac6286c9ac1e8186.jpg#originWidth=4000&originHeight=2667"53 * }54 * }],55 * "name": "My New Gallery",56 * "sortOrder": "1098567432267",57 * "totalItems": 258 * }59 * }60 */