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.
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) app4 function(){5 // Callback once framework and app loaded6 $Lightning.createComponent(7 "c:storeLocatorMain", // top-level component of your app8{}, // attributes to set on the component when created9 "lightningLocator", // the DOM location to insert the component10 function(cmp){11 // callback when component is created and active on the page12},13);14},15 "https://universalcontainers.force.com/ourstores", // Site endpoint16);17</script>