© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•3y ago•
3 replies
Maks

NestJS with Supabase Auth SSR package

Hey, I'm new to Supabase and its community. Would appreciate some guidance 🙂

I'm trying to implement this logic below defined in SSR package docs for express, but in NestJs backend. Is there anyone who managed to implement this?

const { createServerClient } = require('@supabase/ssr')

exports.createClient = (context) => {
  return createServerClient(process.env.SUPABASE_URL, process.env.SUPABASE_ANON_KEY, {
    cookies: {
      get: (key) => {
        const cookies = context.req.cookies
        const cookie = cookies[key] ?? ''
        return decodeURIComponent(cookie)
      },
      set: (key, value, options) => {
        if (!context.res) return
        context.res.cookie(key, encodeURIComponent(value), {
          ...options,
          sameSite: 'Lax',
          httpOnly: true,
        })
      },
      remove: (key, options) => {
        if (!context.res) return
        context.res.cookie(key, '', { ...options, httpOnly: true })
      },
    },
  })
}
const { createServerClient } = require('@supabase/ssr')

exports.createClient = (context) => {
  return createServerClient(process.env.SUPABASE_URL, process.env.SUPABASE_ANON_KEY, {
    cookies: {
      get: (key) => {
        const cookies = context.req.cookies
        const cookie = cookies[key] ?? ''
        return decodeURIComponent(cookie)
      },
      set: (key, value, options) => {
        if (!context.res) return
        context.res.cookie(key, encodeURIComponent(value), {
          ...options,
          sameSite: 'Lax',
          httpOnly: true,
        })
      },
      remove: (key, options) => {
        if (!context.res) return
        context.res.cookie(key, '', { ...options, httpOnly: true })
      },
    },
  })
}
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Supabase Auth with SSR package and Express
SupabaseSSupabase / help-and-questions
3y ago
ssr package buggy with auth
SupabaseSSupabase / help-and-questions
14mo ago
auth-helpers vs @supabase/ssr
SupabaseSSupabase / help-and-questions
3y ago
session with @supabase/ssr
SupabaseSSupabase / help-and-questions
3y ago