Phillip
appMiddleware for API routes?
When an API under /api/admin is being called I want to run my middleware under /server/middleware/admin.ts
I thought I could add a route rule to the nuxt.config.ts like this:
But still, the middleware runs on every request which is also mentioned in the docs (https://nuxt.com/docs/guide/directory-structure/server#server-middleware)
But I was wondering if something like this
'/api/admin/**': { appMiddleware: 'admin' }
is possible?
Otherwise I would need to do something like if (requestUrl.includes('/api/admin'))
right?1 replies
appMiddleware in routeRules not working?
I want to run a middleware when my API in
/server/api/admin/text-snippet.post.ts
is being called but it doesn't run the middleware at all.
Nuxt 3.12.2
nuxt.config.ts
middleware/mytest.ts
server/api/admin/text-snippet.post.ts
Then, I access the API via Postman. Method: Post. URL: http://localhost:3000/api/admin/text-snippet
The response is { success: true }
What am I missing or is this a bug?7 replies
Private server routes
Hello guys, how can i flag my nuxt 3 api routes as private meaning they can only be accessed from the server itself and is not viewable by the user?
Since every API file I put inside /server/api, but also /server/, will be accessible by other users. How can I prevent this?
6 replies
Is there a way to prefetch the next page which has content that is being injected by javascript?
I have a page /welcome/payment-method where I load a Stripe UI payment element.
Stripe has a function
paymentElement.mount('#payment-element')
, so basically, it looks for a DOM element with the id #payment-element
. However, injecting the Stripe script and mounting the element takes time. I would like to show the form immediately.
Is there way I can load the stripe script + mount the div#payment-element
before the user visits the page /welcome/payment-method?
Can I prepare this while the user is on page /welcome/intro or something?
I hope my question is clear. I'm happy to explain further.
Thank you!2 replies
How to access the event in a server/utils function?
I've created a server utility function in /server/utils/get-facebook-account.ts which looks like this
I'm using Supabase so for the serverSupabaseClient I need the event.
Now I'm wondering, do I always need to pass the event to my utility function like this?
/server/api/campaign.post.ts
Because I've read there is a useRequestEvent
composable but it's only available in the Nuxt context. Is there something similar for /server functions?
Thanks!3 replies
await useAsyncData in setup doesn't block navigation
I want to wait until navigating to the next page until the store data has been fetched and set.
I'm using Nuxt 3 + Supabase + Pinia
My approach in
provider.vue
(where user gets redirected after signing in/up to set cookies etc.)
app.vue
: fetch store data. I'm hoping to block navigation by using await useAsyncData
my store (reduced data for demonstration purpose)
... however, after the provider.vue
redirects me, this value is undefined in one of my composables:
const { company } = storeToRefs(useUserStore())
How can I make the application wait until the store has been set?1 replies