Timo Riegebauer
Timo Riegebauer
NNuxt
Created by Timo Riegebauer on 7/4/2024 in #❓・help
Cookie not being set immediately
I have a problem that my cookie is not being set immediately after the request, i need to reload the page for the cookie to be available but i dont want to interfere with the user's experience
const resp = await $fetch("/api/auth/login", {
method: "post",
body: JSON.stringify({
email: email.value,
password: password.value,
}),
});

if (!resp.success) {
status.value = resp.message;
loading.value = false;
return;
}

const authToken = useCookie("auth-token");
console.log(authToken.value); // Prints "undefined"
const resp = await $fetch("/api/auth/login", {
method: "post",
body: JSON.stringify({
email: email.value,
password: password.value,
}),
});

if (!resp.success) {
status.value = resp.message;
loading.value = false;
return;
}

const authToken = useCookie("auth-token");
console.log(authToken.value); // Prints "undefined"
1 replies