Jwt-auth: JWT Default Expiry and Increasing TTL

Created on 4 Feb 2016  路  4Comments  路  Source: tymondesigns/jwt-auth

I have installed jwt-auth in my Laravel 5.1. Couple of questions if someone can help please:

1) What is the default expiry time for a new token that is generated after login? Is it 1 hours, 1/2 hour or 15 mins?

2) How do I change the expiry time for the token when they are generated? Say, if I want to increase the token validity to 24 hours from the time they login?

At the moment, the tokens are created like this:

public function login(Request $request)
        {
            $credentials = $request->only('username', 'password');

            try {
                // verify the credentials and create a token for the user
                if (! $token = JWTAuth::attempt($credentials)) {
                    return response()->json(['error' => 'Invalid Login Credentials'], 401);
                }
            } catch (JWTException $e) {
                // something went wrong
                return response()->json(['error' => 'Could Not Create Token'], 500);
            }

            // if no errors are encountered we can return a JWT
            return response()->json(compact('token'));
        }

Most helpful comment

The default is 60 minutes and it should be in your config/jwt.php file under the ttl option. 1440 minutes is one day so if you change it to that, users will have a valid token for up to a day.

All 4 comments

The default is 60 minutes and it should be in your config/jwt.php file under the ttl option. 1440 minutes is one day so if you change it to that, users will have a valid token for up to a day.

Fantastic. Thank you so much Jeremy for pointing that out. It helps heaps! Cheers!

You're welcome :>

Very thanks @w0rd-driven for this, really i spent 2-3 hours to set token expiry. its was only set in jwt.php file.

Thanks
Rohit

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lbottoni picture lbottoni  路  3Comments

lloy0076 picture lloy0076  路  3Comments

agneshoving picture agneshoving  路  3Comments

marciomansur picture marciomansur  路  3Comments

heroghost picture heroghost  路  3Comments