Pricing Blog

What do you use for refresh session?

  • uunicode-1367461847892099214

    unicodes

    3 months ago

    As it is now I have the login session very long (1day), I want to implement the refresh token system for providing a continuity experience.

    I was thinking to add for each API a check if the error is 401 then refresh the token if isn't expired and if the refresh is success then recall the API. This solution is very annoying because I have to implement this refresh token for every single API and in some cases is huge (considering components, context callings etc.).

    I was thinking to create a listener if something in network fails with 401 to refresh token.

    Another solution would be to refresh the token every X time or in case of 401 to redirect to login (I want to avoid because in some cases you work on something and on pressing "save", you will be redirected to login and lose everything)

    I'm curious what do you use, have you found something very simple to implement?
  • jonathanfors-1367533252088299530

    Jonathan Fors

    3 months ago

    In my case the session lasts 1 hour and a formula to check if it was issued more than 45 minutes ago. If true it refreshes the token (and retries every 5 minutes if it fails). Probably might extend that to more than an hour though
  • uunicode-1367730015684530248

    unicodes

    2 months ago

    Thank you Jonathan, is a great solution!
  • building_stuff-1367817067058958367

    Janis

    2 months ago

    How are you storing the token, I assume you’re using Supabase?
  • jonathanfors-1367829171308593223

    Jonathan Fors

    2 months ago

    The auth/access token? In an http-only cookie