Тёмный

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

Rubyvidhya Ammu
Подписаться 169
Просмотров 6 тыс.
50% 1

#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

Опубликовано:

 

5 апр 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 17   
@MakeeJkee
@MakeeJkee День назад
I even went to like it, it’s just my salvation, there is a bug in laravel 11 ->validate and this video saved me😍
@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
@Foxine
@Foxine 16 дней назад
Thank you so much for this class! Thanks a lot! God bless you! Thank you!
@suriyayash
@suriyayash Месяц назад
nice one
@tintrinh6266
@tintrinh6266 Месяц назад
How appreciate I have! That's great, thank you so much.
@arsyadfinan9189
@arsyadfinan9189 2 дня назад
why when i try bearer is false not giving response unauthorized, but back to login route?
@pacogarcia225
@pacogarcia225 19 дней назад
Do you have the code uploaded to a repository in Github? Thanks for your effort.
@wildandvibe
@wildandvibe 2 дня назад
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 6 дней назад
@@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' => [], ]); }
Далее
Top 5 Laravel "Bad Practices" (My Opinion)
10:32
Просмотров 16 тыс.
CORS in Laravel & Sanctum
10:38
Просмотров 7 тыс.
МЯСНОЙ ЦЕХ - Страшилки Minecraft
37:24
Laravel Passport vs Sanctum: What's the difference?
8:28
Learn React Hooks: useCallback - Simply Explained!
17:15