How long should I set the expiration date for a cookie storing an auth token?

0
8
Asked By CuriousCoder92 On

I'm developing a browser app that allows users to stay signed in on the login screen by storing an authentication token in a cookie. However, I know I can't make this cookie last indefinitely due to security risks. Currently, I've set the expiration to 2 weeks, but I'm curious to hear what others recommend as a reasonable duration for this kind of cookie.

3 Answers

Answered By TechWhiz88 On

For security purposes, it's best to keep the login session cookie short-lived. However, you can refresh its expiration whenever the user interacts with the app—kind of like resetting an idle timer. This way, as long as they're active, they can stay signed in securely.

Answered By CodeMaster21 On

What I usually do is set the auth token to expire in 15 minutes, while the refresh token is set for 30 days. This way, users can stay signed in without compromising security.

Answered By DevGuru33 On

It really depends on your setup. If the token is standalone and isn't backed by any session validation on the server side, you might want to keep the cookie short-lived. A common approach is using an auth token paired with a refresh token. Since your token holds user details, ensure it aligns with your session management to ensure a good balance between usability and security.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.