Created
March 14, 2024 14:30
-
-
Save axilaris/8c417cbf212c35ece93bf0ca81bf1e4d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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