title: How to call me function in laravel based jwt , Its giving 401 error when hit from my react application?
body: <p>Below is my auth controller and api routes file
  login function is working well no issue in that but getting issue on me() function or /me post route please help me to solve it out.</p>
  <p><strong>AuthController</strong></p>
  <pre><code>&lt;?php
  
  namespace App\Http\Controllers;
  
  use Illuminate\Support\Facades\Auth;
  use App\Http\Controllers\Controller;
  use Illuminate\Http\Request; 
  use JWTAuth;
  use JWTFactory;
  
  class AuthController extends Controller
  {
      /**
       * Create a new AuthController instance.
       *
       * @return void
       */
      public function __construct()
      {
          $this-&gt;middleware('auth:api', ['except' =&gt; ['login']]);
      }
  
      /**
       * Get a JWT via given credentials.
       *
       * @return \Illuminate\Http\JsonResponse
       */
      public function index()
      {
          return response()-&gt;json(['message' =&gt; 'Ok Bro !'], 200);
      }    
      
      public function login(Request $request)
      { 
           $password= bcrypt($request-&gt;password);
           $credentials1=[
              'email'=&gt;$request-&gt;email,
              'password'=&gt;$password
           ];
         $credentials = request(['email',   'password',]);  
            if (! $token = JWTAuth::attempt($credentials)) {
          return response()-&gt;json(['error' =&gt; 'Invalid Userid Or Password'], 200);
          } 
  
          return $this-&gt;respondWithToken($token);
          
         //return $credentials1;  // print_r($credentials);
  
         //$2y$10$yxnc9WKUM3fw4BlDOjJWM.8SYuLnWdEoRgrM4Nc\/iQspi2cAE8E5K
         //$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi
      }
  
      /**
       * Get the authenticated User.
       *
       * @return \Illuminate\Http\JsonResponse
       */
      public function me()
      {
         //  $user = JWTAuth::toUser($token);
  
   ///return response()-&gt;json(compact('token', 'user'));
   
            return response()-&gt;json(auth()-&gt;user());
      }
  
      /**
       * Log the user out (Invalidate the token).
       *
       * @return \Illuminate\Http\JsonResponse
       */
      public function logout()
      {
          auth()-&gt;logout();
  
          return response()-&gt;json(['message' =&gt; 'Successfully logged out']);
      }
  
      /**
       * Refresh a token.
       *
       * @return \Illuminate\Http\JsonResponse
       */
      public function refresh()
      {
          return $this-&gt;respondWithToken(auth()-&gt;refresh());
      }
  
      /**
       * Get the token array structure.
       *
       * @param  string $token
       *
       * @return \Illuminate\Http\JsonResponse
       */
      protected function respondWithToken($token)
      {
          return response()-&gt;json([
              'access_token' =&gt; $token,
              'token_type' =&gt; 'bearer',
              'expires_in' =&gt; auth()-&gt;factory()-&gt;getTTL() * 60,
              'user'=&gt;auth()-&gt;user()
          ]);
      }
  }
  </code></pre>
  <p>Below is   api routes file
  login function is working well no issue in that but getting issue on me() function or /me post route please help me to solve it out.</p>
  <p><strong>Api Route</strong></p>
  <pre><code>&lt;?php
  
  use Illuminate\Http\Request;
  use Illuminate\Support\Facades\Route;
  use App\Http\Controllers\AuthController;
  
  /*
  |--------------------------------------------------------------------------
  | API Routes
  |--------------------------------------------------------------------------
  |
  | Here is where you can register API routes for your application. These
  | routes are loaded by the RouteServiceProvider within a group which
  | is assigned the &quot;api&quot; middleware group. Enjoy building your API!
  |
  */
   
   
  Route::middleware('auth:sanctum')-&gt;get('/user', function (Request $request) {
      return $request-&gt;user();
  });
   
   
  
   
  Route::post('login', 'AuthController@login'); 
   
  
  Route::group(['middleware'=&gt;'api'],function(){
  Route::post('logout', 'AuthController@logout');
  Route::post('refresh', 'AuthController@refresh');
  Route::post('me', 'AuthController@me');
  });    
  
  
  </code></pre>
  <p><strong>Result on Post Request in console</strong>
  Issue i am getting on page from post request in react</p>
  <p><a href="https://i.stack.imgur.com/obH2d.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/obH2d.jpg" alt="enter image description here" /></a></p>