Hi everyone,
Sorry, but this still does not work. The app will ask me to allow access every single time, it is as if the local storage does not exist. My client is upset about this because they say it is very slow since it requires them to either log in or at least "allow" permissions every single time they load the app.
Here is my code. Do you see anything wrong with it? If not, is it possible that the localstorage isn't working for some reason?
pre
function doLogin () {
Code: Select all
if (localStorage.getItem("access_token")) {
Appery.navigateTo('HotOppsList', {reverse: false});
}
else {
// as we render all pages into one file, let's check if this is a callback
if (window.location.href.indexOf("access_token") == -1) {
var client_id = SF_Settings['client_id'];
var redirect_url = SF_Settings['redirect_url'];
var login_url = SF_Settings['login_url'];
var url = login_url + "?response_type=token&display=touch&display=touch&client_id=" +
client_id + "&redirect_uri=" + encodeURI(redirect_url);
// let's go to Salesforce to login
window.open(url, "_self");
}
else { // yes, this is a callback
// save token, url into local storag
saveAuthCodeInLocalStorage();
// navigate to HotOpps page
Appery.navigateTo('HotOppsList', {reverse: false});
}
}
}
function saveAuthCodeInLocalStorage () {
Code: Select all
var url_params = [];
var params = window.location.href.slice(window.location.href.indexOf('#')+1);
params = params.split('&');
for (var i in params) {
var item = params[i].split('=');
url_params[item[0]] = item[1];
// find the ID for the current user
if(i == 2) {
var sUserID = item[1].substr(item[1].length - 18);
localStorage.setItem('user_id', sUserID);
}
}
// save token with type: Bearer
localStorage.setItem('access_token', 'Bearer ' + decodeURI(url_params.access_token));
// save service URL, needed to invoke services
localStorage.setItem('instance_url', decodeURIComponent(url_params.instance_url));
// clear the token from URL
//window.location.replace(SF_Settings['redirect_url']+"#");
}
/pre