Reputation: 187
I am trying to instantiate supabase in nuxt3 in the server/api/myroute.ts . It works on my local dev network but when I deploy it to netlify and use postman to hit the route I get the error below. The breaking point is right after it tries to create the supabase instance with create client. The endpoint is being tested on the build on netlify the local network does not have any issues running this code.
If anyone can help with this I would appreciate it, thank you!
{
"url": "/api/incoming-message",
"statusCode": 500,
"statusMessage": "",
"message": "main.createClient is not a function",
"stack": ""
}
import { Database, Json } from '~/types/supabase';
import twilio from 'twilio';
import { createClient } from '@supabase/supabase-js';
export default defineEventHandler(async (event) => {
const config = useRuntimeConfig();
const supabase = createClient<Database>(
config.public.SUPABASE_URL,
config.private.SUPABASE_SERVICE_KEY
);
Upvotes: 0
Views: 817
Reputation: 73
I found a workaround, the error occures when initializing a supabase client using the service role key and no supabase client has been initialized before using the anon token.
serverSupabaseClient(event); // Create a supabase client using anon token
const supabase = serverSupabaseServiceRole<Database>(event);
If someone find a better solution, I'm all ears.
EDIT: My example uses @nuxtjs/supabase
but you can manage to do the same using supabase-js
Upvotes: 1