Getting Started
Installation
Add Nuxt PostgREST to your Nuxt app.
Install the module
Terminal
npx nuxi module add nuxt-postgrest
Point it at PostgREST
nuxt.config.ts
export default defineNuxtConfig({
modules: ['nuxt-postgrest'],
postgrest: {
url: 'http://localhost:3001',
},
})
Or leave url out and set it per environment:
.env
NUXT_PUBLIC_POSTGREST_URL=https://api.example.com
# Optional: anon JWT used when no user is logged in.
# Leave unset to let PostgREST fall back to its db-anon-role.
NUXT_PUBLIC_POSTGREST_KEY=
# Server-only: JWT for a privileged role, used by usePostgrestAdmin()
NUXT_POSTGREST_SECRET_KEY=
Query
app.vue
<script setup lang="ts">
const { data } = await useAsyncData('todos', async () => {
const { data, error } = await usePostgrest().from('todos').select('*')
if (error) throw error
return data
})
</script>
Requires Nuxt
>=4.0.0.Next, set up types so every query is checked at compile time, then connect your auth.