Supabase Reference (JavaScript) # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference Using Filters Filters allow you to only return rows that match certain conditions. Filters can be used on `select()`, `update()`, `upsert()`, and `delete()` queries. If a Postgres function returns a table response, you can also apply filters. ## Examples ### Applying Filters ```ts const { data, error } = await supabase .from('instruments') .select('name, section_id') .eq('name', 'violin') // Correct const { data, error } = await supabase .from('instruments') .eq('name', 'violin') // Incorrect .select('name, section_id') ``` ### Chaining ```ts const { data, error } = await supabase .from('cities') .select('name, country_id') .gte('population', 1000) .lt('population', 10000) ``` ### Conditional Chaining ```ts const filterByName = null const filterPopLow = 1000 const filterPopHigh = 10000 let query = supabase .from('cities') .select('name, country_id') if (filterByName) { query = query.eq('name', filterByName) } if (filterPopLow) { query = query.gte('population', filterPopLow) } if (filterPopHigh) { query = query.lt('population', filterPopHigh) } const { data, error } = await query ``` ### Filter by values within a JSON column ```ts const { data, error } = await supabase .from('users') .select() .eq('address->postcode', 90210) ``` ### Filter referenced tables ```ts const { data, error } = await supabase .from('orchestral_sections') .select(` name, instruments!inner ( name ) `) .eq('instruments.name', 'flute') ``` # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference Using Modifiers Filters work on the row level—they allow you to return rows that only match certain conditions without changing the shape of the rows. Modifiers are everything that don't fit that definition—allowing you to change the format of the response (e.g., returning a CSV string). Modifiers must be specified after filters. Some modifiers only apply for queries that return rows (e.g., `select()` or `rpc()` on a function that returns a table response). ## Examples # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference Overview ## Examples ### Create auth client ```js import { createClient } from '@supabase/supabase-js' const supabase = createClient(supabase_url, anon_key) ``` ### Create auth client (server-side) ```js import { createClient } from '@supabase/supabase-js' const supabase = createClient(supabase_url, anon_key, { auth: { autoRefreshToken: false, persistSession: false, detectSessionInUrl: false } }) ``` # JavaScript Reference ## Examples # JavaScript Reference onAuthStateChange() ## Examples ### Listen to auth changes ```js const { data } = supabase.auth.onAuthStateChange((event, session) => { console.log(event, session) if (event === 'INITIAL_SESSION') { // handle initial session } else if (event === 'SIGNED_IN') { // handle sign in event } else if (event === 'SIGNED_OUT') { // handle sign out event } else if (event === 'PASSWORD_RECOVERY') { // handle password recovery event } else if (event === 'TOKEN_REFRESHED') { // handle token refreshed event } else if (event === 'USER_UPDATED') { // handle user updated event } }) // call unsubscribe to remove the callback data.subscription.unsubscribe() ``` ### Listen to sign out ```js supabase.auth.onAuthStateChange((event, session) => { if (event === 'SIGNED_OUT') { console.log('SIGNED_OUT', session) // clear local and session storage [ window.localStorage, window.sessionStorage, ].forEach((storage) => { Object.entries(storage) .forEach(([key]) => { storage.removeItem(key) }) }) } }) ``` ### Store OAuth provider tokens on sign in ```js // Register this immediately after calling createClient! // Because signInWithOAuth causes a redirect, you need to fetch the // provider tokens from the callback. supabase.auth.onAuthStateChange((event, session) => { if (session && session.provider_token) { window.localStorage.setItem('oauth_provider_token', session.provider_token) } if (session && session.provider_refresh_token) { window.localStorage.setItem('oauth_provider_refresh_token', session.provider_refresh_token) } if (event === 'SIGNED_OUT') { window.localStorage.removeItem('oauth_provider_token') window.localStorage.removeItem('oauth_provider_refresh_token') } }) ``` ### Use React Context for the User's session ```js const SessionContext = React.createContext(null) function main() { const [session, setSession] = React.useState(null) React.useEffect(() => { const {data: { subscription }} = supabase.auth.onAuthStateChange( (event, session) => { if (event === 'SIGNED_OUT') { setSession(null) } else if (session) { setSession(session) } }) return () => { subscription.unsubscribe() } }, []) return ( ) } ``` ### Listen to password recovery events ```js supabase.auth.onAuthStateChange((event, session) => { if (event === 'PASSWORD_RECOVERY') { console.log('PASSWORD_RECOVERY', session) // show screen to update user's password showPasswordResetScreen(true) } }) ``` ### Listen to sign in ```js supabase.auth.onAuthStateChange((event, session) => { if (event === 'SIGNED_IN') console.log('SIGNED_IN', session) }) ``` ### Listen to token refresh ```js supabase.auth.onAuthStateChange((event, session) => { if (event === 'TOKEN_REFRESHED') console.log('TOKEN_REFRESHED', session) }) ``` ### Listen to user updates ```js supabase.auth.onAuthStateChange((event, session) => { if (event === 'USER_UPDATED') console.log('USER_UPDATED', session) }) ``` # JavaScript Reference signInAnonymously() ## Examples ### Create an anonymous user ```js const { data, error } = await supabase.auth.signInAnonymously({ options: { captchaToken } }); ``` ### Create an anonymous user with custom user metadata ```js const { data, error } = await supabase.auth.signInAnonymously({ options: { data } }) ``` # JavaScript Reference signInWithPassword() ## Examples ### Sign in with email and password ```js const { data, error } = await supabase.auth.signInWithPassword({ email: 'example@email.com', password: 'example-password', }) ``` ### Sign in with phone and password ```js const { data, error } = await supabase.auth.signInWithPassword({ phone: '+13334445555', password: 'some-password', }) ``` # JavaScript Reference signInWithIdToken ## Examples ### Sign In using ID Token ```js const { data, error } = await supabase.auth.signInWithIdToken({ provider: 'google', token: 'your-id-token' }) ``` # JavaScript Reference signInWithOtp() ## Examples ### Sign in with email ```js const { data, error } = await supabase.auth.signInWithOtp({ email: 'example@email.com', options: { emailRedirectTo: 'https://example.com/welcome' } }) ``` ### Sign in with SMS OTP ```js const { data, error } = await supabase.auth.signInWithOtp({ phone: '+13334445555', }) ``` ### Sign in with WhatsApp OTP ```js const { data, error } = await supabase.auth.signInWithOtp({ phone: '+13334445555', options: { channel:'whatsapp', } }) ``` # JavaScript Reference signInWithOAuth() ## Examples ### Sign in using a third-party provider ```js const { data, error } = await supabase.auth.signInWithOAuth({ provider: 'github' }) ``` ### Sign in using a third-party provider with redirect ```js const { data, error } = await supabase.auth.signInWithOAuth({ provider: 'github', options: { redirectTo: 'https://example.com/welcome' } }) ``` ### Sign in with scopes and access provider tokens ```js // Register this immediately after calling createClient! // Because signInWithOAuth causes a redirect, you need to fetch the // provider tokens from the callback. supabase.auth.onAuthStateChange((event, session) => { if (session && session.provider_token) { window.localStorage.setItem('oauth_provider_token', session.provider_token) } if (session && session.provider_refresh_token) { window.localStorage.setItem('oauth_provider_refresh_token', session.provider_refresh_token) } if (event === 'SIGNED_OUT') { window.localStorage.removeItem('oauth_provider_token') window.localStorage.removeItem('oauth_provider_refresh_token') } }) // Call this on your Sign in with GitHub button to initiate OAuth // with GitHub with the requested elevated scopes. await supabase.auth.signInWithOAuth({ provider: 'github', options: { scopes: 'repo gist notifications' } }) ``` # JavaScript Reference signInWithSSO() ## Examples ### Sign in with email domain ```js // You can extract the user's email domain and use it to trigger the // authentication flow with the correct identity provider. const { data, error } = await supabase.auth.signInWithSSO({ domain: 'company.com' }) if (data?.url) { // redirect the user to the identity provider's authentication flow window.location.href = data.url } ``` ### Sign in with provider UUID ```js // Useful when you need to map a user's sign in request according // to different rules that can't use email domains. const { data, error } = await supabase.auth.signInWithSSO({ providerId: '21648a9d-8d5a-4555-a9d1-d6375dc14e92' }) if (data?.url) { // redirect the user to the identity provider's authentication flow window.location.href = data.url } ``` # JavaScript Reference signInWithWeb3() ## Examples ### Sign in with Solana or Ethereum (Window API) ```js // uses window.ethereum for the wallet const { data, error } = await supabase.auth.signInWithWeb3({ chain: 'ethereum', statement: 'I accept the Terms of Service at https://example.com/tos' }) // uses window.solana for the wallet const { data, error } = await supabase.auth.signInWithWeb3({ chain: 'solana', statement: 'I accept the Terms of Service at https://example.com/tos' }) ``` ### Sign in with Ethereum (Message and Signature) ```js const { data, error } = await supabase.auth.signInWithWeb3({ chain: 'ethereum', message: '', signature: '', }) ``` ### Sign in with Solana (Brave) ```js const { data, error } = await supabase.auth.signInWithWeb3({ chain: 'solana', statement: 'I accept the Terms of Service at https://example.com/tos', wallet: window.braveSolana }) ``` ### Sign in with Solana (Wallet Adapter) ```jsx function SignInButton() { const wallet = useWallet() return ( <> {wallet.connected ? ( ) : ( )} ) } function App() { const endpoint = clusterApiUrl('devnet') const wallets = useMemo(() => [], []) return ( ) } ``` # JavaScript Reference getClaims() ## Examples ### Get JWT claims, header and signature ```js const { data, error } = await supabase.auth.getClaims() ``` # JavaScript Reference signOut() ## Examples ### Sign out (all sessions) ```js const { error } = await supabase.auth.signOut() ``` ### Sign out (current session) ```js const { error } = await supabase.auth.signOut({ scope: 'local' }) ``` ### Sign out (other sessions) ```js const { error } = await supabase.auth.signOut({ scope: 'others' }) ``` # JavaScript Reference resetPasswordForEmail() ## Examples ### Reset password ```js const { data, error } = await supabase.auth.resetPasswordForEmail(email, { redirectTo: 'https://example.com/update-password', }) ``` ### Reset password (React) ```js /** * Step 1: Send the user an email to get a password reset token. * This email contains a link which sends the user back to your application. */ const { data, error } = await supabase.auth .resetPasswordForEmail('user@email.com') /** * Step 2: Once the user is redirected back to your application, * ask the user to reset their password. */ useEffect(() => { supabase.auth.onAuthStateChange(async (event, session) => { if (event == "PASSWORD_RECOVERY") { const newPassword = prompt("What would you like your new password to be?"); const { data, error } = await supabase.auth .updateUser({ password: newPassword }) if (data) alert("Password updated successfully!") if (error) alert("There was an error updating your password.") } }) }, []) ``` # JavaScript Reference verifyOtp() ## Examples ### Verify Signup One-Time Password (OTP) ```js const { data, error } = await supabase.auth.verifyOtp({ email, token, type: 'email'}) ``` ### Verify SMS One-Time Password (OTP) ```js const { data, error } = await supabase.auth.verifyOtp({ phone, token, type: 'sms'}) ``` ### Verify Email Auth (Token Hash) ```js const { data, error } = await supabase.auth.verifyOtp({ token_hash: tokenHash, type: 'email'}) ``` # JavaScript Reference getSession() ## Examples ### Get the session data ```js const { data, error } = await supabase.auth.getSession() ``` # JavaScript Reference refreshSession() ## Examples ### Refresh session using the current session ```js const { data, error } = await supabase.auth.refreshSession() const { session, user } = data ``` ### Refresh session using a refresh token ```js const { data, error } = await supabase.auth.refreshSession({ refresh_token }) const { session, user } = data ``` # JavaScript Reference getUser() ## Examples ### Get the logged in user with the current existing session ```js const { data: { user } } = await supabase.auth.getUser() ``` ### Get the logged in user with a custom access token jwt ```js const { data: { user } } = await supabase.auth.getUser(jwt) ``` # JavaScript Reference updateUser() ## Examples ### Update the email for an authenticated user ```js const { data, error } = await supabase.auth.updateUser({ email: 'new@email.com' }) ``` ### Update the phone number for an authenticated user ```js const { data, error } = await supabase.auth.updateUser({ phone: '123456789' }) ``` ### Update the password for an authenticated user ```js const { data, error } = await supabase.auth.updateUser({ password: 'new password' }) ``` ### Update the user's metadata ```js const { data, error } = await supabase.auth.updateUser({ data: { hello: 'world' } }) ``` ### Update the user's password with a nonce ```js const { data, error } = await supabase.auth.updateUser({ password: 'new password', nonce: '123456' }) ``` # JavaScript Reference getUserIdentities() ## Examples ### Returns a list of identities linked to the user ```js const { data, error } = await supabase.auth.getUserIdentities() ``` # JavaScript Reference linkIdentity() ## Examples ### Link an identity to a user ```js const { data, error } = await supabase.auth.linkIdentity({ provider: 'github' }) ``` # JavaScript Reference unlinkIdentity() ## Examples ### Unlink an identity ```js // retrieve all identities linked to a user const identities = await supabase.auth.getUserIdentities() // find the google identity const googleIdentity = identities.find( identity => identity.provider === 'google' ) // unlink the google identity const { error } = await supabase.auth.unlinkIdentity(googleIdentity) ``` # JavaScript Reference reauthenticate() ## Examples ### Send reauthentication nonce ```js const { error } = await supabase.auth.reauthenticate() ``` # JavaScript Reference resend() ## Examples ### Resend an email signup confirmation ```js const { error } = await supabase.auth.resend({ type: 'signup', email: 'email@example.com', options: { emailRedirectTo: 'https://example.com/welcome' } }) ``` ### Resend a phone signup confirmation ```js const { error } = await supabase.auth.resend({ type: 'sms', phone: '1234567890' }) ``` ### Resend email change email ```js const { error } = await supabase.auth.resend({ type: 'email_change', email: 'email@example.com' }) ``` ### Resend phone change OTP ```js const { error } = await supabase.auth.resend({ type: 'phone_change', phone: '1234567890' }) ``` # JavaScript Reference setSession() ## Examples ### Set the session ```js const { data, error } = await supabase.auth.setSession({ access_token, refresh_token }) ``` # JavaScript Reference exchangeCodeForSession() ## Examples ### Exchange Auth Code ```js supabase.auth.exchangeCodeForSession('34e770dd-9ff9-416c-87fa-43b31d7ef225') ``` # JavaScript Reference startAutoRefresh() ## Examples ### Start and stop auto refresh in React Native ```js import { AppState } from 'react-native' // make sure you register this only once! AppState.addEventListener('change', (state) => { if (state === 'active') { supabase.auth.startAutoRefresh() } else { supabase.auth.stopAutoRefresh() } }) ``` # JavaScript Reference stopAutoRefresh() ## Examples ### Start and stop auto refresh in React Native ```js import { AppState } from 'react-native' // make sure you register this only once! AppState.addEventListener('change', (state) => { if (state === 'active') { supabase.auth.startAutoRefresh() } else { supabase.auth.stopAutoRefresh() } }) ``` # JavaScript Reference ## Examples # JavaScript Reference Overview ## Examples # JavaScript Reference mfa.enroll() ## Examples ### Enroll a time-based, one-time password (TOTP) factor ```js const { data, error } = await supabase.auth.mfa.enroll({ factorType: 'totp', friendlyName: 'your_friendly_name' }) // Use the id to create a challenge. // The challenge can be verified by entering the code generated from the authenticator app. // The code will be generated upon scanning the qr_code or entering the secret into the authenticator app. const { id, type, totp: { qr_code, secret, uri }, friendly_name } = data const challenge = await supabase.auth.mfa.challenge({ factorId: id }); ``` ### Enroll a Phone Factor ```js const { data, error } = await supabase.auth.mfa.enroll({ factorType: 'phone', friendlyName: 'your_friendly_name', phone: '+12345678', }) // Use the id to create a challenge and send an SMS with a code to the user. const { id, type, friendly_name, phone } = data const challenge = await supabase.auth.mfa.challenge({ factorId: id }); ``` # JavaScript Reference mfa.challenge() ## Examples ### Create a challenge for a factor ```js const { data, error } = await supabase.auth.mfa.challenge({ factorId: '34e770dd-9ff9-416c-87fa-43b31d7ef225' }) ``` ### Create a challenge for a phone factor ```js const { data, error } = await supabase.auth.mfa.challenge({ factorId: '34e770dd-9ff9-416c-87fa-43b31d7ef225', }) ``` ### Create a challenge for a phone factor (WhatsApp) ```js const { data, error } = await supabase.auth.mfa.challenge({ factorId: '34e770dd-9ff9-416c-87fa-43b31d7ef225', channel: 'whatsapp', }) ``` # JavaScript Reference mfa.verify() ## Examples ### Verify a challenge for a factor ```js const { data, error } = await supabase.auth.mfa.verify({ factorId: '34e770dd-9ff9-416c-87fa-43b31d7ef225', challengeId: '4034ae6f-a8ce-4fb5-8ee5-69a5863a7c15', code: '123456' }) ``` # JavaScript Reference mfa.challengeAndVerify() ## Examples ### Create and verify a challenge for a factor ```js const { data, error } = await supabase.auth.mfa.challengeAndVerify({ factorId: '34e770dd-9ff9-416c-87fa-43b31d7ef225', code: '123456' }) ``` # JavaScript Reference mfa.unenroll() ## Examples ### Unenroll a factor ```js const { data, error } = await supabase.auth.mfa.unenroll({ factorId: '34e770dd-9ff9-416c-87fa-43b31d7ef225', }) ``` # JavaScript Reference mfa.getAuthenticatorAssuranceLevel() ## Examples ### Get the AAL details of a session ```js const { data, error } = await supabase.auth.mfa.getAuthenticatorAssuranceLevel() const { currentLevel, nextLevel, currentAuthenticationMethods } = data ``` ### Get the AAL details for a specific JWT ```js const { data, error } = await supabase.auth.mfa.getAuthenticatorAssuranceLevel(jwt) ``` # JavaScript Reference ## Examples # JavaScript Reference OAuth Server API ## Examples # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference AuthOAuthServerApi.revokeGrant() ## Examples # JavaScript Reference Overview ## Examples ### Create server-side auth client ```js import { createClient } from '@supabase/supabase-js' const supabase = createClient(supabase_url, service_role_key, { auth: { autoRefreshToken: false, persistSession: false } }) // Access auth admin api const adminAuthClient = supabase.auth.admin ``` # JavaScript Reference getUserById() ## Examples ### Fetch the user object using the access_token jwt ```js const { data, error } = await supabase.auth.admin.getUserById(1) ``` # JavaScript Reference listUsers() ## Examples ### Get a page of users ```js const { data: { users }, error } = await supabase.auth.admin.listUsers() ``` ### Paginated list of users ```js const { data: { users }, error } = await supabase.auth.admin.listUsers({ page: 1, perPage: 1000 }) ``` # JavaScript Reference createUser() ## Examples ### With custom user metadata ```js const { data, error } = await supabase.auth.admin.createUser({ email: 'user@email.com', password: 'password', user_metadata: { name: 'Yoda' } }) ``` ### Auto-confirm the user's email ```js const { data, error } = await supabase.auth.admin.createUser({ email: 'user@email.com', email_confirm: true }) ``` ### Auto-confirm the user's phone number ```js const { data, error } = await supabase.auth.admin.createUser({ phone: '1234567890', phone_confirm: true }) ``` # JavaScript Reference deleteUser() ## Examples ### Removes a user ```js const { data, error } = await supabase.auth.admin.deleteUser( '715ed5db-f090-4b8c-a067-640ecee36aa0' ) ``` # JavaScript Reference inviteUserByEmail() ## Examples ### Invite a user ```js const { data, error } = await supabase.auth.admin.inviteUserByEmail('email@example.com') ``` # JavaScript Reference generateLink() ## Examples ### Generate a signup link ```js const { data, error } = await supabase.auth.admin.generateLink({ type: 'signup', email: 'email@example.com', password: 'secret' }) ``` ### Generate an invite link ```js const { data, error } = await supabase.auth.admin.generateLink({ type: 'invite', email: 'email@example.com' }) ``` ### Generate a magic link ```js const { data, error } = await supabase.auth.admin.generateLink({ type: 'magiclink', email: 'email@example.com' }) ``` ### Generate a recovery link ```js const { data, error } = await supabase.auth.admin.generateLink({ type: 'recovery', email: 'email@example.com' }) ``` ### Generate links to change current email address ```js // generate an email change link to be sent to the current email address const { data, error } = await supabase.auth.admin.generateLink({ type: 'email_change_current', email: 'current.email@example.com', newEmail: 'new.email@example.com' }) // generate an email change link to be sent to the new email address const { data, error } = await supabase.auth.admin.generateLink({ type: 'email_change_new', email: 'current.email@example.com', newEmail: 'new.email@example.com' }) ``` # JavaScript Reference updateUserById() ## Examples ### Updates a user's email ```js const { data: user, error } = await supabase.auth.admin.updateUserById( '11111111-1111-1111-1111-111111111111', { email: 'new@email.com' } ) ``` ### Updates a user's password ```js const { data: user, error } = await supabase.auth.admin.updateUserById( '6aa5d0d4-2a9f-4483-b6c8-0cf4c6c98ac4', { password: 'new_password' } ) ``` ### Updates a user's metadata ```js const { data: user, error } = await supabase.auth.admin.updateUserById( '6aa5d0d4-2a9f-4483-b6c8-0cf4c6c98ac4', { user_metadata: { hello: 'world' } } ) ``` ### Updates a user's app_metadata ```js const { data: user, error } = await supabase.auth.admin.updateUserById( '6aa5d0d4-2a9f-4483-b6c8-0cf4c6c98ac4', { app_metadata: { plan: 'trial' } } ) ``` ### Confirms a user's email address ```js const { data: user, error } = await supabase.auth.admin.updateUserById( '6aa5d0d4-2a9f-4483-b6c8-0cf4c6c98ac4', { email_confirm: true } ) ``` ### Confirms a user's phone number ```js const { data: user, error } = await supabase.auth.admin.updateUserById( '6aa5d0d4-2a9f-4483-b6c8-0cf4c6c98ac4', { phone_confirm: true } ) ``` ### Ban a user for 100 years ```js const { data: user, error } = await supabase.auth.admin.updateUserById( '6aa5d0d4-2a9f-4483-b6c8-0cf4c6c98ac4', { ban_duration: '876000h' } ) ``` # JavaScript Reference ## Examples # JavaScript Reference mfa.deleteFactor() ## Examples ### Delete a factor for a user ```js const { data, error } = await supabase.auth.admin.mfa.deleteFactor({ id: '34e770dd-9ff9-416c-87fa-43b31d7ef225', userId: 'a89baba7-b1b7-440f-b4bb-91026967f66b', }) ``` # JavaScript Reference ## Examples ### List all factors for a user ```js const { data, error } = await supabase.auth.admin.mfa.listFactors() ``` # JavaScript Reference OAuth Admin API ## Examples # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference invoke() ## Examples ### Basic invocation ```js const { data, error } = await supabase.functions.invoke('hello', { body: { foo: 'bar' } }) ``` ### Error handling ```js import { FunctionsHttpError, FunctionsRelayError, FunctionsFetchError } from "@supabase/supabase-js"; const { data, error } = await supabase.functions.invoke('hello', { headers: { "my-custom-header": 'my-custom-header-value' }, body: { foo: 'bar' } }) if (error instanceof FunctionsHttpError) { const errorMessage = await error.context.json() console.log('Function returned an error', errorMessage) } else if (error instanceof FunctionsRelayError) { console.log('Relay error:', error.message) } else if (error instanceof FunctionsFetchError) { console.log('Fetch error:', error.message) } ``` ### Passing custom headers ```js const { data, error } = await supabase.functions.invoke('hello', { headers: { "my-custom-header": 'my-custom-header-value' }, body: { foo: 'bar' } }) ``` ### Calling with DELETE HTTP verb ```js const { data, error } = await supabase.functions.invoke('hello', { headers: { "my-custom-header": 'my-custom-header-value' }, body: { foo: 'bar' }, method: 'DELETE' }) ``` ### Invoking a Function in the UsEast1 region ```js import { createClient, FunctionRegion } from '@supabase/supabase-js' const { data, error } = await supabase.functions.invoke('hello', { body: { foo: 'bar' }, region: FunctionRegion.UsEast1 }) ``` ### Calling with GET HTTP verb ```js const { data, error } = await supabase.functions.invoke('hello', { headers: { "my-custom-header": 'my-custom-header-value' }, method: 'GET' }) ``` ### Example 7 ```ts const { data, error } = await functions.invoke('hello-world', { body: { name: 'Ada' }, }) ``` # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference removeChannel() ## Examples ### Removes a channel ```js supabase.removeChannel(myChannel) ``` # JavaScript Reference removeAllChannels() ## Examples ### Remove all channels ```js supabase.removeAllChannels() ``` # JavaScript Reference getChannels() ## Examples ### Get all channels ```js const channels = supabase.getChannels() ``` # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference Overview ## Examples # JavaScript Reference ## Examples # JavaScript Reference listBuckets() ## Examples # JavaScript Reference getBucket() ## Examples # JavaScript Reference createBucket() ## Examples # JavaScript Reference emptyBucket() ## Examples # JavaScript Reference updateBucket() ## Examples # JavaScript Reference deleteBucket() ## Examples # JavaScript Reference from.upload() ## Examples # JavaScript Reference from.update() ## Examples # JavaScript Reference from.move() ## Examples # JavaScript Reference from.copy() ## Examples # JavaScript Reference from.createSignedUrl() ## Examples # JavaScript Reference from.createSignedUrls() ## Examples # JavaScript Reference from.createSignedUploadUrl() ## Examples # JavaScript Reference from.uploadToSignedUrl() ## Examples # JavaScript Reference from.getPublicUrl() ## Examples # JavaScript Reference from.download() ## Examples # JavaScript Reference from.remove() ## Examples # JavaScript Reference from.list() ## Examples # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference Overview ## Examples # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference Overview ## Examples # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference VectorBucketScope.createIndex() ## Examples # JavaScript Reference VectorBucketScope.deleteIndex() ## Examples # JavaScript Reference VectorBucketScope.getIndex() ## Examples # JavaScript Reference VectorBucketScope.listIndexes() ## Examples # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference ## Examples # JavaScript Reference ## Examples