Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nuxt.confg.ts supabase clientOptions db schema works for useSupabaseClient() but NOT serverSupabaseClient() #275

Closed
jonesisg1 opened this issue Sep 22, 2023 · 1 comment · Fixed by #277
Labels
bug Something isn't working

Comments

@jonesisg1
Copy link
Contributor

Version

@nuxtjs/supabase: v1.1.0
nuxt: v3.7.3

Steps to reproduce

Create a new schema 'myschema' in Supabase project.
Grant privs as in docs:

GRANT USAGE ON SCHEMA myschema TO anon, authenticated, service_role;
GRANT ALL ON ALL TABLES IN SCHEMA myschema TO anon, authenticated, service_role;
GRANT ALL ON ALL ROUTINES IN SCHEMA myschema TO anon, authenticated, service_role;
GRANT ALL ON ALL SEQUENCES IN SCHEMA myschema TO anon, authenticated, service_role;
ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA myschema GRANT ALL ON TABLES TO anon, authenticated, service_role;
ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA myschema GRANT ALL ON ROUTINES TO anon, authenticated, service_role;
ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA myschema GRANT ALL ON SEQUENCES TO anon, authenticated, service_role;

Add myschema to Project Settings -> API Settings -> API settings -> Exposed schemas
Create a table 'mytable' in myschema and add a row of data.
Configure your nuxt.config.ts file:

export default defineNuxtConfig({
  devtools: { enabled: true }, 
  modules: [
    '@nuxtjs/supabase'
  ],
  runtimeConfig: {
    public: {
      baseUrl: process.env.BASE_URL || 'http://localhost:3000'
    },
  },
  supabase: {
    clientOptions: {
      db: { schema: 'myschema' }
    },    
    redirectOptions: {
      login: '/',
      callback: '/confirm'
    },
  }
})

Create a server API route:

import { serverSupabaseClient } from '#supabase/server';
export default defineEventHandler(async (event) => {
  console.log('Calling client.from')
  const client = await serverSupabaseClient(event);
  const { data } = await client.from('mytable').select('mycol');
  console.log(data);
  return data;
});

Call the endpoint from your Vue page.

What is Expected?

Variable 'data' should contain the row from myschema.mytable.

What is actually happening?

Variable 'data' is always null.
When you look in the database logs you see:

[{"event_message":"relation \"public.mytable\" does not exist","metadata":[{"file":null,"host":"db-....

Other comments.

If you place the following code in the Vue page:

const client = useSupabaseClient()
const { data: data } = await useAsyncData('mydata', async () => {
  console.log('from asyncData');
  const { data } = await client.from('mytable').select('mycol')
  return data
})

The variable 'data' is populated with the row from mytable correctly.

@jonesisg1 jonesisg1 added the bug Something isn't working label Sep 22, 2023
@jonesisg1
Copy link
Contributor Author

I have fixed this issue locally and will fork the project and attempt a pull request. (Never done one before!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant