简体   繁体   中英

How to access Sanctum package in custom laravel package

我想访问在项目路由中运行良好的 laravel sanctum auth 我正在制作一个自定义的 api 包,它需要在自定义包路由中使用相同的 sanctum 身份验证

use auth sanctum middleware for your routes, See below example.

https://laravel.com/docs/9.x/sanctum#protecting-routes

I was having the same problem, but I found that the packet routes did not have a default guard and the session was not accessible through the packet.

The solution was to add the 'web' middleware to the routes.


Before:

Route::get('/dashboard', [HomeController::class, 'index'])->middleware(['auth:sanctum'])->name('dashboard');

After:

Route::get('/dashboard', [HomeController::class, 'index'])->middleware(['web', 'auth:sanctum'])->name('dashboard');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM