#Nuxt 4 + Supabase Auth example? (SSR)
5 messages · Page 1 of 1 (latest)
Hi @steady cedar. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
The knowledge sources don’t contain a full, bare‑bones Nuxt 4 + Supabase SSR auth template, and they only touch Supabase in a few small ways (redirect behavior and some config hints), so I can’t give you a complete, authoritative example from them.
Here’s what is clearly documented:
-
The Supabase Nuxt module auto‑redirects to
/loginby default when a non‑authenticated user hits a guarded route. That’s why a fresh Nuxt app with@nuxtjs/supabasecan suddenly start redirecting to/logineven if you didn’t add any middleware yourself. [Nuxt redirect]
The docs (linked in that answer) explain you can disable or customize this via theredirectOptionsinnuxt.config:// nuxt.config.ts export default defineNuxtConfig({ modules: ['@nuxtjs/supabase'], supabase: { redirectOptions: { login: '/login', callback: '/confirm', exclude: ['/*'], // or adjust to your needs }, }, }) -
For OAuth flows, the module expects a callback route (e.g.
/confirm) that you must actually create as a page. In one example, GitHub OAuth wasn’t working until aconfirm.vuepage was added to matchredirectOptions.callback. [Supabase OAuth]// nuxt.config.ts (excerpt) supabase: { redirectOptions: { login: '/login', callback: '/confirm', exclude: ['/*'], }, }And then you need a
pages/confirm.vuefile so the callback route exists. [Supabase OAuth] -
There’s also a note from a Nuxt issue showing a working Nuxt 4 + Supabase setup that adds some Vite/Nitro config to make Supabase work nicely in SSR:
// nuxt.config.ts (excerpt)
export default defineNuxtConfig({
modules: ['@nuxtjs/supabase', /* ... */],
vite: {
optimizeDeps: {
include: ['@supabase/postgrest-js', '@supabase/supabase-js'],
},
},
nitro: {
externals: {
inline: ['@supabase/supabase-js'],
},
},
supabase: {
// your supabase config here
},
})
What’s missing from the sources:
- A full SSR‑first pattern like “check session on the server in middleware, inject user into SSR context, and render protected pages accordingly” is not shown in the provided documents.
- There’s no complete example repo or code snippet that wires
useSupabaseUser()/useSupabaseClient()into a Nuxt 4 SSR auth flow.
Given that, I can’t honestly provide a full, working “barebones Nuxt 4 + Supabase SSR auth template” strictly from these sources.
If you want to build SSR auth around the module, the pieces you do have from the docs/answers above are:
- Use the
@nuxtjs/supabasemodule with theredirectOptionsto control unauthenticated redirects. [Nuxt redirect] - Ensure your OAuth
callbackroute (e.g./confirm) exists as a page so the login flow completes. [Supabase OAuth] - Apply the Vite/Nitro config shown above if you hit bundling/SSR issues with Supabase in Nuxt 4. [Nuxt 4 + Supabase]