Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Salesforce
  3. Question
Salesforce

Failed to load resource: the server responded with a status of 401 (Unauthorized)

Asked by Andrew Jenkins Apr 23, 2021 9.0K views 1 answer
Share

About this question

I have Visualforce pages contains Lightning App, that contains Aura components hosted to Community aka Experience Builder, which are working fine when user is loggedIn, however, for guest users it is throwing "Failed to load resource: the server responded with a status of 401 (Unauthorized)"

for api.js and xdomain.js as shown in screenshot below.

enter image description here

Please find the below code for the VF page and controller class

 [removed] // Here 'VfApp' Is Lightning Application Name $Lightning.use("c:UserActionMenuApp", function () { $Lightning.createComponent("c:horizontalNav", { }, "horizontalNav", function (component) { console.log("component created"); }); }); [removed]  

Code for the Class file

public without sharing class CommunityUserDetailController { @AuraEnabled(cacheable=true) public static List getCurrentUser(){ System.debug('==getCurrentUser CALLED===>'); List users=new List(); if(UserInfo.getUserType()!='Guest'){ users= [SELECT Id, Name, profile.Name,SmallPhotourl,FullPhotoUrl FROM User WHERE Id =: Userinfo.getUserId()]; } System.debug('==getCurrentUser users===>'+ users); return users; } }

Any help on this will be appreciated

Thanks

Your answer

1 Answer

More Salesforce discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Salesforce Blogs

Guides, tips and career advice on Salesforce from JanBask experts.