Help: Testing Nuxt API Routes Using serverSupabaseServiceRole and serverSupabaseUser with Vitest #503
cubinet-code
started this conversation in
General
Replies: 1 comment
-
|
I'm also dealing with this right now, and haven't found a good solution yet (granted, I've only been working on it today). But the fact that the supabaseServerClient needs the Nitro request event is weird to me. I understand that it provides all the other benefits of supabase, but that means that I'm having to engineer my Use Cases and my Repositories to all accept nitro events as parameters, which creates tight coupling. Even the serverSupabaseServiceRole requires the event, but it's not doing row level security. Why does it need access to the server event? https://supabase.nuxtjs.org/services/serversupabaseservicerole |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi everyone,
I’m currently writing tests for Nuxt server API routes using Vitest, and I’m having trouble mocking the Supabase utilities provided by #supabase/server — specifically serverSupabaseUser(event) and serverSupabaseServiceRole(event).
Despite searching extensively, I haven’t found any clear examples or official documentation on how to test Nuxt routes that depend on these functions. The serverSupabaseUser is used to get the authenticated user, and serverSupabaseServiceRole gives a service client for queries. Both are deeply integrated into route logic, so I need a way to mock or stub them to write proper unit tests.
Example route I’m testing
Here’s a simplified version of the route handler (in server/api/accounts/index.ts):
What I’ve tried
What I need help with
⸻
Thanks in advance! 🙏
If I find a solution, I’ll be sure to post it here for others.
Beta Was this translation helpful? Give feedback.
All reactions