https://supabase.com/ logo
Join Discord
Powered by
# help-and-questions
  • Are types in mutations like this supported? If not, what's the alternative?
    w

    whaley

    09/25/2022, 2:20 PM
    Not sure what I'm doing wrong here tbh. What's the recommended way to do stuff like this?
    • 1
    • 4
  • code 'PGRST102', message 'All object keys must match'
    p

    pvtctrlalt

    09/25/2022, 2:45 PM
    Hey, Im trying to upload a largeish javascript object as json to the database just into one row and i keep getting that error. i haev already removed all null entries but it still get the error. main function
    Copy code
    export async function sendDeviceDetails() {
      const devd = await store.getDeviceInfo();
    console.log(devd);
      const { data, error } = await supabase
        .from('devicedetails')
        .upsert([
          { UUID: devd.system.uuid },
          { systeminfo: JSON.stringify(devd) },
        ])
        if (error){  console.log(error); return error;}
        console.log(data);
        return data;
    
      }
    and how im cleaning the empties
    Copy code
    const removeEmpty = (obj:any) => {
      Object.entries(obj).forEach(([key, val])  =>
        (val && typeof val === 'object') && removeEmpty(val) ||
        (val === null || val === "" || val === "Not defined") && delete obj[key]
      );
      return obj;
    };
    
    // eslint-disable-next-line consistent-return
    export async function getDeviceInfo() {
      try {
        const devData:any = await userData.get('deviceInfo.info');
        if (devData) {
          // eslint-disable-next-line no-return-assign
          const o = await removeEmpty(devData);
          return o;
        }
      } catch (error) {
        return error;
      }
    }
    g
    • 2
    • 26
  • when will the release candidate of supabase-js V2 be released?
    e

    eqoram

    09/25/2022, 2:57 PM
    when will the release candidate of supabase-js V2 be released?
    j
    • 2
    • 1
  • RLS Anyone Can Count, but NOT Read
    j

    jdgamble555

    09/25/2022, 3:38 PM
    Copy code
    hearts
    - pid (fk to posts.id)
    - uid (fk to users.id)
    (pk = pid + uid)
    I have set up my rules so that only a user can like their own post. Basically all CRUD operations. However, I need ANYONE to be able to count the likes for a post. Current Rule
    Copy code
    sql
    (role() = 'authenticated'::text)
    AND (uid = uid())
    AND (uid() = (SELECT posts.author FROM posts WHERE (posts.id = hearts.pid)))
    Count Query
    Copy code
    typescript
    // pid is the post id
    const q2 = supabase.from('hearts')
      .select('pid', { count: 'exact' })
      .eq('pid', pid);
    How can I create a rule allowing anyone to be able to ONLY count the total likes, just not CRUD them? Can I do this with an additional rule, or do I need to edit the current one? Thanks, J
    g
    • 2
    • 3
  • Client-side data fetching supabaseauth-helpers-nextjs only gets data after navigating internally
    h

    HunterAndersonX

    09/25/2022, 3:57 PM
    I've implemented a client-side request inside useEffect() per the documentation (https://github.com/supabase/auth-helpers/blob/main/packages/nextjs/README.md#client-side-data-fetching-with-rls), and it works great when navigating inside the app, but if I load the page directly, it fails to return any data. There's no error though, it just returns an empty array. I've checked that the user object is present, but somehow, it still always returns an empty set instead of the expected set of objects. Page code: https://gist.github.com/8d250b94057981f7f17cc0dc73abc274 Versions:
    Copy code
    {
      "dependencies": {
        "@supabase/auth-helpers-nextjs": "^0.2.8",
        "@supabase/auth-helpers-react": "^0.2.4",
        "@supabase/supabase-js": "^1.35.7",
        "@supabase/ui": "^0.36.5",
        "next": "12.3.1",
        "pocketbase": "^0.7.1",
        "react": "17.0.2",
        "react-dom": "17.0.2"
      },
    }
    h
    • 2
    • 11
  • Typescript support in V2 with reading foreign tables
    a

    appixel

    09/25/2022, 4:39 PM
    Has anyone had any luck getting this to work using v2? seems like the example from the docs does not work - https://supabase.com/docs/reference/javascript/next/typescript-support#nested-tables In my opinion this works so much better in V1 like below:
    Copy code
    ts
    import { useQuery } from '@tanstack/react-query';
    
    import supabase from './supabase';
    import { Listing } from './types';
    
    export async function getListings() {
      const query = `
        id,
        title,
        price,
        photos,
        seller: profiles (id, name, city, state),
        categories (name, slug)
      `;
    
      return supabase.from<Listing>('listings').select(query);
    }
    
    export const useGetListings = () => {
      return useQuery(['home', 'listings'], () => getListings());
    };
    Using V2 as instructed in the docs but does not work
    Copy code
    ts
    import { useQuery } from '@tanstack/react-query';
    
    import supabase from './supabase';
    import type { Database } from './database.types';
    
    export async function getListings() {
      const response = await supabase.from('listings').select(`
        id,
        title,
        price,
        photos,
        seller: profiles (id, name, city, state),
        categories (name, slug)
      `);
    
      return response;
    }
    
    export const useGetListings = () => {
      return useQuery(['home', 'listings'], () => getListings());
    };
    
    type profiles = Database['public']['Tables']['profiles']['Row'];
    type ListingsResponse = Awaited<ReturnType<typeof getListings>>;
    export type ListingsResponseSuccess = ListingsResponse['data'] & {
      seller: profiles;
    };
    j
    j
    g
    • 4
    • 17
  • Is it 'expensive' to start realtime channels?
    e

    enyo

    09/25/2022, 4:44 PM
    In my app it's a lot easier to create new channels for different use cases, than to share the same channel. But I wonder whether I'll be wasting performance, or use more resources than necessary. Should I try to fit everything in one channel?
  • Publish and unPublished post.
    d

    DevThoughts

    09/25/2022, 4:56 PM
    When toggling between publish and unPublised posts, should that be some kind of Supabase function for single value update or i just PATCH with rest api? Any good tips?
    g
    • 2
    • 1
  • How to create an entry in database when user signs in
    a

    AnimeDev

    09/25/2022, 5:08 PM
    Hello, I would like to create an entry in supabase database when user signs in for the first time. How to do it?
    g
    • 2
    • 10
  • How can I prevent creating a new record?
    u

    0xdunston

    09/25/2022, 5:12 PM
    Is it possible to prevent inserting a new record if it has some data matching another record in the table? Currently I have to do a filter query on my table to see if there is an existing record with the same
    follow_by
    and
    twit_id
    of the record I want to add
    Copy code
    let { data, error } = await supabase
        .from('new-follows')
        .select('username,follow_by,twit_id')
        .eq('follow_by', String(follow_by))
        .eq('twit_id', String(twit_id));
    I run that on each record I want to add and if they return nothing then I proceed with inserting new records:
    Copy code
    let { data, error } = await supabase
        .from('new-follows')
        .insert(followsTostore);
    
      if (error) {
        throw new Error(error.message);
      }
      return data;
    Doing that first query for each record I potentially want to add really adds up though! 😦 Is there another way? Can I create some sort of table policy or edge function so I don't have to the first query for each new record?
    g
    • 2
    • 6
  • Creating a stored proc, losing my sanity on a simple INSERT...
    t

    tales

    09/25/2022, 5:59 PM
    insert into batch (id, batch_log) VALUES (default, "test-log");
    Failed to run sql query: column "test-log" does not exist
    test-log
    exists in the other table **row in image manually inserted
    g
    • 2
    • 4
  • TimeScaleDB on Supabase
    k

    KickSquare

    09/25/2022, 6:40 PM
    Hey 👋 I'm working on a project that would require a decently large database. I found https://www.timescale.com/, which advertises multiple features that would be great for my use-case, such as up-to-94% compression, horizontal scaling, and a focus on timestamp-labeled data (+ 10-100x faster queries? Not sure if this is too good to be true). Both timescale and supabase use PostgreSQL, and I'm a huge fan of using supabase cloud. I was thinking, is it possible to install or use timescale as an addon to supabase's database? Maybe there is a way I can add a suggestion to the supabase developers to add this as an option?
    g
    • 2
    • 11
  • How does scaling works in Supabase? Can I create read replicas in different regions?
    z

    zenny.eth

    09/25/2022, 7:08 PM
    How does scaling works in Supabase? Can I create read replicas in different regions?
    k
    • 2
    • 1
  • How to keep Leading Zeros in record?
    t

    TZUZ

    09/25/2022, 8:50 PM
    I have zeros at the beginning of phone numbers. Supabase drops leading zeros. How can I keep them? 😬
    g
    • 2
    • 3
  • 404 on websocket connection when subscribing to realtime updates
    s

    semipiccolo

    09/25/2022, 9:41 PM
    I used the snippet from the docs. Serving locally in a svelte app. Replication is active for the table.
    g
    • 2
    • 35
  • emptyFolderPlaceholder
    n

    NotThatBot

    09/25/2022, 10:58 PM
    when i get all files in my storage, i see the normal files, and then another called emptyFolderPlaceholder
    g
    • 2
    • 46
  • RLS check current user has a role, if so delete
    u

    ((()))

    09/26/2022, 12:39 AM
    I have a table where each user has a role that's either admin or default. I want to allow only those who have role = admin to delete rows from this table. Right now it's very counter-intuitive when I try to make a policy as seen in screenshot. What am I missing? With current policy I can only delete users that have role = admin and those with role default are rejected. I want only those signed in users who have role=admin be able to delete users
    j
    • 2
    • 1
  • How can I cast the type of data from supabase response?
    x

    Xzight

    09/26/2022, 1:17 AM
    How can I cast the type of the
    tasks
    variable to an interface
    Task[]
    ?
    Copy code
    js
    const { data: tasks, error: taskError } = await supabase
        .from("tasks")
        .select(
          `id, title, description, priority, due_by, is_completed, tags (title, id)`
        );
  • Composite Primary Key creation error
    l

    lawrence

    09/26/2022, 1:21 AM
    I cant add my project_id (Foreign Key) and user_id (another Foreign Key) as part of composite primary key in Supabase
    j
    • 2
    • 4
  • How to restrict access based on many-to-many relationship
    h

    HunterAndersonX

    09/26/2022, 1:38 AM
    I'd like to restrict access to rows in a table based on there being a many-to-many relationship between
    User
    and
    Projects
    (stored in
    Members
    ). I can't seem to figure it out, any ideas?
    j
    • 2
    • 8
  • Paginating a table with getStaticProps in Next.js
    u

    매튜

    09/26/2022, 3:27 AM
    I am making a table in nextjs that lists vocabulary words pulled from a supabase table using getStaticProps and I want to create a table with pagination to display the data. The supabase table is very large however so I only want to pull 200 rows at a time. What is the best way to go about updating .range based on the page selected by the user?
    g
    • 2
    • 3
  • Supabase Pricing Help
    u

    Unfocused

    09/26/2022, 3:38 AM
    Supabase free does not come with backups of the database & the jump is $25 to get backups. It is possible to use a provider such as Render with Supabase free or do I have to pay $25 just to get backups
    s
    • 2
    • 11
  • React authentication not working as expected
    h

    Homemadesteam58

    09/26/2022, 5:07 AM
    I am using SupaBase Auth in my React app and when I sign in, it signs in as per normal and the homepage loads, but when I refresh the web browser and access the app again. I just get a blank screen and it look like the
    authStateChange
    event hasn't fired. Is this event fired on page load or am I missing something? Help would be greatly appreciated.
    c
    • 2
    • 3
  • SQL Editor Your queries will not be saved as you do not have sufficient permissions
    j

    jxyz

    09/26/2022, 6:22 AM
    I renamed my project, then when I browse my SQL Editor, it says "Your queries will not be saved as you do not have sufficient permissions". Any ideas?
    t
    s
    • 3
    • 7
  • Permission denied after pg_net upgrade
    p

    psteinroe

    09/26/2022, 8:14 AM
    After pg_net got upgraded, it throws a permission denied for table http_request_queue when trying to insert as an authenticated user. Assumption is that any supabase extension works out of the box with the role and auth setup in the database. What do we need to do to fix it? This is critical for us.
    • 1
    • 2
  • can't drop view - does not exists
    u

    3dyuval

    09/26/2022, 9:17 AM
    I have a view that I previously created listed in the API auto generated list. When I try to drop it, it does not exists. It's also not listed in the views column under the tables dashboard. Can someone help?
    • 1
    • 1
  • Functions defined in the migrations are not found in the seed.sql
    r

    ricogallo

    09/26/2022, 11:14 AM
    Hi, I defined some functions in one of my migration files, but when I run
    supabase db reset
    unfortunately they are not found. Any idea why is this happening? I am guessing there is some transaction logic involved?
    j
    • 2
    • 2
  • How do I ignore graphql extensions when dumping?
    g

    gantiplex

    09/26/2022, 11:20 AM
    psql -d localdb < database-dump.sql
    results in attached, what am I missing in the documentation?
  • My Log-in override for Supabase is not working in Framer
    j

    Johnny Robert

    09/26/2022, 12:23 PM
    Hello, I need some help with my code please.
    s
    g
    • 3
    • 18
  • Create rows in multiple tables on new user
    w

    WORLDS BEYOND | DARREN

    09/26/2022, 1:06 PM
    How can I create the following in a single function? - a row in table users with the auth.users.id, - a row in table org with a unique id and name My first org, - a row in org_users with a unique id, user_id from row created in users, and org_id from the row created in org.
    Copy code
    begin
        WITH users AS (
          insert into public.users (id) values (new.id) returning new
        ),
        org AS (
          insert into public.org ( name) values (name ->> 'My first Org') returning name
        )
        insert into public.org_users (user_id, org_id) 
          select users.id, org.id from public.users, public.org;
          return NULL;
    
      end;
    When using this function I get
    There is a column named "name" in table "org", but it cannot be referenced from this part of the query.
    in the Postgres Logs.
    g
    • 2
    • 5
1...313233...230Latest