Authentication in Vue using Laravel Sanctum

  Рет қаралды 72,351

Andrew Schmelyun

Andrew Schmelyun

Күн бұрын

Пікірлер: 101
@aschmelyun
@aschmelyun 4 жыл бұрын
If you'd like to see the full source code behind this video, you can check it out on my GitHub here: github.com/aschmelyun/video-auth-vue-laravel-sanctum
@moranilt
@moranilt 4 жыл бұрын
$request->user()->secrets isn't working. 500 ERROR is always response. But Secrets::all() is working good. Any ideas how to fix?
@claudio-emmanuel
@claudio-emmanuel 3 жыл бұрын
Hi Andrew, what are your IDE's theme and font settings? and which IDE are you using?
@bruttavoglia
@bruttavoglia 3 жыл бұрын
Hi Andrew! I want to implement even registration from Vue, if I'm not wrong it's just move the user creation process from UserFactory to Register.vue component right?
@mihoteo
@mihoteo 3 жыл бұрын
@@moranilt I would like to know too.
@danishirfanshah5770
@danishirfanshah5770 2 жыл бұрын
@@moranilt hey, did you get the answer. i also have same problem
@ademtepe2855
@ademtepe2855 3 жыл бұрын
One of the fullest 23 mins of my life, thank you for making such a clear and concise video. (Well, it's 23 mins but actually I watched, applied and worked on this video and subject all day.)
@aschmelyun
@aschmelyun 3 жыл бұрын
Thank you so much! That means a lot to me, I'm glad you enjoyed the video!
@DarylLegion
@DarylLegion 4 жыл бұрын
Your tutorials are well explained. Please make a series of this Laravel Vue + Sanctum
@ademtepe2855
@ademtepe2855 3 жыл бұрын
I would appreciate that too. A simple but full app example would be great!
@dawidwinkler3854
@dawidwinkler3854 3 жыл бұрын
I don't get it. As already someone mentioned, the XSRF-Token already exists without /sanctum/csrf-cookie, wo why do we call that? And it says, that after a successful login I can call any other api routes, yes, of course, couse there is no auth:sanctum middleware in your secrets api call, so i can call that through postman too.
@shamscorner
@shamscorner 4 жыл бұрын
Man!!! The video quality is A+
@icekalang3598
@icekalang3598 2 жыл бұрын
what happens when you accidentally refresh the page?
@Tyche.Crypto
@Tyche.Crypto 4 жыл бұрын
Would you please make a video about protecting the routes with the sanctum, and how to refresh or expire the token.
@aschmelyun
@aschmelyun 4 жыл бұрын
Sure! I will add it to my list.
@tysonadeyemi3726
@tysonadeyemi3726 3 жыл бұрын
I was wondering if Sanctum can be used for a Multi guard set up such as Admin, Customer and Vendor type of setup
@kennyteoh4409
@kennyteoh4409 3 жыл бұрын
Hi, isn't your "api/secrets" api path been expose to frontend. Where anyone can use postman to call the "api/secrets" without authenticate?
@FilipBekic01
@FilipBekic01 4 жыл бұрын
Why do we do GET /sanctum/csrf-cookie if we already have XSRF-TOKEN in our cookies?
@sevolaiser
@sevolaiser 4 жыл бұрын
If I try to retrieve the user secrets I get the error that there is no User on the request. I dont know why he is telling me im not logged in after entering the right credentials. What could be the problem?
@AllanVigiano
@AllanVigiano 4 жыл бұрын
same problem here... I have a git clone and then composer update, npm install and php artisan migrate (plus factories). So strange!
@marcuu5
@marcuu5 3 жыл бұрын
Is it possible to use the Laravel ui auth forms and laravel sanctum or do you have to write your own login form?
@MrEdSaints
@MrEdSaints 2 жыл бұрын
It would be amazing if you could make an updated version of this ..
@JJ-ot3ps
@JJ-ot3ps 2 жыл бұрын
is this one the same as laravel breeze that comes with vue? and maybe add vite ?
@someone-jq3lc
@someone-jq3lc 4 жыл бұрын
what font family you are using in your editor?
@digitaluniverse9826
@digitaluniverse9826 3 жыл бұрын
Andrew how do we logout with this cookie stuff?
@sukatuabdullahithedevissa4454
@sukatuabdullahithedevissa4454 2 жыл бұрын
Thank you very much for a beautiful short and detailed tutorial.
@Cybersix6666
@Cybersix6666 4 жыл бұрын
Great video... would you make a video on how to deploy this into a live server ? I dont seem to be able to find one ... thanks
@claudio-emmanuel
@claudio-emmanuel 3 жыл бұрын
Hi Andrew, what are your IDE's theme and font settings? and which IDE are you using?
@Ahmed-157
@Ahmed-157 2 жыл бұрын
This was a perfectly made tutorial! Do you plan to make more Vue and Laravel tutorials?
@КириллБелоусов-ы5е
@КириллБелоусов-ы5е 3 жыл бұрын
in which folder is the admin panel created? in client project or inside laravel project?
@anbuselvanrocky
@anbuselvanrocky 4 жыл бұрын
What are the code extensions and configurations you are using?
@dgloria
@dgloria 4 жыл бұрын
My problem with this that my api is not protected from third party if I call myApp/public/api/secrets page. So that would be a security issue. How would you do that? Eg. in postman you aren't able to access the api only if I provide you an access bearer token. One little addition, when you make a video, please keep bottom 3% free from content, I can't see your terminal commands of the youtube progress bar correctly when pausing the video. Thank you.
@redonechkernit5510
@redonechkernit5510 3 жыл бұрын
Thank you about this video. How i can check if user authenticated ?
@softwareEngineerKunwar
@softwareEngineerKunwar 3 жыл бұрын
Great tutorial. The description is clear and to the point. Would you mind to make full new video for laravel 8 vue3 + sanctum rest api full stack? Thanks in advance.
@henriqueferr8623
@henriqueferr8623 4 жыл бұрын
I'm having a problem at 20:20. When i go into 'localhost:8000/api/secrets' it says that i'm "trying to get property 'secrets' of non-object". When I try only to return $request->user() it shows nothing. I'm using Laravel 8
@beehive219
@beehive219 4 жыл бұрын
Make sure you added your domain (for me, using Valet, It's 'spa.test') to the 'stateful' option in config/sanctum.php :)
@drsolace
@drsolace 4 жыл бұрын
@@beehive219 Thanks Lars!
@mihoteo
@mihoteo 3 жыл бұрын
@@beehive219 Doesnt work for me. It still shows non-object instead of data :/
@Simone-ft2cg
@Simone-ft2cg 4 жыл бұрын
Hi, Thanks for this video! I need to make a PUT api Route to modify the product in the cart. Can I just write the route in api.php or I need Laravel Sanctum?
@thomaspotterdotexe
@thomaspotterdotexe 3 жыл бұрын
Did you know what vscode extension to install to make showing the identifier, like that 'table' and 'column' in migration file? thanks!
@aschmelyun
@aschmelyun 3 жыл бұрын
Hey Thomas! I believe for this video, I used the PHP Intelephense plugin: marketplace.visualstudio.com/items?itemName=bmewburn.vscode-intelephense-client
@thomaspotterdotexe
@thomaspotterdotexe 3 жыл бұрын
@@aschmelyun oh, I use that too but it doesn't showing like that ("table", "column", etc) idk why :'(
@jerickcarlosmangalus6856
@jerickcarlosmangalus6856 3 жыл бұрын
i'm having problems with laravel santum its very slow in response when i use sails in docker ? any idea how to fix this ?
@lloparyllopary
@lloparyllopary 3 жыл бұрын
which code editor do you use? And if it is vscode which extensions do you have?
@aschmelyun
@aschmelyun 3 жыл бұрын
I'm using PHPStorm with the Material UI Theme plugin set to the Atom One Dark color scheme!
@lloparyllopary
@lloparyllopary 3 жыл бұрын
@@aschmelyun thanks!!
@Vtivo
@Vtivo 4 жыл бұрын
Thanks for the course, hoping to understand Sanctum more... @5:25 In Tinker when I run: App\User::with('secrets')->get(); I get the following error: PHP Error: Call to a member function addEagerConstraints() on null in /Users/[username]/Sites/sanctum/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php on line 578 Can you help?
@Vtivo
@Vtivo 4 жыл бұрын
My follow along version uses Laravel Framework 7.25.0. App\Secret::with('user')->get() works. I downloaded & setup your repo (Laravel Framework 7.9.2) both tinker queries worked fine, has anything changed on the newer version of Laravel?
@aschmelyun
@aschmelyun 4 жыл бұрын
Hey Dino! Check your User.php model, where you're defining the public function secrets() method and make sure that there's a return statement. You should have something like: public function secrets() { return $this->hasMany('App\Secret'); }
@kosticnemanja1914
@kosticnemanja1914 4 жыл бұрын
Work through the Controller, not through the Tinker... App\Secret::with('user')->get(); WORKING App\User::with('secrets')->get(); NOT WORKING ?? HELP Illuminate/Database/Eloquent/RealationNotFoundException with message 'Call to undefined realationship [secrets] on model [App/User]
@alexandriv2174
@alexandriv2174 3 жыл бұрын
what is it dcr?
@raufhashimov241
@raufhashimov241 4 жыл бұрын
Thanks man youre channel best for anyone whos learning laravel.If you also will show auth laravel sanctum with react that's will be great.And try to show every example using react because developers usually use react.
@nirajgautam403
@nirajgautam403 3 жыл бұрын
lets say im at dashboard , and im making axios call to get user which is protected with auth:sanctum middleware , do i have to send the token manually through my axios call or it will work just fine
@aschmelyun
@aschmelyun 3 жыл бұрын
As long as it's coming from the same domain name, you shouldn't have to include the token at all. You may need to add withCredentials: true to your axios initialization though.
@stanislavkacmarik6210
@stanislavkacmarik6210 4 жыл бұрын
Why is this much better option then tymon/jwt-auth? Is it more secure? Or does sanctum solve some problems that are in tymon/jwt-auth? Or is it just easier to setup?
@aschmelyun
@aschmelyun 4 жыл бұрын
It works similarly behind the scenes for API tokens, but also does a lot of authentication setup automatically when combined with frontend JavaScript calls. It’s also an official Laravel repository, meaning that it will be updated consistently as the framework is!
@richardwheatley7194
@richardwheatley7194 4 жыл бұрын
I was building on valet and failed to pick up domain config, but otherwise a great tutorial in both content and delivery.
@SussanRai
@SussanRai 4 жыл бұрын
How can i get auth user in public api using scantum
@Venezuelangel
@Venezuelangel 3 жыл бұрын
I'm sorry for being lost, but what password are you using to log in to your dummy users (it's hashed in the DB, of course).
@SabinMehedin
@SabinMehedin 3 жыл бұрын
Hi! The password is password. In your factory file can see a comment near the hash: // password :)
@stefantatic4836
@stefantatic4836 4 жыл бұрын
Hi, Andrew, awesome video. Regarding the last example, I assume it's easier and more robust to use the auth:sanctum (instead of the default auth:api) middleware on protected routes? This way it'll throw a 401 (unauthenicated) and for some routes 403 (unauthorized) error which is clearer than "general" 500 (internal server error). Of course, the biggest plus you get is that you can set this middleware on your controller's constructor/chain it in the routes file instead of performing the checks for each controller's method. Am I right to point this out? Another comment: is there something that can be done to handle redirection of your Vue frontend in the same way Laravel does it out of the box for back-end served apps? I'm specifically thinking (but you might add something as well) about RedirectIfAuthenticated middleware which prevents signed-in users from reaching e.g. Login/Register pages. How can this be tackled for your Vue front end app? Thanks again for this great tutorial, I subscribed and hope to see more cool videos from you. Keep up!
@stefantatic4836
@stefantatic4836 4 жыл бұрын
Also, the thing I'm baffled for the last 3 days: how do you handle the (authenticated) User object? E.g: you want your navbar to have the user options on top or login/register if no one's signed in and of course have this updated on login/logout. Do you keep the object on the root instance and have all your other components (e.g. mentioned top navbar, but also sidebar which can show different options to admin/regular user/guest user) update on this change or... Let me know if you need me to explain it a bit more, I hope you get my question. I am somewhat experienced with Laravel, but I'm pretty new to Vue and I'm currently building my first SPA so it's a fun journey. 😃
@orlandoubilla7055
@orlandoubilla7055 4 жыл бұрын
Hi! if your .env file have the var SANCTUM_STATEFUL_DOMAINS and using localhost over some port (like 8080) , add it too. SANCTUM_STATEFUL_DOMAINS=localhost:8080 Regards.-
@DavixeTheBoss
@DavixeTheBoss 4 жыл бұрын
@@stefantatic4836 For this kind of use cases, i think the best is to use Vuex
@maulik1644
@maulik1644 4 жыл бұрын
Which IDE are you using??🤔 Is that php Strom??
@aschmelyun
@aschmelyun 4 жыл бұрын
Yes! It's using the Material Theme UI with Firacode as the font.
@wojciech-koziol
@wojciech-koziol 4 жыл бұрын
Hi, great tutorial but I've got problem with login in. When I do axios.post on route /login I've got error: errors: {email: ["These credentials do not match our records."]} message: "The given data was invalid." I've checked up several times and inputed data is correct.
@wojciech-koziol
@wojciech-koziol 4 жыл бұрын
Okey, I solved the problem. I just created manually user.
@hanimajebry4970
@hanimajebry4970 4 жыл бұрын
13:30 , you could've used `form-group` class
@robbichandra6279
@robbichandra6279 3 жыл бұрын
Can you do full tutorial please
@aschmelyun
@aschmelyun 3 жыл бұрын
It's on my to-do list! Keep an eye out for future videos!
@ronnelsuan5846
@ronnelsuan5846 4 жыл бұрын
Hi i have vue login page. and i just want to implement sanctum on may login. it should i need secret or not ?
@ronnelsuan5846
@ronnelsuan5846 4 жыл бұрын
if it's okay my login is vue only then after i logged in its typical laravel blade templating?
@ronnelsuan5846
@ronnelsuan5846 4 жыл бұрын
what's the use of personal token access in sanctum ?
@kushtra24
@kushtra24 4 жыл бұрын
Does this work for laravel 8?
@nirmaldangi877
@nirmaldangi877 4 жыл бұрын
I have problem in using laravel8
@michaelerwin8744
@michaelerwin8744 4 жыл бұрын
Since this relies on cookies for security, how does mobile app integration work using same API?
@aschmelyun
@aschmelyun 4 жыл бұрын
If you check out the Laravel Sanctum documentation, there's a whole section about using bearer tokens as authentication. You can pass them through as an Authorization header to your API requests!
4 жыл бұрын
Hello there! I try this with Laravel 8, and I'm blocked by this error: "localhost:8000/login 404 (Not Found)" What could be the problem?
@moranilt
@moranilt 4 жыл бұрын
Hi. Just try to read laravel.com/docs/8.x/sanctum There are some differences between v7 and v8 of Laravel. YOu don't need to install laravel/ui. Instead you should use laravel/jetstream
4 жыл бұрын
@@moranilt Yep, thank you very much, I realized by now that 8 is different in that field... so I started a new project installing Jetstream, now I'm configuring my Vue app to handle the login/logout requests, check if someone is authenticated, etc...
@guillercelestino801
@guillercelestino801 4 жыл бұрын
Can please add on how to refresh the token.
@aschmelyun
@aschmelyun 4 жыл бұрын
Sure thing! I'll add this to my list of upcoming videos, keep an eye out!
@rosesolution2435
@rosesolution2435 3 жыл бұрын
Can't see the commands
@FilipBekic01
@FilipBekic01 4 жыл бұрын
I've thinking about Sanctum and.. if you use just a simple authorization system, why do you even need Sanctum? Can't you just authorize normaly vie axios request? Sanctum may be useful only issuing API tokens which you do not do in the video.
@aaronmeder
@aaronmeder 4 жыл бұрын
Thanks, great overview!
@JohnnyBigodes
@JohnnyBigodes 4 жыл бұрын
Awesome as always.... Thank you
@ahmadabuaysheh
@ahmadabuaysheh 4 жыл бұрын
Really clear and amazing video. Thank you!
@SergeySSD
@SergeySSD 3 жыл бұрын
work with token match easy and better if need full cross domain
@neomn110
@neomn110 2 жыл бұрын
13:55
@Lumaport
@Lumaport 4 жыл бұрын
Awesome video thank you
@Sub_Boi
@Sub_Boi 10 ай бұрын
Thank you
@igorthierry
@igorthierry 3 жыл бұрын
if you want to make requests for api routes from a web page SESSION_DRIVER=cookie SESSION_DOMAIN=localhost SANCTUM_STATEFUL_DOMAINS=localhost:8000
@eisa343s
@eisa343s 4 жыл бұрын
Thanks.
@akiaksandrpapilau932
@akiaksandrpapilau932 4 жыл бұрын
artisan make:controller SicretController - makes a new blank class with the name SicretController, it is so useful, i do not even know how i would live without this help, lmao, every day i get more and more disappointed about this framework, also you tutorial is not relevant alredy for the 8th version. f**k do these guys have anything permanent?
@franzkafka9734
@franzkafka9734 3 жыл бұрын
Русскоговорящим ку У кого его метод не работает пишите: App\Models\User::factory()->create();
@mihaylov13
@mihaylov13 3 жыл бұрын
Тода Андрей
@joshuaabejero9592
@joshuaabejero9592 2 жыл бұрын
OMG I almost run go back to ExpressJS! You saved me a lot of trouble. Now I can access the AUTH User using $request-user()->id.
@SquarCoX
@SquarCoX 4 жыл бұрын
How do i check in each component if the user is authenticated??
@DavixeTheBoss
@DavixeTheBoss 4 жыл бұрын
The best option for this, in my opinion, is to save the user data in a global, eg: Vuex, check if the user is authenticated or not before accessing any route within the Vue Router and this way you could define which components could the user access or not.
Laravel SPA Authentication - setup and common mistakes
16:55
You don't need a frontend framework
15:45
Andrew Schmelyun
Рет қаралды 136 М.
So Cute 🥰 who is better?
00:15
dednahype
Рет қаралды 19 МЛН
I built the same app 10 times // Which JS Framework is best?
21:58
Fireship
Рет қаралды 2,6 МЛН
Populating Google Maps with Vue and Laravel
25:17
Andrew Schmelyun
Рет қаралды 23 М.
5 tips for supercharged Laravel Eloquent queries
16:29
Andrew Schmelyun
Рет қаралды 68 М.
PHP is the future
34:27
Aaron Francis
Рет қаралды 183 М.
Build a shopping cart with Laravel Cashier and Vue
55:07
Andrew Schmelyun
Рет қаралды 48 М.
Laravel SPA Auth different domains
10:51
cdruc
Рет қаралды 9 М.
I built an app using a single index.php file, here's how it went
32:42
Andrew Schmelyun
Рет қаралды 92 М.
Laravel Sanctum SPA Auth Overview
13:34
cdruc
Рет қаралды 11 М.
Caleb Porzio "Livewire 3" - Laracon US 2023 Nashville
43:28