I am trying to get Auth sessions working between Nuxt 3 and Adonis 6 using this YT video as a reference https://www.youtube.com/watch?v=zvK4-suEKnM
When my login code runs, it returns a user from Adonis and cookies are set in my browser
try {
await $fetch($api('/user/login'), {
method: 'POST',
body: user,
onResponse: (data) => {
if(data.response.ok) {
userStore.setUser(data.response._data)
toast.add({ title: 'Login Successful', duration: 6000, color: 'green' })
router.push('/')
} else {
toast.add({ title: `Login Failed: ${data.response._data.errors[0].message}`, duration: 6000, color: 'red' })
console.log("fetch result", data)
}
}
})
}catch(_error){}
In my default layout, I want to re authenticate the user if the browser is refreshed with this code.
<script setup>
const headers = useRequestHeaders(['cookie']);
console.log("headers", headers);
const data = await fetch("http://localhost:3333/api/v1/user/auth", {
headers,
credentials: "include",
});
</script>
The console log in the code above displays an empty object