@enfyra/sdk-nuxt
v1.0.2
Published
Nuxt module for Enfyra — SSR-safe client, composables, and cookie bridge proxy
Readme
@enfyra/sdk-nuxt
Nuxt 3/4 module for Enfyra. Cookie-bridge auth, SSR-safe request-scoped client, and auto-imported composables.
Install
yarn add @enfyra/sdk-nuxt @enfyra/sdk-coreSet ENFYRA_APP_URL in your environment — that's it:
ENFYRA_APP_URL=https://admin.example.comexport default defineNuxtConfig({
modules: ['@enfyra/sdk-nuxt'],
})If you prefer config over env (e.g. for multi-tenant or per-environment overrides), set enfyra.appUrl instead — it takes precedence over the env var:
export default defineNuxtConfig({
modules: ['@enfyra/sdk-nuxt'],
enfyra: {
appUrl: 'https://admin.example.com',
},
})No plugin, server middleware, route rule, or cookie handler needs to be written manually.
Options
All options are optional. appUrl falls back to ENFYRA_APP_URL when omitted.
| Option | Type | Default | Notes |
|---|---|---|---|
| appUrl | string | process.env.ENFYRA_APP_URL | Server-only. Overrides the env var when set. |
| routePrefix | string | '/enfyra' | Exposed to browser as the cookie-bridge proxy prefix. |
Composables
All composables are auto-imported — no manual imports needed.
useEnfyra
Returns the EnfyraClient instance for direct API access.
const client = useEnfyra()
const { data } = await client.get('/projects')useAuth
const { user, isAuthenticated, pending, login, logout, refresh, oauthLogin } = useAuth()
await login({ email: '[email protected]', password: '...' })
oauthLogin('google')useQuery / useMutation
const { data, error, pending, meta, refresh } = useQuery('articles', {
select: 'id,title,status',
filter: { status: { _eq: 'published' } },
limit: 20,
})
const { execute, pending: saving } = useMutation('articles')
await execute({ data: { title: 'Hello' } })useStorage
const { upload, uploading, download, getDownloadUrl, getFolderTree } = useStorage()
const file = await upload(fileInput.files[0], { folder: 1 })useWebSocket
const ws = useWebSocket('cloud', { immediate: true })
ws.on('cloud:project-changed', (event) => { ... })SSR behavior
- One
EnfyraClientper incoming request; never cached across requests. - Forwards the request's
CookieandAuthorizationheaders to the Enfyra App. - Appends rotated
Set-Cookieheaders back to the SSR response. - Browser traffic uses the same-origin
/enfyraproxy withHttpOnlycookies.
What the module does
- Proxies
/${routePrefix}/**→${appUrl}/api/**with manual redirects. - Creates a request-scoped client (SSR) or singleton (CSR) via a Nuxt plugin.
- Auto-imports all composables.
- Sets
cookieBridgePrefixfor OAuth redirect flows.
