Skip to content

AllAuth Headless Not Recognizing CSRF #4138

Closed Answered by krizh-p
krizh-p asked this question in Q&A
Discussion options

You must be logged in to vote

Closing this thread as the issue is not with allauth. In case anyone looks at this in the future, the problem was that Next.js does not send cookies with fetch() even if you explicitly say credentials: "include" in your code. Instead, you have to manually send cookies via a Cookie header, as such:

const response = await fetch("http://localhost:8000/_allauth/browser/v1/auth/signup", {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      'X-CSRFToken': csrftoken as string, // Django might not read the X-CSRFToken header
      Cookie: cookies().toString(), // Use this instead to send Cookies with Nextjs
    },
    body: JSON.stringify({ username, email, password })

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@krizh-p
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by krizh-p
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants