How to solve the 302 redirection error when laravel passport uses javascript to call the interface?

use laravel passport as api authentication. A valid token has been applied for using the authorization code.

works well in postman :

clipboard.png

javascript

clipboard.png

clipboard.png

javascript :

clipboard.png

I said that I am particularly speechless, why postman using token is normal, and then javascript uses token access but authentication is not successful for redirection!

Mar.21,2021

when a request contains a custom header (sometimes Authorization is also considered a custom header), the browser will initiate a preflight request in the form of options before initiating the real request. Laravel does not handle the pre-check request correctly, so it returns 404, and then the web server redirects 404 to the error page.

the following solution is not very elegant:
is to add middleware that handles preflight .

protected $middleware = [
    \App\Http\Middleware\PreflightResponse::class,
    // ...
];

should be able to fix this problem

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bdb58a-3128c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bdb58a-3128c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?