CipherStashDocs
StackLatestPackagesStackSrcSupabaseFunctions

encryptedSupabase

encryptedSupabase is a function in @cipherstash/stack. TypeScript API reference with its signature, parameters, and usage.

@cipherstash/stack


Function: encryptedSupabase()

function encryptedSupabase(config): EncryptedSupabaseInstance;

Defined in: packages/stack/src/supabase/index.ts:41

Create an encrypted Supabase wrapper that transparently handles encryption and decryption for queries on encrypted columns.

Parameters

config

EncryptedSupabaseConfig

Configuration containing the encryption client and Supabase client.

Returns

EncryptedSupabaseInstance

An object with a from() method that mirrors supabase.from() but auto-encrypts mutations, adds ::jsonb casts, encrypts filter values, and decrypts results.

Example

import { Encryption } from '@cipherstash/stack'
import { encryptedSupabase } from '@cipherstash/stack/supabase'
import { encryptedTable, encryptedColumn } from '@cipherstash/stack/schema'

const users = encryptedTable('users', {
  name: encryptedColumn('name').freeTextSearch().equality(),
  email: encryptedColumn('email').freeTextSearch().equality(),
})

const client = await Encryption({ schemas: [users] })
const eSupabase = encryptedSupabase({ encryptionClient: client, supabaseClient: supabase })

// INSERT - auto-encrypts, auto-converts to PG composite
await eSupabase.from('users', users)
  .insert({ name: 'John', email: '[email protected]', age: 30 })

// SELECT with filter - auto-casts ::jsonb, auto-encrypts search term, auto-decrypts
const { data } = await eSupabase.from('users', users)
  .select('id, email, name')
  .eq('email', '[email protected]')

On this page