Sunday, May 12, 2024
 Popular · Latest · Hot · Upcoming
35
rated 0 times [  42] [ 7]  / answers: 1 / hits: 5115  / 6 Years ago, mon, march 5, 2018, 12:00:00

First I'm setting the string value after user login in login.html page:



success:function(data){
if(res.IsSuccess){
localStorage.setItem(token,data.Response.AuthToken);
window.location.href=/dashboard.html;
}
} Once this is success it is redirecting to dashboard


On the dashboard page, I'm retrieving the value like this:



var Authtoken=localStorage.getItem(token)



How to check if the Authtoken value exists or not?



More explanation:



I'm storing the localStorage value from the server response, so in Serverend the authtoken expire time is 10min.




  1. Login page
    once the user click on RememberMe, at the time only I'm storing textbox values using localstorage to redirect to the dashboard next time without login(BrowserAction Icon click)


  2. Once I click the login button I'm storing the authtoken localStorage.setItem(token,data.Response.AuthToken);




If the dashboard based on localStorage value, how to check if it exists or not?


More From » jquery

 Answers
8

You can check it like to make sure you get something out of it



var token = localStorage.getItem(token)
var data = token && JSON.parse(token)

[#14818] Saturday, March 3, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
stacie

Total Points: 476
Total Questions: 92
Total Answers: 102

Location: Bosnia and Herzegovina
Member since Tue, Mar 29, 2022
2 Years ago
;