Hello!
I'm really struggling with a project where the backend was already made on NodeJS.
I need to create the frontend also on NodeJS and I'm using Wappler for that (which in the end will be on different domain/port).
For testing, backend is :3000, frontend :4000 and for login and storing cookies, I ran in some issues.
This doesn't store cookies:
<form is="dmx-api-form" id="apiform1" action="http://localhost:3000/auth/login" method="post" post-data="json">
<input id="text1" name="email" type="text" class="form-control">
<input id="text2" name="password" type="text" class="form-control">
<button id="btn1" class="btn" type="submit">Login</button>
But this, does:
<form id="loginForm">
<input id="email" name="email" type="text" class="form-control">
<input id="password" name="password" type="password" class="form-control">
<button id="loginButton" class="btn" type="submit">Login</button>
</form>
<script>
document.getElementById('loginForm').addEventListener('submit', async (event) => {
event.preventDefault();
const email = document.getElementById('email').value;
const password = document.getElementById('password').value;
const response = await fetch('http://localhost:3000/auth/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
credentials: 'include',
body: JSON.stringify({ email, password })
});
</script>
If I comment credentials: 'include', the cookies are not being stored, so I think the issue is going on that direction.
Is it possible to send credentials on an API form?
Thanks!