Laravel 11 - Auth Api - using sanctum ( Register, Login, Profile Data and Logout )

  Рет қаралды 5,480

Rubyvidhya Ammu

Ай бұрын

#laravel11 #laravel_tutorial #laravel_api
Hi All,
Sorry! I used error code 401 for validation. The code is wrong.
Validation error code - 422
Unauthorized error code - 401
please change it while coding

Пікірлер: 17
@MakeeJkee
@MakeeJkee 10 сағат бұрын
I even went to like it, it’s just my salvation, there is a bug in laravel 11 ->validate and this video saved me😍
@Foxine
@Foxine 15 күн бұрын
Thank you so much for this class! Thanks a lot! God bless you! Thank you!
@andreyp.5389
@andreyp.5389 Ай бұрын
Thanks a lot. Will fit for any level of developer :) I'm using laravel for 5-7 years but older versions mostly. I was surprised that 11th doesn't have scaffolded auth routes like it did before. From what I remember, previously you could just "php artisan make:auth" to have all needed auth routes
@suriyayash
@suriyayash Ай бұрын
nice one
@tintrinh6266
@tintrinh6266 Ай бұрын
How appreciate I have! That's great, thank you so much.
@arsyadfinan9189
@arsyadfinan9189 Күн бұрын
why when i try bearer is false not giving response unauthorized, but back to login route?
@pacogarcia225
@pacogarcia225 18 күн бұрын
Do you have the code uploaded to a repository in Github? Thanks for your effort.
@wildandvibe
@wildandvibe Күн бұрын
iam getting an error
@shubhamc4
@shubhamc4 Ай бұрын
On validation fail. You should return 422 validation http code instead of 401 which is for unauthorized access.
@rubyvidhyaammu4984
@rubyvidhyaammu4984 Ай бұрын
Thanks.... The error code detail was added in the description....
@DonLAtinop
@DonLAtinop Ай бұрын
Awesome video, thanks! btw , I am getting this in the profile link when the token is not right : Symfony\Component\Routing\Exception\RouteNotFoundException: Route [login] not defined. in file Any idea how to fix it?
@rubyvidhyaammu4984
@rubyvidhyaammu4984 Ай бұрын
The route is protected. Please add "Accept"=>"application/json" in Postman - Headers parameter. It will show: { "message": "Unauthenticated." } Laravel will check the configuration for "Accept", it will return the web page or html if no value is set at "Accept" by default.
@molefinance6826
@molefinance6826 Ай бұрын
@@rubyvidhyaammu4984 but since this is in the api routes, can't we automatically get this behaviour without the necessity to send the Accept type? This would prevent the error on this endpoint.
@jenneracostadiaz
@jenneracostadiaz Ай бұрын
Perffect 💖, one question please, in my intelephense return: Undefined method 'tokens'.intelephense(P1013) have you been able to resolve it?
@rubyvidhyaammu4984
@rubyvidhyaammu4984 Ай бұрын
You need to check your return type. You'll find the warnings go away if you wrote something like this. Please try this in function.... $user = Auth::user(); if ($user instanceof \App\Models\User) { // Hinting here for $user will be specific to the User object return $user->createToken("API TOKEN")->plainTextToken; } else { // Handle Error. Not logged in or guard did not return a User object. }
@user-oi5qj1hg1l
@user-oi5qj1hg1l 5 күн бұрын
@@rubyvidhyaammu4984 Hello, this worked for me. Is this a normal solution? public function logout(Request $request) { $request->user()->tokens()->delete(); return response()->json([ 'status' => true, 'message'=> 'User logged out', 'data' => [], ]); }
Cat story: from hate to love! 😻 #cat #cute #kitten
00:40
Stocat
Рет қаралды 13 МЛН
ХОТЯ БЫ КИНОДА 2 - официальный фильм
1:35:34
ХОТЯ БЫ В КИНО
Рет қаралды 2,3 МЛН
когда достали одноклассники!
00:49
БРУНО
Рет қаралды 2,1 МЛН
Cat story: from hate to love! 😻 #cat #cute #kitten
00:40
Stocat
Рет қаралды 13 МЛН