Skip to content

Latest commit

 

History

History
144 lines (123 loc) · 2.36 KB

api.md

File metadata and controls

144 lines (123 loc) · 2.36 KB

API Documentation

Supabase API

Authentication

Sign Up

const { data, error } = await supabase.auth.signUp({
  email: '[email protected]',
  password: 'password'
});

Sign In

const { data, error } = await supabase.auth.signInWithPassword({
  email: '[email protected]',
  password: 'password'
});

Users

Create User Profile

const { data, error } = await supabase
  .from('users')
  .insert([
    {
      id: 'user_id',
      email: '[email protected]',
      full_name: 'John Doe',
      user_type: 'student'
    }
  ]);

Get User Profile

const { data, error } = await supabase
  .from('users')
  .select('*')
  .eq('id', 'user_id')
  .single();

Credentials

Issue Credential

const { data, error } = await supabase
  .from('credentials')
  .insert([
    {
      issuer_id: 'issuer_id',
      recipient_id: 'recipient_id',
      title: 'Degree Title',
      description: 'Description',
      blockchain_tx_hash: 'tx_hash'
    }
  ]);

Get Credentials

const { data, error } = await supabase
  .from('credentials')
  .select(`
    *,
    issuer:users!credentials_issuer_id_fkey(*),
    recipient:users!credentials_recipient_id_fkey(*)
  `)
  .or('issuer_id.eq.user_id,recipient_id.eq.user_id');

Web3 API

Connect Wallet

const address = await web3Service.connect();

Issue Credential

const txHash = await web3Service.issueCredential(
  recipientAddress,
  credentialHash
);

Verify Credential

const credential = await web3Service.verifyCredential(
  credentialId
);

Response Types

User

type User = {
  id: string;
  email: string;
  full_name: string;
  user_type: string;
  wallet_address: string | null;
};

Credential

type Credential = {
  id: string;
  title: string;
  description: string;
  issue_date: string;
  blockchain_tx_hash: string | null;
  issuer: User;
  recipient: User;
};

Error Handling

try {
  const result = await apiCall();
} catch (error) {
  if (error instanceof AuthError) {
    // Handle auth errors
  } else if (error instanceof DatabaseError) {
    // Handle database errors
  } else {
    // Handle other errors
  }
}

Rate Limits

  • Supabase: Depends on your plan
  • Web3: Depends on the network