Authenticate with Session Storage

Asked

Viewed 224 times

0

I have a login screen, where if the user logs in a Sesssion Log with the necessary information, I also saw how I can read this saved information, but how do I open a page through the URL to check if the Sesame Log has been saved, If this is OK, open the page, or redirect to another. I am using Html5, javascritp, css, in this application I can not use a language Clint server, type PHP, ASP NET or other, I have to work exclusively on the client side, always consuming the webservice using ajax.

Thank you

  • I think it’s a case of using Oauth or Json Web Token, man. I don’t know if it would be safe to save user information in Session Storage...

1 answer

0


If login is correct, create a Session in your login page script

sessionStorage.setItem('Intelider', 'Sistemas');

Now just test if the session has expired on the protected pages:

  //recupera a session    
  var data = sessionStorage.getItem('Intelider');

  if (data == null){
     //exemplo
      window.location.href = 'suaPaginaDeLogin.html'; 
  }
  • Thanks @Leo Caracciolo, it worked perfect, thank you

Browser other questions tagged

You are not signed in. Login or sign up in order to post.