Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save axilaris/8c417cbf212c35ece93bf0ca81bf1e4d to your computer and use it in GitHub Desktop.
Save axilaris/8c417cbf212c35ece93bf0ca81bf1e4d to your computer and use it in GitHub Desktop.
function submitLogin(e) {
e.preventDefault();
const csrftoken = Cookies.get('csrftoken');
console.log("XXX /api/login csrftoken:" + csrftoken);
const url = 'http://localhost:8000/api/login'; // Corrected URL
const data = {
email: email,
password: password,
};
fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
//'X-CSRFToken': csrftoken, // Include the CSRF token
},
body: JSON.stringify(data),
credentials: 'include', // Ensure cookies are sent
})
.then((response) => {
const responsecsrftoken = Cookies.get('csrftoken');
const sessionid = Cookies.get('sessionid');
console.log("XXX /api/login responsecsrftoken:" + responsecsrftoken);
console.log("XXX /api/login sessionid:" + sessionid);
console.log('cookies', document.cookie)
return response.json();
})
.then((res) => {
// Handle the response here
console.log('Response:', res);
setCurrentUser(true);
})
.catch((error) => {
console.error('Error fetching data:', error);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment