In this tutorial, we will be using lumen; a super-fast micro-framework by laravel to build a simple and secure REST API. At the end of this tutoria...
For further actions, you may consider blocking this person and/or reporting abuse
getting this error after install jwt
php artisan jwt:secret
There are no commands defined in the "jwt" namespace.
Had the same issue.
following the docs here jwt-auth.readthedocs.io/en/develop...
especially the chapter Bootstrap file changes fixed the issue
Add the following snippet to the
bootstrap/app.php
file under the providers section as follows:Please check to make sure
tymon/jwt-auth
installed successfullyAlso type
php artisan
to see available commands.Keep me posted on your progress.
Side note: the command
jwt:secret
updates your .env file with something like JWT_SECRET=secretkeystring."It is the key that will be used to sign your tokens. How that happens exactly will depend on the algorithm that you choose to use."
now it's working. Thank you.
You are welcome
Hi Ndifreke,
can you explain how to publish jwt library also need to token expire time and refresh token. thank you in advance.
php artisan vendor:publish --provider="Tymon\JWTAuth\Providers\LaravelServiceProvider"
The above command publishes the JWTAuth Package. Here's this thing, the
vendor:publish
command is not available in lumen.You can try using third party packages to pull this in ( github.com/laravelista/lumen-vendo... )
For managing expiration time and refreshing tokens, this link should help out; jwt-auth.readthedocs.io/en/develop...
Hi Ndifreke,
Thanks for reply. one more thing I need if you help me. you have any example for lumen with vue also include in jwt token use.
you might want to also add
when you add
respondWithToken
toapp/Http/Controllers/Controller.php
(Lumin 6+)This is key.
I was followed step by step your tutorial, writing the code by myself (i mean, without clone your github project) and without this line (thanks @cleathley ) an error appears.
I think you should edit your post and add that line after you explain this:
«Add a global respondWithToken method to Controller class»
Anyway, great tutorial. It help me a lot!!
I'm glad it helped 👍
I will update the post, so new readers don't run into this same error.
This saved my life ty
Thanks For this, I will update the tutorial to help people not encounter this error in the future.
First of all great tutorial, thanks a lot for all your efforts dude, I've a question, how can I set a remember me system with JWT token ? And also, how to increase expiration duration from the config file (config/auth.php) ?
Would there be a need for remember me? As long as the client has the token; they have access to the system.
You could extend token's time to live for those type of users, that could work...I think.
Override the token ttl
$token = auth()->setTTL(7200)->attempt($credentials);
Further Reading
stackoverflow.com/questions/236038...
Thanks dude, I've another question please, if the token is stocked localy, then yo access protected area I've check the user token for that, if Auth::user() did the job, why we stock the token localy ?
For the second part of the question, the answer should be:
github.com/tymondesigns/jwt-auth/b...
Getting this error,
In Connection.php line 665:
SQLSTATE[HY000] [2002] Connection refused (SQL: create table
migrations
(id
int unsigned not null auto_increment primary key,migration
varchar(255) not null,batch
int notnull) default character set utf8mb4 collate 'utf8mb4_unicode_ci')
In Connector.php line 70:
SQLSTATE[HY000] [2002] Connection refused
Using Homestead development environment.
This error is due to PHP not being able to connect to MySQL
"Create a .env file, copy all contents in .env.example into the .env file and add your database configurations."
This was of great help. The only problem I encountered was when running
php artisan jwt:secret
.$app->register(Tymon\JWTAuth\Providers\LumenServiceProvider::class);
needs to be added to app.php before the command is executed.Hi,
Thanks for your great tutorial.
But I want a custom field (email and password) both so could you make it an example for that.
My field name = USER_NAME, PASSWORD (Both are capital)
I try but token always false.
If you do then its great help for me.
Thank you
Nice tutorial, very clear and straight to the point. My worry is why the dev-develope branch? The main branch, does it have an issue?
For some reason the dev-develop branch has always worked for new versions of lumen, the next best thing would be version @2.0-dev
Ok thanks. I tried using the default and it keeps failing and when i use dev-develop, it worked well.
Thanks again for the tutorial, nice, easy and straight to the point.
I come again with one question. If i log into different devices, eg 4 different clients and have 4 different tokens, will all 4 be valid simultaneously? If not, what will you suggest to be done to ensure multiple tokens are valid across different devices.
:)
Every Token Generated that is yet to expired is valid; So yes, a user can have multiple tokens across multiple devices.
everything except php artisan jwt::secret is work...
so, i write jwt key in .env by myself..
thank you, nice tutorial...
I've just reviewed and coded through. It worked wonderfully~~~
Thank you, very good tutorial
I am yet to come across this issue. Is there an open issue on github?
Wonderful Bro.. It really helped me to understand the concept.. Thank you..
Thanks for this article! Very straightforward and easy to understand : )
I'm glad it helped :)
Nice one!
Thanks!
Thanks for the tutorial, helps me a lot
Great post! You had save me!
how to do this when using mongodb?
Hy bro, thanks for the tutorial. I want to know how I implements logout
public function logout () {
Auth::logout();
return response()->json(['message' => 'Successfully logged out']);
}
Does the lumen version affect? I use lumen version 6
This was really helpful, man! Thanks very much.
What a great tutorial. Thank you very much!
You are welcome
can you go further this post by making role-based auth in lumen?
Please, can you explain how to reset the password of user?
Maybe this can help
stackoverflow.com/questions/373380...
getting this error when doing login request
"Method Illuminate\Auth\RequestGuard::attempt does not exist."
Any help ?
Sorry, my mistake who put config/auth.php that not in root directory
This has been an amazing tutorial , few bugs but were resolved :)-
thanks for sharing this great tutorial.
I had issue with ('model' => \App\User::class).
so I changed it to ('model' => \App\Models\User::class),
and it works now.