400 bad request jwt authentication error

about 2 years ago - Direct link

i want to add jwt authentication in django-react app and i am following this tutorial. at django part to avoid cors-block i used the following settings for cors-headers:

CORS_ORIGIN_ALLOW_ALL = True

CORS_ALLOW_CREDENTIALS = True

CORS_ORIGIN_WHITELIST = [

'http://localhost:3000',

]

in frontend part i would like to use react-hooks function and here is the following code for sign up in App.js:

import React,{useState} from 'react'

export default function App(){

const [username, setUsername] = useState("");

const [password, setPassword] = useState("");

function handleUsername(evt) {

setUsername(evt.target.value);

    }

function handlePassword(evt) {

setPassword(evt.target.value);

    }

function handle_signup(evt, data) {

evt.preventDefault();

fetch("http://localhost:8000/core/users/", {

method: "POST",

headers: {

"Content-Type": "application/json",

        },

body: JSON.stringify(data),

      })

        .then((res) => res...


Go to article →

Links in this thread

Django & React: JWT Authentication | by Dakota Lillie | Medium
Recently I’ve been building an app using a combination of React for the frontend and Django for the backend. I wasn’t previously all too familiar with Django, but this seemed like a good opportunity…


http://localhost:3000


http://localhost:8000/admin/auth/user/


http://localhost:8000/core/users/