How can i get the event within middleware?

Hi there, I need to know some of the headers (and some other details) from the event in middleware. However it seems like useEvent does not work. Does someone have an idea how i can make it work?
2 Replies
Attacler/Bart
Attacler/BartOP3mo ago
my code is something like:
export default defineNuxtRouteMiddleware(async (to) => {
if (import.meta.server) {
const event = useEvent();

const user = await getUser(event);

if (user.status == "error") return navigateTo("/login");
else return;
// console.log("Server sided!");
}
}
export default defineNuxtRouteMiddleware(async (to) => {
if (import.meta.server) {
const event = useEvent();

const user = await getUser(event);

if (user.status == "error") return navigateTo("/login");
else return;
// console.log("Server sided!");
}
}
in side server api routes i would have the event (ofc) but in this case it doesnt look like that.
Cue
Cue3mo ago
I think you mean https://nuxt.com/docs/api/composables/use-request-event
if (import.meta.server) {
console.log(Object.fromEntries(useRequestEvent()?.headers || []))
}
if (import.meta.server) {
console.log(Object.fromEntries(useRequestEvent()?.headers || []))
}
Want results from more Discord servers?
Add your server