export default defineEventHandler(async (event) => {
console.log('REQUEST WAS MADE');
const cookies = parseCookies(event);
console.log(cookies);
if (cookies.jwtToken) {
try {
const userId = (await decryptToken(cookies.jwtToken)) as string;
event.context.userId = userId;
} catch (error) {
console.log(error);
}
} else {
console.log('NOT LOGGED IN');
}
});
``` my auth middleware for my api route. If i refresh my site the first few requests in the first ms are without the headers. This is my template ```<template>
<div>
{{ user }}
</div>
</template>
<script setup lang="ts">
const { data: user } = await useFetch("/api/user/details");
definePageMeta({
middleware: ["auth"],
});
</script>
<style scoped>
</style>``` Workaround right now is to set a timeout which runs after 1000ms, ```const user = ref("Loading");
setTimeout(async () => {
console.log("fetch user");
const { data } = await useFetch("/api/user/details");
user.value = data.value?.user;
}, 1000);``` This is working but i think there has to be another way
#Cookies needs time to set cookies after hard reload
2 messages · Page 1 of 1 (latest)