PricingBlog

Clear Session Storage question

  • patrickmast-1264275674391249107

    Patrick Mast

    1 year ago

    I'm building a web app that requires login authentication through Xano. When authorization succeeds, I store the token via "Set Session Cookies". This way, when I load the app, I can check if the user is authorized by calling an auth API to Xano. There's no need to pass a token manually, as the API call retrieves the token from the saved session. It works great!

    Now, I have a menu item "Log Out". What I do here is clear the session storage. I expected that, the next time I call the Auth API to Xano, it would fail because there would be no token in the session storage. However, that's not the case. Even after clearing the session storage, authorization to Xano still works.

    Is this the correct way to "clear" the saved token?

    This is the API call for the authorization:
    1264275674546311330-image.png
  • max.kayr-1264292895414812763

    Max

    1 year ago

    Hi Patrick! The auth information is stored in a cookie. Cookies are not part of the session storage. So if you clear the session storage, you won't loose the auth info. To be honest, I never did that in Toddle, because our backend has a "logout" endpoint that invalidates the session. As far as I know, Xano cannot do that. So I would set the session cookie to Null. That should remove the cookie
  • patrickmast-1264450009500221570

    Patrick Mast

    1 year ago

    Hey Max! Thanks for the pointers. Shouldn't the "Clear Session Storage" do just that?
  • max.kayr-1264474596522856530

    Max

    1 year ago

    No. The session storage is not the storage for cookies. When you clear the session storage, the cookies remain untouched
  • patrickmast-1264477866700181566

    Patrick Mast

    1 year ago

    Ok, thanks! So, what exactly does "Clear Session Storage" do? 🙂
  • max.kayr-1264480502107213834

    Max

    1 year ago

    Well, it clears the session storage 😅. There are three main types of storage you can access in Toddle (and JS): Cookies (permanent with optional aging, for tokens and identifiers mainly), Session Storage (volatile, is cleared when the browser is closed or refreshed), and Local Storage (permanent). Local storage is useful, for example, for storing local config (light/dark mode, language, preferred layout...). Session storage can be used for information that is relevant for the current session but does not need to be stored permanently (e.g., the visited screens, recently opened stuff...). When you store info in session storage ("Save to Session Storage"), this data can be cleared with the "Clear Session Storage" command.
  • patrickmast-1264610496821203074

    Patrick Mast

    1 year ago

    Okay, starting to understand! Thanks, @Max !
  • samuelt_19895-1275754548111081504

    Samuel T

    1 year ago

    @Max I think I'm having a similar issue. That means setting logout button to clear session storage and redirect means that clicking the back button in the browser should not load ex. the dashboard that you were just on right?
  • max.kayr-1275755902506369133

    Max

    1 year ago

    I think that depends on your browser. Different browsers cache the previously loaded pages. But clearing the session storage won't log you out
  • samuelt_19895-1275756059847295049

    Samuel T

    1 year ago

    Ok any way to ensure that the button actually logs you out?
  • max.kayr-1275766676893208668

    Max

    1 year ago

    A little higher up 😊
    1275766676763312150-IMG_0431.png
    🙏1
  • samuelt_19895-1276527622607601787

    Samuel T

    1 year ago

    @Max Tried not to ask, but can you help me with steps for that? 🙂
  • max.kayr-1276545941696155773

    Max

    1 year ago

    Sure 😄
  • samuelt_19895-1276549603491188767

    Samuel T

    1 year ago

    Thank you 🙂
  • lucasg-1276555818677964966

    Lucas G

    1 year ago

    The simples option is to link to /.toddle/logout
  • Can also manually clear tokens and/or set expiration to 0
  • samuelt_19895-1276648036294197311

    Samuel T

    1 year ago

    @Lucas G but just linking to the logout page does not actually log you out right? Cos it’s just another page - or am i missing something?
  • lucasg-1276648345347162153

    Lucas G

    1 year ago

    the toddle logout endpoint is not a page, it sets the expiration to 0 and then redirects to '/' (home)
  • So it effectively logs a user out
  • samuelt_19895-1276648817516744786

    Samuel T

    1 year ago

    Oh I see, thanks a lot @Lucas G I’ll give it a try
  • alexsiale_17363-1276692892471005294

    Alex

    1 year ago

    This worked for me
  • samuelt_19895-1277308475780759643

    Samuel T

    1 year ago

    I think this worked for me too, thanks! Is there a way to get ot to redirect to another page? Like /login instead of home?