Skip to content

CSRF Token missing in POST #10

@chefsoo

Description

@chefsoo

React front end, trying to post to the server side, however I get a Error: CSRF token missing

import Cookies from 'js-cookie';
....
        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 pulling the csrf token?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions