我嘗試通過教程使用 php-open-source-saver/jwt-auth https://blog.logrocket.com/implementing-jwt-authentication-laravel-9/
它工作正常,但我在注銷時遇到一些問題。
Auth::logout();
當(dāng)我注銷并嘗試調(diào)用我的測試方法時,它使用舊令牌。
class SubjectController extends Controller { public function __construct() { $this->middleware('auth:api'); } public function show($id) { $subject = Subject::find($id); return response(json_encode($subject)) ->header('Content-Type','application/json'); } }
檢查文檔:https://laravel-jwt-auth .readthedocs.io/en/latest/auth-guard/
logout()
注銷用戶 - 這將使當(dāng)前令牌無效并取消設(shè)置經(jīng)過身份驗證的用戶。
auth()->logout(); // Pass true to force the token to be blacklisted "forever" auth()->logout(true);