PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, March 3, 2022

[FIXED] Swagger UI requestInterceptor throws the "Cannot set property 'X-CSRF-TOKEN' of undefined" error

 March 03, 2022     laravel, laravel-5, swagger, swagger-ui     No comments   

Issue

I'm using Laravel 5.7 and Swagger to create API documentation.

composer require:

"require": {
    "php": ">=5.6.4",
    "darkaonline/l5-swagger": "^5.7.3",
    "filp/whoops": "~2.0",
    "laravel/framework": "5.7.*",
    "laravel/passport": "~4.0",
    "laravel/tinker": "~1.0",
    "mll-lab/laravel-graphql-playground": "^2.1",
    "nuwave/lighthouse": "^4.15",
    "paragonie/random_compat": "~2.0",
    "zircote/swagger-php": "3.*"
},

Everything is working OK, but when I try to execute a request in Swagger UI, I get an error:

actions.js:453
TypeError: Cannot set property 'X-CSRF-TOKEN' of undefined

This is the code that throws the error:

 requestInterceptor: function() {
      this.headers['X-CSRF-TOKEN'] = 'hM4lUy0ednXXWEFwYc1iRprnSuBuPwQH6Z4pi6v8';
      return this;
    },

Why does the error occur?


Solution

Your requestInterceptor function is missing an argument.

The requestInterceptor function must have one argument, say, req. This argument provides access to the request data. The function must return the modified request.

requestInterceptor: function(req) {
  req.headers['X-CSRF-TOKEN'] = 'hM4lUy0ednXXWEFwYc1iRprnSuBuPwQH6Z4pi6v8';
  return req;
},


Answered By - Helen
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing