JavaScript: Initializing | Supabase Docs (original) (raw)
- Introduction
- Installing
- Initializing
- TypeScript support
- Database
- Fetch data
- Insert data
- Update data
- Upsert data
- Delete data
- Call a Postgres function
- Using filters
- Column is equal to a value
- Column is not equal to a value
- Column is greater than a value
- Column is greater than or equal to a value
- Column is less than a value
- Column is less than or equal to a value
- Column matches a pattern
- Column matches a case-insensitive pattern
- Column is a value
- Column is in an array
- Column contains every element in a value
- Contained by value
- Greater than a range
- Greater than or equal to a range
- Less than a range
- Less than or equal to a range
- Mutually exclusive to a range
- With a common element
- Match a string
- Match an associated value
- Don't match the filter
- Match at least one filter
- Match the filter
- Using modifiers
- Return data after inserting
- Order the results
- Limit the number of rows returned
- Limit the query to a range
- Set an abort signal
- Retrieve one row of data
- Retrieve zero or one row of data
- Retrieve as a CSV
- Override type of successful response
- Partially override or replace type of successful response
- Using explain
- Auth
- Overview
- Create a new user
- Listen to auth events
- Create an anonymous user
- Sign in a user
- Sign in with ID token (native sign-in)
- Sign in a user through OTP
- Sign in a user through OAuth
- Sign in a user through SSO
- Sign in a user through Web3 (Solana, Ethereum)
- Get user claims from verified JWT
- Sign out a user
- Send a password reset request
- Verify and log in through OTP
- Retrieve a session
- Retrieve a new session
- Retrieve a user
- Update a user
- Retrieve identities linked to a user
- Link an identity to a user
- Unlink an identity from a user
- Send a password reauthentication nonce
- Resend an OTP
- Set the session data
- Exchange an auth code for a session
- Start auto-refresh session (non-browser)
- Stop auto-refresh session (non-browser)
- Initialize client session
- Auth MFA
- Enroll a factor
- Create a challenge
- Verify a challenge
- Create and verify a challenge
- Unenroll a factor
- Get Authenticator Assurance Level
- List all factors for current user
- OAuth Server
- Get authorization details
- Approve authorization
- Deny authorization
- List grants
- Revoke grant
- Auth Admin
- Retrieve a user
- List all users
- Create a user
- Delete a user
- Send an email invite link
- Generate an email link
- Update a user
- Sign out a user (admin)
- Delete a factor for a user
- List all factors for a user (admin)
- OAuth Admin
- List OAuth clients
- Get OAuth client
- Create OAuth client
- Update OAuth client
- Delete OAuth client
- Regenerate client secret
- Edge Functions
- Invokes a Supabase Edge Function.
- Realtime
- Subscribe to channel
- Unsubscribe from a channel
- Unsubscribe from all channels
- Retrieve all channels
- Broadcast a message
- Storage
- File Buckets
- Access a storage bucket
- List all buckets
- Retrieve a bucket
- Create a bucket
- Empty a bucket
- Update a bucket
- Delete a bucket
- Upload a file
- Replace an existing file
- Move an existing file
- Copy an existing file
- Create a signed URL
- Create signed URLs
- Create signed upload URL
- Upload to a signed URL
- Retrieve public URL
- Download a file
- Delete files in a bucket
- List all files in a bucket
- Check if file exists
- Get file metadata
- List files (v2)
- Convert file to base64
- Analytics Buckets
- Access an analytics bucket
- Create a new analytics bucket
- List analytics buckets
- Delete an analytics bucket
- Vector Buckets
- Access a vector bucket
- Create a vector bucket
- Delete a vector bucket
- Retrieve a vector bucket
- List all vector buckets
- Create a vector index
- Delete a vector index
- Retrieve a vector index
- List all vector indexes
- Access a vector index
- Delete vectors from index
- Retrieve vectors from index
- List vectors in index
- Add vectors to index
- Search vectors in index
Create a new client for use in the browser.
Parameters
supabaseUrl
(Required)
The unique Supabase URL which is supplied when you create a new project in your project dashboard.
supabaseKey
(Required)
The unique Supabase Key which is supplied when you create a new project in your project dashboard.
options
(Optional)
Examples
Creating a client
import { createClient } from '@supabase/supabase-js'
// Create a single supabase client for interacting with your database
const supabase = createClient('https://xyzcompany.supabase.co', 'publishable-or-anon-key')
With a custom domain
import { createClient } from '@supabase/supabase-js'
// Use a custom domain as the supabase URL
const supabase = createClient('https://my-custom-domain.com', 'publishable-or-anon-key')
With additional parameters
import { createClient } from '@supabase/supabase-js'
const options = {
db: {
schema: 'public',
},
auth: {
autoRefreshToken: true,
persistSession: true,
detectSessionInUrl: true
},
global: {
headers: { 'x-my-custom-header': 'my-app-name' },
},
}
const supabase = createClient("https://xyzcompany.supabase.co", "publishable-or-anon-key", options)
With custom schemas
import { createClient } from '@supabase/supabase-js'
const supabase = createClient('https://xyzcompany.supabase.co', 'publishable-or-anon-key', {
// Provide a custom schema. Defaults to "public".
db: { schema: 'other_schema' }
})
Custom fetch implementation
import { createClient } from '@supabase/supabase-js'
const supabase = createClient('https://xyzcompany.supabase.co', 'publishable-or-anon-key', {
global: { fetch: fetch.bind(globalThis) }
})
React Native options with AsyncStorage
import 'react-native-url-polyfill/auto'
import { createClient } from '@supabase/supabase-js'
import AsyncStorage from "@react-native-async-storage/async-storage";
const supabase = createClient("https://xyzcompany.supabase.co", "publishable-or-anon-key", {
auth: {
storage: AsyncStorage,
autoRefreshToken: true,
persistSession: true,
detectSessionInUrl: false,
},
});
React Native options with Expo SecureStore
import 'react-native-url-polyfill/auto'
import { createClient } from '@supabase/supabase-js'
import AsyncStorage from '@react-native-async-storage/async-storage';
import * as SecureStore from 'expo-secure-store';
import * as aesjs from 'aes-js';
import 'react-native-get-random-values';
// As Expo's SecureStore does not support values larger than 2048
// bytes, an AES-256 key is generated and stored in SecureStore, while
// it is used to encrypt/decrypt values stored in AsyncStorage.
class LargeSecureStore {
private async _encrypt(key: string, value: string) {
const encryptionKey = crypto.getRandomValues(new Uint8Array(256 / 8));
const cipher = new aesjs.ModeOfOperation.ctr(encryptionKey, new aesjs.Counter(1));
const encryptedBytes = cipher.encrypt(aesjs.utils.utf8.toBytes(value));
await SecureStore.setItemAsync(key, aesjs.utils.hex.fromBytes(encryptionKey));
return aesjs.utils.hex.fromBytes(encryptedBytes);
}
private async _decrypt(key: string, value: string) {
const encryptionKeyHex = await SecureStore.getItemAsync(key);
if (!encryptionKeyHex) {
return encryptionKeyHex;
}
const cipher = new aesjs.ModeOfOperation.ctr(aesjs.utils.hex.toBytes(encryptionKeyHex), new aesjs.Counter(1));
const decryptedBytes = cipher.decrypt(aesjs.utils.hex.toBytes(value));
return aesjs.utils.utf8.fromBytes(decryptedBytes);
}
async getItem(key: string) {
const encrypted = await AsyncStorage.getItem(key);
if (!encrypted) { return encrypted; }
return await this._decrypt(key, encrypted);
}
async removeItem(key: string) {
await AsyncStorage.removeItem(key);
await SecureStore.deleteItemAsync(key);
}
async setItem(key: string, value: string) {
const encrypted = await this._encrypt(key, value);
await AsyncStorage.setItem(key, encrypted);
}
}
const supabase = createClient("https://xyzcompany.supabase.co", "publishable-or-anon-key", {
auth: {
storage: new LargeSecureStore(),
autoRefreshToken: true,
persistSession: true,
detectSessionInUrl: false,
},
});
Example 8
import { createClient } from '@supabase/supabase-js'
const supabase = createClient('https://xyzcompany.supabase.co', 'public-anon-key')
const { data } = await supabase.from('profiles').select('*')