[英]Laravel Auth Problem for Web and Api Routes
不幸的是,我找不到實際經常發生的用戶案例的解決方案。
為了更好地描述它,我把我的 laravelapp 的路由結構(web 和 api)放在這里:
路線/web.php
get(start|products|product/{id}|contact|inprint|login|register)
get(checkout|checkout/(any))->middleware( auth ) // Checkout is a VUE App
路線/api.php
// only the Vue App use the api
get(user|user_orders|user_address) ->middleware( auth )
post (purchase_order) -> middleware(auth)
正如您可能看到的,我想保護網站的某些部分。 此外,我想檢查每個查詢用戶是否已登錄,以便在導航欄中顯示注銷按鈕。
謝謝你的幫助!
你可以反過來。 這將使您可以靈活地檢查 controller 中的身份驗證
Auth::check();
通過這些簡單的步驟,您還可以在 API 路由中檢查身份驗證。 因此,您可以將 JWT 與 auth web 路由集成。
你只需要添加
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Session\Middleware\StartSession::class,
在您的“API”中間件組中
'api' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Session\Middleware\StartSession::class,
\\ existing code...
],
謝謝,
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.