Title:
Vue 3 fetch works for first request but fails/omits credentials on subsequent API call in onMounted
Body:
I am developing a user management dashboard in Vue 3 using
. In theonMountedhook, I am performing two sequential fetch requests to an Express.js backend. The first request validates the session, and the second one fetches the list of users to display them in av-forloop.I noticed that while my authentication check passes successfully, the second request (
/api/users) behaves differently, and I want to make sure I am handling cross-origin requests and asynchronous flow correctly within this component.Here is my
Users.vuecomponent code:Felhasználók
- {{ user.user_name }} ({{user.type}})
My questions:
I forgot to include
credentials: 'include'in the secondfetch("http://localhost:3000/api/users")call. Will this cause the Express backend to reject the request if the routes are protected, or will it just omit the session cookie?Similar to my other views, calling
router.push('/')inside theif (!res.ok)block does not stop the rest of the function from executing. What is the cleanest way to prevent the/api/usersfetch from firing at all if the initial session check fails?Thank you for your help and insights!