GiyanGiyan

Quickstart

Giyan works with the official supabase-js. These steps take you from an empty project to an app with users, data, files and realtime.

  1. Get your project URL and key

    Once you have access and have created a project in the panel, you need two things: the project URL, which looks like https://<ref>.giyanapp.ir, and the anon key. Both are on the project page in the panel.

  2. Install the library

    npm install @supabase/supabase-js
  3. Connect

    import { createClient } from '@supabase/supabase-js'
    
    const supabase = createClient(
      'https://<ref>.giyanapp.ir', // project URL, from the panel
      '<anon-key>'                 // anon key, from the panel
    )

    The anon key is meant for client-side code, provided RLS is enabled on your tables. Never put the service_role key in an app or a browser.

  4. Sign a user in

    Sign-in with email and password. Create the user with signUp or from Studio.

    const { data, error } = await supabase.auth.signInWithPassword({
      email: 'sara@example.com',
      password: 'a-long-password',
    })
    
    if (error) console.error(error.message)
    else console.log('signed in as', data.user.id)
  5. Create a table and enable RLS

    Run this SQL in Studio. With this policy, each user sees and changes only their own notes.

    create table public.notes (
      id bigint generated always as identity primary key,
      user_id uuid not null default auth.uid() references auth.users (id),
      body text not null,
      created_at timestamptz not null default now()
    );
    
    alter table public.notes enable row level security;
    
    create policy "own notes" on public.notes
      for all to authenticated
      using (user_id = auth.uid())
      with check (user_id = auth.uid());
  6. Write and read

    A signed-in user gets back only their own rows. RLS does that, not your code.

    const { error } = await supabase.from('notes').insert({ body: 'Hello Giyan' })
    
    const { data: notes } = await supabase
      .from('notes')
      .select('id, body, created_at')
      .order('created_at', { ascending: false })
  7. Upload a file

    First create a bucket and let each user write to their own folder:

    insert into storage.buckets (id, name) values ('avatars', 'avatars');
    
    create policy "own folder" on storage.objects
      for all to authenticated
      using (bucket_id = 'avatars' and (storage.foldername(name))[1] = auth.uid()::text)
      with check (bucket_id = 'avatars' and (storage.foldername(name))[1] = auth.uid()::text);

    Then upload from your app:

    const { data: { user } } = await supabase.auth.getUser()
    
    // file is a File or Blob, for example from <input type="file">
    const { error } = await supabase.storage
      .from('avatars')
      .upload(`${user.id}/avatar.png`, file, { upsert: true })
  8. Listen to changes

    Add the table to the realtime publication:

    alter publication supabase_realtime add table public.notes;

    And subscribe in your app:

    const channel = supabase
      .channel('notes')
      .on(
        'postgres_changes',
        { event: 'INSERT', schema: 'public', table: 'notes' },
        (payload) => console.log('new note', payload.new)
      )
      .subscribe()

The rest is the supabase-js documentation. What Giyan does not have yet is listed on the features page.

Want to try it?

The Giyan panel is invite-only for now. Fill in the request form and we will review it.