hasHeader('access-token')) { return response()->json(['status' => 'error', 'status_code' => 401, 'message' => 'Access token not provided'], 401); } // Retrieve the token from the custom access-token header $token = $request->header('access-token'); try { // Attempt to authenticate the user based on the token $user = JWTAuth::setToken($token)->authenticate(); // Check if authentication was successful and user type is correct Log::info("Customer jwt"); Log::info($user); if (!$user || $user->principal_type_xid != 3) { return response()->json(['status' => 'error', 'status_code' => 401, 'message' => 'Unauthorized access'], 401); } Log::info("Customer jwt"); Log::info($user); Log::info($user->principal_type_xid); Session::flash('vendorToken', $token); } catch (JWTException $e) { return response()->json(['status' => 'error', 'status_code' => 401, 'message' => 'Invalid token'], 401); } return $next($request); } }