W
W
whiteleaf2016-05-19 17:03:28
Node.js
whiteleaf, 2016-05-19 17:03:28

Why does this error occur and how can I fix it?

I have sails version 0.12.3
Forbidden
CSRF mismatch

/**
 * UserController
 *
 * @description :: Server-side logic for managing users
 * @help        :: See http://sailsjs.org/#!/documentation/concepts/Controllers
 */

module.exports = {

  'new': function(req,res){
    res.view();
  },

  create: function(req,res,next){
    // Create a User with the params sent from
    // the signup form --> new.ejs
    User.create( req.params.all(), function userCreated (err, user){

      // If there is an error
      if(err) return next(err);

      // After successfully creating the user
      // redirect to the show action
      res.json(user);
    });
  }
};

csrf enabled
/****************************************************************************
*                                                                           *
* Enabled CSRF protection for your site?                                    *
*                                                                           *
****************************************************************************/

 module.exports.csrf = true;

/****************************************************************************
*                                                                           *
* You may also specify more fine-grained settings for CSRF, including the   *
* domains which are allowed to request the CSRF token via AJAX. These       *
* settings override the general CORS settings in your config/cors.js file.  *
*                                                                           *
****************************************************************************/

 module.exports.csrf = {
    grantTokenViaAjax: true,
    origin: ''
 }

How to configure csrf correctly?
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question