Share Lightning Out (Beta) Apps with Unauthenticated Users

We recommend using Lightning Out 2.0 instead of Lightning Out (beta). Lightning Out 2.0 is a new generally available feature that completely replaces–and isn’t an extension of–Lightning Out (beta), which is still subject to Beta Service Terms. See How Lightning Out 2.0 Compares to Lightning Out (Beta).

Tip

To make your Lightning Out (beta) app available to users without requiring them to authenticate with Salesforce, add the ltng:allowGuestAccess interface. With this interface, you can build your app with Lightning web components, and deploy it anywhere and to anyone.

If a user is authenticated with the Lightning Out (beta) endpoint, you must set the session in $Lightning.use().

Note

Usage 

You can add a Lightning Out (beta) app with the ltng:allowGuestAccess interface to a Visualforce page and to a page hosted outside Salesforce.

  • Using Lightning Web Components for Visualforce, you can add your Lightning Out (beta) app to a Visualforce page, and then use that page in Salesforce Tabs + Visualforce sites. Then you can allow public access to that page.
  • Using Lightning Out (beta), you can deploy your app anywhere Lightning Out (beta) is supported—which is almost anywhere!

The ltng:allowGuestAccess interface is only usable in orgs that have Digital Experiences enabled, and your Lightning Out (beta) app is associated with all site endpoints that you’ve defined in your org.

When you make a Lightning Out (beta) app accessible to guest users by adding the ltng:allowGuestAccess interface, it’s available through every Experience Cloud site in your org, whether that site is enabled for public access or not. You can’t prevent it from being accessible via site URLs, and you can’t make it available for some sites but not others.

Important

Be careful about apps you open for guest access. Apps enabled for guest access bypass the object- and field-level security (FLS) you set for your site’s guest user profile. Components don’t automatically enforce CRUD and FLS in an Apex method when you reference or retrieve objects. The framework continues to display records and fields for which users don’t have CRUD access and FLS visibility. A mistake in code used in an app enabled for guest access can open your org’s data to the world.

Note

Example: Allow Guest Access to a Lightning Out (Beta) App 

Add the ltng:allowGuestAccess interface to your Lightning Out (beta) app.

1<aura:application access="GLOBAL" extends="ltng:outApp"
2    implements="ltng:allowGuestAccess">
3
4    <aura:dependency resource="c:storeLocatorMain"/>
5
6</aura:application>

You can only add the ltng:allowGuestAccess interface to the Lightning Out (beta) app, not to individual components.

Note

Next, add the Lightning Out (beta) JavaScript library to your page.

  • With Lightning Web Components for Visualforce, simply add the <apex:includeLightning /> tag anywhere on your page.

  • With Lightning Out (beta), add a <script> tag that references the library directly, using a site endpoint URL.

    1<script src="https://SITE_DOMAIN/SITE_URL/lightning/lightning.out.js"></script>

    For example: https://universalcontainers.force.com/ourstores/lightning/lightning.out.js

Finally, add the JavaScript code to load and activate your Lightning Out (beta) app. This code is standard Lightning Out (beta), with the important addition that you must use one of your org’s site URLs for the endpoint. The endpoint URL takes the form https://YOURSITEDOMAIN/SITEURL, as shown by https://universalcontainers.force.com/ourstores/ in this example.

1<script>
2  $Lightning.use(
3    "c:locatorApp", // name of the Lightning Out (beta) app
4    function () {
5      // Callback once framework and app loaded
6      $Lightning.createComponent(
7        "c:storeLocatorMain", // top-level component of your app
8        {}, // attributes to set on the component when created
9        "lightningLocator", // the DOM location to insert the component
10        function (cmp) {
11          // callback when component is created and active on the page
12        },
13      );
14    },
15    "https://universalcontainers.force.com/ourstores", // Site endpoint
16  );
17</script>

See Also