Failed To Load Resource: The Server Responded With A Status Of 401 (Unauthorised)
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 (Unauthorised)" 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; } }
Regarding the error - failed to load resource: the server responded with a status of 401 (unauthorised) Assuming that you are using form authentication and you are trying to get it before login. You can use the following in your web.config file inside .
It will make you files inside AngularJS folder available without login