簡體   English   中英

如何在自定義 laravel 包中訪問 Sanctum 包

[英]How to access Sanctum package in custom laravel package

我想訪問在項目路由中運行良好的 laravel sanctum auth 我正在制作一個自定義的 api 包,它需要在自定義包路由中使用相同的 sanctum 身份驗證

為您的路線使用 auth sanctum 中間件,請參見下面的示例。

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

我遇到了同樣的問題,但我發現數據包路由沒有默認保護,並且無法通過數據包訪問會話。

解決方案是將“網絡”中間件添加到路由中。


前:

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

后:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM