Auth providers

Supabase

@nuxtjs/supabasegetClaimsisAuthRetryableFetchError
Verify the Supabase session with getClaims, and tell bad tokens from outages.

@nuxtjs/supabase stores the session in Cookies. Its serverSupabaseUser(event) throws an error without a status code when the token is invalid, which the guard would answer with 503. Call getClaims() yourself so that a bad token becomes 401 and only network failures become 503.

server/auth/verify-user.ts
import { createError } from 'h3'
import { isAuthRetryableFetchError } from '@supabase/supabase-js'
import type { VerifyUser } from '@kurashina-design/nuxt-bff-guard'
import { serverSupabaseClient } from '#supabase/server'

export default (async (event) => {
  const client = await serverSupabaseClient(event)
  const { data, error } = await client.auth.getClaims()

  // Network or 5xx from Supabase Auth: let it through → 503.
  if (error && isAuthRetryableFetchError(error)) throw error
  // No session, expired or invalid token → 401.
  if (error || !data?.claims?.sub) throw createError({ statusCode: 401 })

  event.context.user = { id: data.claims.sub, role: data.claims.role }
  return { viaBearer: false }
}) satisfies VerifyUser

Mobile or CLI clients with a Bearer token

The module's server client reads Cookies only. For a client that sends Authorization: Bearer <access token>, pass the token to getClaims.

server/auth/verify-user.ts
import { createError, getHeader } from 'h3'
import { isAuthRetryableFetchError } from '@supabase/supabase-js'
import type { VerifyUser } from '@kurashina-design/nuxt-bff-guard'
import { serverSupabaseClient } from '#supabase/server'

export default (async (event) => {
  const bearer = /^Bearer[ \t]+(\S+)$/i.exec(getHeader(event, 'authorization') ?? '')?.[1]
  const client = await serverSupabaseClient(event)
  const { data, error } = await client.auth.getClaims(bearer)

  if (error && isAuthRetryableFetchError(error)) throw error
  if (error || !data?.claims?.sub) throw createError({ statusCode: 401 })

  event.context.user = { id: data.claims.sub }
  return { viaBearer: Boolean(bearer) }
}) satisfies VerifyUser

Row Level Security in the database stays your last line: the guard decides who reaches the handler, RLS decides which rows they see.