This question already has an answer here:

I want to read the cookies out of the DOM document object. I tried the following:


init : function(component, event, helper) {
     console.log(document.cookie); // returns nothing


afterRender : function(component, helper) {
    console.log(document.cookie); // returns nothing

I want to read the Salesforce session id out of the cookies. I also tried to get the session id via apex:

public static string requestSession() {
    return UserInfo.getSessionId();

But I can not use the returned id for REST API calls. But the sid in the cookies works for REST API.


marked as duplicate by sfdcfox lightning-components Dec 4 '18 at 16:49

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


You should be able to read the SecureDocument.cookie attribute Locker Service document.cookie support

But for your use case Salesforce recommends using Named Credentials to authenticate to Salesforce. https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/apex_api_calls.htm

Not the answer you're looking for? Browse other questions tagged or ask your own question.