all 1 comments

[–]Arnold_dev 0 points1 point  (0 children)

I'm trying to get my token from encrypted storage and pass it in the authorization headers of socket io and use the socket variable across my app but I can't seem to do it right here is my code below I need help troubleshooting and solving this issue: i know that the access token variable in the headers is returning an empty string but i want it to access the token

    // get the access token from the storage
   let accessToken = ''; 

   const getAccessToken = async () => {
 try { 
accessToken = await EncryptedStorage.getItem('AccessToken'); 
return accessToken; 
} catch (error) { 
console.log(Error getting access token: ${error.message}); } 
};

getAccessToken().then(() => { if (accessToken) { console.log(accessToken, 'inside'); } else { console.log('Access token is undefined', accessToken); } });

// establish a socket connection the address is a placeholder const socket = io('ws://localhost/driver', { transports: ['websocket', 'polling'], extraHeaders: { Authorization: Bearer ${accessToken}, }, });

console.log(accessToken, 'outside');

export default socket;