I am trying to call a function and use the value from that function to the global variable. The problem is value is not going outside. I am kinda not so good in javascript. I don't know if i wrote the function correctly.
async function leader(platformName){
let fullUrl = getUrlPrefix(platformName) + "createsessionjson/" + devKey + "/" + sig('createsession') + "/" + timestamp;
const response = await fetch(fullUrl, { method: 'GET' });
const json = await response.json();
console.log(json);
console.log(json.session_id);
return (json.session_id);
}
var session1 = '';
export async function leaderboard (platformName) {
var session = await leader(platformName);
console.log("Session" + ":" + " " + session);
session1 = session;
}
export function leaderboardsession (platformName) {
console.log("Global session" + ":" + " " + session1);
let fullUrl1 = getUrlPrefix(platformName) + "getleagueleaderboardjson/" + devKey + "/" + sig('getleagueleaderboard') + "/" + session1 + "/" + timestamp + "/" + 428 + "/" + 27 + "/" + 2;
console.log("this is inner url ->" + "\n" + fullUrl1);
return (fetch(fullUrl1, { method: 'GET' }))
.then(function (response) {
return response.json();
});
}
Here the global session is empty. I want to call leaderboard() one time, store the session in global session variable and use the global session in leaderboardsession() [as many time i call leaderboardsession()].
How do i store that ?