Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Kan20's avatar
Level 1

Laravel Sanctum token refresh

Hello, I recently started using Sanctum for API and I use the token based authentication. I have set token life to 60 minutes but I don't know how to manage token refreshing, because after 60 minutes the token becomes invalid and I cant determine the user which I want to generate new token - i get Unauthenticated response. I could just redirect client side to login page again but I do not want that - i want the refreshing to happen in the background. I could just set token life to 65 minutes and refresh the token after 60 min but I do not know if that is good practice and secure. Thanks!

0 likes
5 replies
Kan20's avatar
Level 1

@jlrdw well it seems they have the exact same issues as me. If I don't end up finding built in Sanctum way i will use the package

jlrdw's avatar

@Kan20 well either set a longer time or just have them sign in again. Humana Military does this exact thing, after X time you are logged out and have to login again. A new login is not that bad.

Kan20's avatar
Level 1

@jlrdw What if they are in the middle of some kind of operation and data is lost

jlrdw's avatar

@Kan20 The Humana site displays a popup letting you know you have a certain amount of time left.

Please or to participate in this conversation.