Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSRF Token missing in POST #902

Closed
chefsoo opened this issue Aug 22, 2018 · 1 comment
Closed

CSRF Token missing in POST #902

chefsoo opened this issue Aug 22, 2018 · 1 comment

Comments

@chefsoo
Copy link

chefsoo commented Aug 22, 2018

React front end, trying to post to the server side.
However I get an "Error: CSRF token missing"

import Cookies from 'js-cookie';
....
           async submitForm() {
        console.log('submitting form');
        console.log(this.state);
        const formData = {
            checkinData: this.state.checkinData,
        };
       const xsrfCookie = Cookies.get('XSRF-TOKEN');
        const headers = new Headers({
            'XSRF-TOKEN': xsrfCookie,
            '_csrf': xsrfCookie,
        });

        console.log("formdata",formData)
        const res = await fetch('/postAttempts', {
            method: 'POST',
            headers,
            credentials: 'include',
            body: JSON.stringify(formData),
        })

From the controller

exports.postAttempts = function(req, res) {
  console.log(req);
  console.log(req.body);

  res.json({data: 'hi'});
};

Am I incorrectly setting the csrf token in the header?

@YasharF
Copy link
Collaborator

YasharF commented Aug 23, 2018

This project isn't based on react. You may have a better answer from one of the react support groups.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants