LWCIntermediateexperience-cloudsecurityerror-handling
Handle Experience Cloud member login session expiry in embedded LWC
Real World Scenario
Community member leaves tab open overnight. Morning Apex calls return 401 and LWC shows infinite spinner.
Expected Answer
• Detect 401 or SESSION_EXPIRED in imperative Apex catch block
• Redirect to community login with return URL encoded
• finally block always clears loading state
• Optional session heartbeat for long-running wizards
• Guest vs member session timeout differences in testing
• Toast explaining session expired not generic error
• Preserve draft form data in sessionStorage before redirect optional
Follow-Up Questions & Answers
Click to expand — each follow-up includes a direct, interview-ready answer
Direct answer: Detect 401 or SESSION_EXPIRED in imperative Apex catch block Also consider: Redirect to community login with return URL encoded In practice: finally block always clears loading state Balance speed of delivery with maintainability.
Architect Perspective
Session expiry is normal path—not edge case. Every imperative call needs 401 handling.