Getting Started
Introduction
What Nuxt PostgREST is and when to use it.
Nuxt PostgREST connects a Nuxt app to a self-hosted PostgREST API. It gives you typed query builders in components and server routes, forwards the logged-in user's JWT so Postgres row-level security (RLS) applies, and provides a server-only admin client for privileged work.
pages/todos.vue
<script setup lang="ts">
const postgrest = usePostgrest()
const { data: todos } = await useAsyncData('todos', async () => {
const { data, error } = await postgrest.from('todos').select('id, title').order('id')
if (error) throw error
return data
})
</script>
When to use it
Use this module if you run PostgREST yourself (Docker, Kubernetes, a VPS) and want a Nuxt-native way to call it. If you are on Supabase, use @nuxtjs/supabase instead: it covers Supabase Auth, Storage and Realtime, which this module intentionally does not.
What you get
| Composable | Where | Acts as |
|---|---|---|
usePostgrest() | Components, pages, plugins (client + SSR) | The current user, or anon |
usePostgrestUser(event) | Server routes | The requesting user, or anon |
usePostgrestAdmin() | Server routes | Your privileged secret role |
createPostgrestClient() | Anywhere | Whatever key you pass |
All four return a standard PostgrestClient, so everything in the postgrest-js API works: filters, embedding, rpc(), .schema() and more.