N
Nuxt3mo ago
Mirage

How to access the request event from within @sidebase/nuxt-auth NuxtAuthHandler?

I'd like to access the request event from within NuxtAuthHandler callbacks. I need this in order to set additional cookies / or access objects on event.context. This was one of the attempts I tried:
import { NuxtAuthHandler } from '#auth'
import { useRequestEvent } from 'nuxt/app';

export default NuxtAuthHandler({
callbacks: {
async signIn({ account }) {
const event = useRequestEvent()
},
async session({ session }) {
const event = useRequestEvent()
return session
},
async jwt({ token }) {
const event = useRequestEvent()
return token
},
},
});
import { NuxtAuthHandler } from '#auth'
import { useRequestEvent } from 'nuxt/app';

export default NuxtAuthHandler({
callbacks: {
async signIn({ account }) {
const event = useRequestEvent()
},
async session({ session }) {
const event = useRequestEvent()
return session
},
async jwt({ token }) {
const event = useRequestEvent()
return token
},
},
});
However, this results in the following error:
ERROR RollupError: [plugin impound] Vue app aliases are not allowed in server runtime.
ERROR RollupError: [plugin impound] Vue app aliases are not allowed in server runtime.
What's an alternative to access the request event in this case?
2 Replies
kapa.ai
kapa.ai3mo ago
Hi @Mirage. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Based on the knowledge sources provided, I don't have specific information about accessing the request event within the @sidebase/nuxt-auth NuxtAuthHandler. The error you're encountering suggests that you're trying to use Vue app-specific composables in a server-side context, which is not allowed. However, I can provide some general guidance based on Nuxt 3's approach to handling server-side requests and events: 1. In Nuxt 3, the useRequestEvent() composable is typically used within components, pages, or plugins to access the incoming request event. It's not designed to be used directly in server-side handlers like the one you're working with. 2. For server-side API routes and handlers in Nuxt 3, you usually have direct access to the event object. However, the structure of the NuxtAuthHandler might be different. 3. Instead of trying to use useRequestEvent(), you might want to check if the @sidebase/nuxt-auth package provides a way to access the request event directly within its callbacks. 4. If you need to set cookies, you might be able to use the h3 package's setCookie function, which is often available in Nuxt 3 server-side contexts. However, this would depend on how @sidebase/nuxt-auth is implemented. 5. For accessing or setting values on event.context, you might need to look into how @sidebase/nuxt-auth exposes the underlying request or event object, if at all. Unfortunately, the provided knowledge sources don't contain specific information about the @sidebase/nuxt-auth package or how to access the request event within its handler. You might want to consult the official documentation for @sidebase/nuxt-auth or reach out to their support channels for more specific guidance on how to achieve what you're trying to do within their auth handler. If you need to perform actions like setting cookies or accessing event.context, you might need to explore alternative approaches that are compatible with the @sidebase/nuxt-auth package's architecture. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai3mo ago
<@1188032231105630269> Kapa.ai is still learning and improving, please let me know how I did by reacting below.

Did you find this page helpful?