Quickstart#
Get data flowing in 5 minutes.
1. Install the SDK#
npm install @rafikidb/sdk
Bash2. Create a client#
import { createClient } from '@rafikidb/sdk';
const db = createClient({
projectId: process.env.RAFIKIDB_PROJECT_ID!,
apiKey: process.env.RAFIKIDB_API_KEY!,
baseUrl: 'https://api.rafikidb.com/api/v1', // optional
persistSession: true, // keep the user session across refreshes
});
TypeScriptSecurity: keep the API key server-side. For client apps, the key is scoped to your project; combine it with project-user auth so RLS decides what each user can do.
3. Write and read data#
// Insert
const { data } = await db.from('profiles').insert({
full_name: 'Asha Mwinyi',
nationality: 'Tanzania',
});
// Read with filters
const rows = await db
.from('profiles')
.select('id, full_name, nationality')
.eq('nationality', 'Tanzania')
.order('created_at', { ascending: false })
.limit(25);
TypeScript4. Authenticate a user#
const { data } = await db.auth.signup({
email: 'user@example.com',
password: 'strong-pass1',
full_name: 'Asha Mwinyi',
phone: '+255712345678',
});
const { data: session } = await db.auth.login({
email: 'user@example.com',
password: 'strong-pass1',
});
// session.tokens.access_token - used automatically for RLS
TypeScript5. React in real time#
import { useAuth } from '@rafikidb/sdk/react';
function App({ db }) {
const { user, isAuthenticated, login, signOut } = useAuth(db);
// ...
}
db.realtime.subscribe('profiles', (event) => {
console.log(event.type, event.record); // INSERT / UPDATE / DELETE
});
TypeScript6. Done#
You now have data, auth and realtime. Next: