Note: You should have already learned about Web Modules before reading this article.
Web Module permissions allow you to control which users can work with functionality in your site that depends on your Web Module functions.
Setting Web Module permissions allows you to ensure that no one can access or use your backend code in ways that you didn't intend, either through your site's functionality or using a browser's developer tools.
The following example shows how backend functions with added permissions can only be called by certain types of site visitors.
This example was created using the following code:
Copy Code
import { helloAnyone, helloMember, helloAdmin } from 'backend/helloModule';$w.onReady(function () {$w('#anyoneButton').onClick(async () => {try{$w('#responseText').text = await helloAnyone();setupGoodResponse();}catch {$w('#errorText').text = 'Backend call failed. Are you sure you are an anyone?';setupBadResponse();}});$w('#memberButton').onClick(async () => {try{$w('#responseText').text = await helloMember();setupGoodResponse();}catch {$w('#errorText').text = 'Backend call failed. Are you logged in?';setupBadResponse();}});$w('#adminButton').onClick(async () => {try{$w('#responseText').text = await helloAdmin();setupGoodResponse();}catch {$w('#errorText').text = 'Backend call failed. Are you sure you\'re the admin?';setupBadResponse();}});});function setupGoodResponse() {$w('#errorText').hide();$w('#responseText').show();}function setupBadResponse() {$w('#errorText').show();$w('#responseText').hide();}
You can experiment with this example for yourself on our Hello Web Modules example page.
Note: By default, permissions are granted to Anyone for all the functions in your Web Module.