jwt-auth icon indicating copy to clipboard operation
jwt-auth copied to clipboard

Customizing TTL per user

Open aconital opened this issue 3 years ago • 4 comments

I've been trying to create custom TTL and expiry for tokens based on my user roles for example admin 24 hr and regular user 1 hour. Is that possible?

aconital avatar May 11 '21 17:05 aconital

@aconital Yes,just do this

$token = auth()->setTTL(7200)->attempt($credentials);

see the doc : https://jwt-auth.readthedocs.io/en/develop/auth-guard/

chuoke avatar May 13 '21 02:05 chuoke

@aconital Yes,just do this

$token = auth()->setTTL(7200)->attempt($credentials);

see the doc : https://jwt-auth.readthedocs.io/en/develop/auth-guard/

It's Not Working

dy7338 avatar Jan 30 '23 08:01 dy7338

@aconital @dy7338 Did you ever solve this? I have similar issue where the default TTL is always being applied when i specify a different TTL.

EmilChigu avatar Apr 03 '23 09:04 EmilChigu

@aconital @dy7338 Did you ever solve this? I have similar issue where the default TTL is always being applied when i specify a different TTL.

1.

I'm set .env like this JWT_TTL=4320 JWT_REFRESH_TTL=43200

then set Middleware like this $token = $this->auth->refresh (); return response ()->json ($token................) It can notify the mobile token to expire and return to the mobile new token.The server will only notify you once.

2.

You can get the new one by refreshing the token before it expires.

dy7338 avatar Apr 03 '23 10:04 dy7338