https://supabase.com/ logo
Join Discord
Powered by
# help-and-questions
  • RLS Solution
    k

    kevlust

    05/05/2023, 3:48 PM
    I have 2 tables: posts and comments. In order to simplify things and optimize for performance, I have my posts table keep track of a post's comment count in a column called estimated_comment_count . The idea is that whenever a comment is added to a post, we increase the count, and whenever one is deleted, we decrease the count. My problem: with RLS enabled on my posts table (UPDATE access only if auth.uid() = post_author_user_id), I'm not able to edit these counts whenever a comment is added by a user different from the post author. I tried writing triggers that react to INSERTs and DELETEs on my comments table and update the counts on the posts table, but they don't work with that policy enabled. I tried writing a single insert_comment function that I call from the client (rpc) and takes care of the count updates, but it also doesn't work with that policy enabled. What's the best way to do this? I don't want a separate table to keep track of the counts because I want to avoid having too many JOINs. For similar reasons, I want to have that column on my posts table to optimize for performance. And it feels risky to remove the RLS policy for posts UPDATEs and allow anyone to make them. Any advice would be immensely helpful. Thanks!
    g
    • 2
    • 2
  • How to invoke an edge function with a GET request.?
    v

    ven

    05/05/2023, 4:39 PM
    I am trying this
    Copy code
    async function getOne() {
        const { data, error } = await supabaseClient.functions.invoke("contact", {
            method: "GET",
            body: JSON.stringify({ id: "23" }),
        });
        console.log(data, error);
    }
    and get an error. how to send the request method? tia ❤️
    g
    • 2
    • 31
  • How can I make one of the properties in user_metadata unique?
    w

    Whoman

    05/05/2023, 6:28 PM
    I have username and pfp (avatar) in my user_metadata, how can i make only username unique? i dont want to have unique avatars
    g
    • 2
    • 8
  • Default column value for User Management Starter (public profiles)
    s

    Sig

    05/05/2023, 6:43 PM
    I'm using Supabase Auth and created a public "profiles" table using the User Management Starter query. I want to set a default value for the
    avatar_url
    to 'avatar.svg' which is hosted in my avatars bucket. I can manually add the value to a row, but when a new user is created it always defaults to
    null
    in stead. I have attached a screenshot of the column settings, any suggestions are highly appreciated.

    https://cdn.discordapp.com/attachments/1104116223647686817/1104116560446107718/CleanShot_2023-05-05_at_20.44.39.png▾

    g
    • 2
    • 6
  • How to create user profile only after the email is verified?
    a

    alpha_

    05/05/2023, 7:02 PM
    Hi all! I'm building a dashboard web app with supabase as backend, I want to store
    full_name
    in profiles table and just implemented the same using user management starter. Everything was pretty good so far but, now when I look at the profiles table, it looks like when someone signs up, a profile is being created (as per the SQL query and trigger from user management starter) even without their email being verified. I probed google a bit, but couldn't find a clear solution on how to create a user profile only when the user email is being verified?
    v
    • 2
    • 2
  • Unable to retrieve data by user ID
    r

    Revaycolizer

    05/05/2023, 7:09 PM
    I tried to fetch user details from table category but by filtering through ID but I get null Array
    Copy code
    const User =async()=>{
        const {data:{user}} =  await supabase.auth.getUser()
        if(user){
            const { data:files } = await supabase
            .from('category')
            .select().eq('user',user.id)
            console.log(files)
            if(files){
              console.log(files)
              const posts = []
            for (const file of files) {
              const { data:post } = await supabase.storage.from('files').createSignedUrl(file.vname, 3600000, {
                transform: {
                  width: 200,
                  height: 200,},
                })
             if(post){
                posts.push(post)
              // const diwn = await supabase.from('category').select().eq('vname',file.name)
              setDownload(posts)
              // setDfiles(diwn)
            }
             
            }
          }
    g
    • 2
    • 13
  • Error: Project already initialized but supabase\config.toml does not exist.
    b

    BrendanH117

    05/05/2023, 7:32 PM
    I'm trying to do a clean install of local development, but running
    supabase init --debug
    returns
    Error: Project already initialized. Remove supabase\config.toml to reinitialize.
    . I'm running this in a project directory where only
    .vscode
    exists, no other files or folders. I can't find any other config.toml files on my PC. Any help or pointers is appreciated.
    s
    • 2
    • 1
  • Getting unacceptableStatusCode(406) on Swift when trying to query
    l

    leleco

    05/05/2023, 7:49 PM
    Hi, I'm new to Supabase and I'm trying to execute this query on my iOS app, but I keep getting this unacceptableStatusCode(406) error. Can anyone help, please? Thanks!
    Copy code
    let client = SupabaseClient(supabaseURL: URL(string: "myurl")!, supabaseKey: "my-api-key")
        
        func getAllLeagues() {
            let query = client.database.from("Leagues").select(columns: "id").single();
            Task {
                do {
                    let response: [League] = try await query.execute().value
                    print(response)
                } catch {
                    print(error)
                }
            }
        }
    g
    • 2
    • 6
  • Hand-rolled JWT -> Supabase Auth session?
    t

    timm

    05/05/2023, 8:08 PM
    Is this even possible? Current situation: * I programmatically create users in Supabase db (
    supabase.auth.admin.createUser
    ) * I generate a JWT using those details. * I can pass the JWT token to client via an API, and inject it into `createClient`'s
    global.headers
    , which works (for a while) *
    supabase-auth-token
    cookie does not get set. * Stops working once JWT expires. My hope was to somehow "programmatically" sign-in as a user, and let Supabase Auth handle everything. Is this possible, using JWT or another approach?
    g
    • 2
    • 8
  • Fetching data by Id but takes a lot of time to render remaining data
    r

    Revaycolizer

    05/05/2023, 8:12 PM
    wondering if i can speedup my function as it fetches and renders a first item and then takes 5 minutes to render the rest
    Copy code
    const User =async()=>{
        const {data:{user}} =  await supabase.auth.getUser()
        if(user){
            const { data:files } = await supabase
            .from('category')
            .select().eq('user',user.id)
    
            if(files){
              const posts = []
            for (const file of files) {
              const { data:post } = await supabase.storage.from('files').createSignedUrl(file.vname, 3600000, {
                transform: {
                  width: 200,
                  height: 200,},
                })
             if(post){
                posts.push(post)
              setDownload(posts)
            }
             
            }
          }
          
         
        }
      }
    o
    • 2
    • 2
  • (FIXED) Failed to create function: failed to create pg.functions: syntax error at or near "set"
    g

    garyaustin

    05/05/2023, 9:17 PM
    UPDATE weather SET temp_lo = temp_lo+1, temp_hi = temp_lo+15, prcp = DEFAULT
    Is the normal format for multiple columns. If multiple sets work, you at least need a comma.
    s
    • 2
    • 45
  • Can't retrieve additional user metadata (Nuxt)
    s

    SaltySesame

    05/05/2023, 9:36 PM
    I'm using Nuxt 3 + Supabase for my project. In my app I can create an account and login, both work fine. The login page redirects you to a profile page if you login successfully. The app sends additional user data when registering (first and last name for now). When I login, the **user **object that is returned contains **user_metadata **which contains first_name and** last_name**. But I can't access them for some reason. I get undefined. Why? Signup JS (Full code):
    Copy code
    js
    import {ref} from 'vue'
    const supabase  = useSupabaseClient()
    
    const firstName = ref('')
    const lastName = ref('')
    const email = ref('') 
    const password = ref('')
    
    async function register() {
      const {data, error} = supabase.auth.signUp({
        email: email.value,
        password: password.value,
        //additional user data
        options: {
          data: {
            first_name: firstName,
            last_name: lastName
          }
        }
      })
    }
    
    const user = useSupabaseUser()
    
    onMounted(()=>{
        watchEffect(()=>{
            if(user.value){
                navigateTo('/profile')
            }
        })
    })
    Below is the problematic code. Retrieval JS in profile page (Full code):
    Copy code
    js
    //unimportant (auth middleware)
    definePageMeta({
        middleware: [
            'auth'
        ]
    })
    
    //THE PROBLEM
    const user = useSupabaseUser() //user object (It's OK)
    const name = user.value.user_metadata.first_name //undefined
    //user_metadata alone works too
    (I'm pretty new to both. It's my first time using Supabase. Sorry if the question is bad or that's the wrong place to ask)
    g
    v
    • 3
    • 110
  • homebrew-supabase
    j

    joshu.a

    05/05/2023, 10:26 PM
    Trying to install the Supabase CLI via homebrew on my macbook but running into an issue, any ideas?

    https://cdn.discordapp.com/attachments/1104172395713019996/1104172396400873513/Screen_Shot_2023-05-05_at_6.25.13_PM.png▾

    s
    • 2
    • 2
  • Switching from password auth to GitHub?
    d

    dave

    05/05/2023, 10:41 PM
    I signed up for Supabase with an email/password; is it possible to switch to using GitHub?
    o
    • 2
    • 3
  • Cannot see what is wrong with this query
    s

    Sig

    05/05/2023, 11:50 PM
    I cannot see what is wrong with this query, I keep getting "Invalid SQL query" I'm fairly new to SQL, so any help is greatly appreciated.
    Copy code
    create table images (
        id integer not null generated by default as identity primary key,
        owner_id references auth.users on delete cascade not null,
        updated_at timestamp with time zone,
        image_url text not null,
        location text,
        camera text,
        aperture text,
        shutter text,
        iso text,
      );
    
    alter table images
      enable row level security;
    
    -- Create a policy to allow anyone to insert into the images table
    create policy "images are viewable by everyone." on images
      for select using (true);
      
    -- Create policy for anyone to inert images
    create policy "Anyone can insert new images." on images 
      for insert using (true);
    
    -- Create a policy to allow only owners to update their own images
    create policy "Owner can update their own images." on images
      for update using (auth.uid() = owner_id);
    
    -- Set up Storage!
    insert into storage.buckets (id, name)
      values ('image_bucket', 'image_bucket');
    
    -- Set up access controls for storage.
    -- See https://supabase.com/docs/guides/storage#policy-examples for more details.
    create policy "Images are publicly accessible." on storage.objects
      for select using (bucket_id = 'image_bucket');
    
    create policy "Anyone can upload an image." on storage.objects
      for insert with check (bucket_id = 'image_bucket');
    g
    • 2
    • 1
  • Is out of box chat module on Supabase roadmap
    j

    Jolly Joy

    05/06/2023, 1:50 AM
    A chat module is a common requirement for numerous applications, and since Supabase already offers an incredible product, it would be fantastic if you could provide built-in chat support like GetStream or CometChat. The necessary technical components exist, but currently, everyone seems to be creating their own logic for this widely-used feature at the platform level. I'd love to connect with anyone who has already built a chat system using Supabase. Please feel free to comment below or send me a DM!
    o
    • 2
    • 3
  • There has any way to create DB functions using the CLI?
    r

    rafael

    05/06/2023, 2:13 AM
    I'm wondering if there have any way to create DB functions/triggers using the CLI. I was creating this directly in the interface and would be nice to have all this information in my git. I know I can basically run:
    Copy code
    supabase db remote commit
    and a migration file will be created inside the supabase/migrations folder. But I'm not sure what is the proper way to create a new one and deploy it to production. Actually, would be really nice to be able to create those DB functions like Edge functions, and functions located in the functions folder etc (just to keep it organized) instead of in the same migration file. There is any good way to keep all organized?
    s
    • 2
    • 1
  • PKCE for email tokens?
    d

    dave

    05/06/2023, 5:02 AM
    Does PKCE do anything for email tokens?
    s
    • 2
    • 2
  • Date deleted after resuming supabase instance
    a

    AkashSh

    05/06/2023, 5:50 AM
    My data got deleted after I resumed my supabase instance from dashboard (it got blocked yesterday). Is there any way of getting it back?
    n
    • 2
    • 1
  • Insert array of objects with timestampz
    k

    Kai___

    05/06/2023, 5:57 AM
    I have 2 separate places in my code where I am inputting timestampz. The first one is an array of objects and submits with timestamp just fine. The issue is when I submit just one object and I am getting an error: {"code":"22023","details":null,"hint":null,"message":"time zone \"gmt-0400\" not recognized"} Why isn't this working? I also tried converting to: 6/9/2023, 8:00:00 PM -04 That is not working either.
  • Images uploaded have a max filesize of 768kb
    f

    Fluck

    05/06/2023, 5:59 AM
    Hi, I'm was having trouble uploading images to storage from SvelteKit. I feel like I figured it out, however whenever I upload an image that is bigger than 768kb it simply cuts off what it needs to reduce it to that size it seems. I feel as though this might be because I send things as a blob and decode it but I am not sure. I checked the limits and it is at 5mb so that is also not it. Here is the relevant code for the action:
    Copy code
    const dataUrls = formData.getAll('files')
      
        const imageUuidList = [];
        const promises = [];
        
        for (const file of dataUrls) {
            const imageId = uuid();
            imageUuidList.push(imageId);
            // Upload the File object to Supabase Storage
            promises.push(supabase.storage.from("listing_images").upload(imageId, decode(file), {
                contentType: 'image/*'
              })
            );
        }
    And here is the code for the form:
    Copy code
    let selectedImages: string[] = [];
        let selectedBlobs: string[] = [];
        let files: FileList;
    
        async function onChangeHandler(e: Event) {
        if (selectedImages.length + files.length > 6) {
            alert('You can only upload a maximum of 6 images.');
            return;
        }
        const file = files.item(0);
        if (file != null) {
            const reader = new FileReader();
            reader.readAsDataURL(file);
            reader.onload = (event) => {
                if(!event.target) return;
                const image = event.target.result as string;
                selectedImages.push(image);
                const data = image.split(',');
                
                selectedBlobs.push(data[1]);
                selectedBlobs = selectedBlobs.slice();
                selectedImages = selectedImages.slice();
            };
            
        }
        }
  • Auth UI Sign Up
    r

    RyanLuttrell

    05/06/2023, 6:08 AM
    Hey supabase! I'm wondering if there's a way to programmatically go directly to the sign up route for the Auth UI, rather than making a user see the sign in route first. Any and all help would be greatly appreciated 🙂
    d
    s
    • 3
    • 4
  • rookie question: is it possible to have a generated column?
    r

    rico.wtf

    05/06/2023, 6:23 AM
    I'm wondering if I can have a column
    full_name
    that merges
    first_name
    and
    last_name
  • tried turbo and now everything is a bit broken
    o

    Olyno

    05/06/2023, 5:20 PM
    Hi It looks like more an issue with Turbopack iteself than Supabase @Hexi
  • supabase typescript insert type error
    c

    chit

    05/06/2023, 11:25 AM
    I am trying to insert data to my supabase database
    export const supabase = createClient<Database>(supabaseUrl, supabaseAnonKey);
    supabase is created using this key, I also have the correct schema.ts
    Copy code
    export interface Database {
        public: {
            Tables: {
    ...
    but then when I try to insert stuff, it says my types are wrong, when that is the exact type definition in the schema.ts file

    https://cdn.discordapp.com/attachments/1104368222721032192/1104368223052365865/image.png▾

    v
    • 2
    • 4
  • ASAP: i want to select a specific id on purchase table why it is this wrong?
    m

    Mashwishi

    05/06/2023, 11:44 AM
    Copy code
    tsx
            const supabaseAccessToken = await session.getToken({
                template: 'Supabase'
            });
    
            const supabase = await supabaseClient(supabaseAccessToken);
    
            const { data } = await supabase
            .from('purchase')
            .eq('id', referenceNumber)
            .select()
    • 1
    • 1
  • How to do inner joins on select query's js
    h

    Hugos

    05/06/2023, 11:49 AM
    The experimental AI told me to use ``innerJoin`` (see picture) but that method simply doesn't exist so how can I query with inner joins I have my orders table:
    Copy code
    sql
    create table
      public.orders (
        id uuid not null,
        status public.order_status not null,
        city text not null,
        postal_code text not null,
        address text not null,
        customer_email text not null,
        created_at timestamp with time zone null default now(),
        constraint orders_2_pkey primary key (id)
      ) tablespace pg_default;
    And my order_products table:
    Copy code
    sql
    create table
      public.order_products (
        order_id uuid not null,
        product_id uuid not null,
        quantity integer not null,
        price double precision not null,
        constraint order_products_pkey primary key (order_id, product_id),
        constraint order_products_order_id_fkey foreign key (order_id) references orders (id),
        constraint order_products_product_id_fkey foreign key (product_id) references products (id)
      ) tablespace pg_default;
    I want to query an order along with the products from that order with the Javascript client, is this possible, if so, how? If not, what would be a work around.

    https://cdn.discordapp.com/attachments/1104374274766155796/1104374274921332848/image.png▾

    s
    • 2
    • 2
  • Real-time db with RLS only detecting delete actions?
    b

    bingbong

    05/06/2023, 12:28 PM
    Want to create a shared shopping list which detect changes in real time. But the combination of real-time db and rls seems to only detect delete actions in db. is this by design? Broadcasting and detection works fine for all action types when rls is disabled.
    g
    • 2
    • 1
  • Twilio - Setting Sender ID
    m

    Masini

    05/06/2023, 1:14 PM
    Hey guys 😃 First time posting here. I am currently working on a project with supabase and we are using Twilio as a messaging provider. The messaging service API supports a "From" parameter, which can be set as a user friendly name so that upon receiving the SMS the user will see the business name instead of the actual phone number. Unfortunately, I haven't found how I can change this parameter in Supabase. Is this feature even supported in Supabase?
  • PostgrestException (PostgrestException(message: Could not find a relationship between 'profiles' and
    a

    Agon

    05/06/2023, 1:31 PM
    Copy code
    Searched for a foreign key relationship between 'profiles' and 'users' in the schema 'public', but no matches were found.
    this happens when calling
    Copy code
    dart
    await Supabase.instance.client.rest
            .from('profiles')
            .select<PostgrestList>('*, users(*)')
    table
    Copy code
    profiles
    has a column
    Copy code
    user_id
    which is a foreign key pointing to table
    Copy code
    users
    rls is turned off
    g
    • 2
    • 15
1...203204205...230Latest