https://supabase.com/ logo
Join Discord
Powered by
# help-and-questions
  • Not able to upload avatar to storage bucket using formidable
    v

    ven

    10/26/2022, 12:48 AM
    I am building an app in Nuxt 3 and trying to upload an avatar to the storage bucket through an api call to my server. i parse the files using formidable like so
    Copy code
    const form = formidable({ multiples: true });
        const client = await serverSupabaseClient(event);
    
        const response = await new Promise((resolve, reject) => {
            form.parse(event.req, (err, fields, files) => {
                if (err) {
                    reject(err);
                }
                resolve({ fields, files });
            });
        });
        const { fields, files } = response;
    and then i rename my file removing any blank spaces
    Copy code
    const fileName = encodeURIComponent(
            files.avatar.originalFilename.replace(/\s/g, '-')
        );
    and try to upload the file
    Copy code
    // upload the file to supabase storage
        const { data, error } = await client.storage
            .from('site')
            .upload('public/' + Date.now() + '-' + fileName, files.avatar);
        return data;
    i get no error and there is no file in storage. any thoughts on what could be happening?
    d
    • 2
    • 2
  • How do you use an Alias with JS select?
    c

    Cory

    10/26/2022, 1:29 AM
    Trying to use an alias in a normal select, how is this done?
    • 1
    • 1
  • Template literals throwing typescript error in V2
    f

    ferpintado

    10/26/2022, 3:43 AM
    Prior to v2 I used to construct my
    select
    off other variables like so:
    Copy code
    .select(
            `
            ${PROPS},
            ${DATABASE}!${FOREIGN_KEY.parent} (
              ${PROPS}
            ),
            ${vendorService.DATABASE}!${FOREIGN_KEY.vendor} (${vendorService.PROPS})
    Now that I am trying to migrate to v2 typescript is throwing an error like the image. Is there anything I can do to fix that?
  • Error P1011 when attempting 'npx prisma migrate dev --name init'
    n

    NanoBit

    10/26/2022, 6:22 AM
    Could you provide more info like: which db , local or self hosted or cloud? Any fireball block?
    • 1
    • 1
  • How to store a list of things such as ingredients or tags?
    b

    bensurf

    10/26/2022, 8:01 AM
    Hello, I am creating a simple recipe site and I am just designing the database structure for a recipe. I have so far these columns in my
    recipes
    table: id title: text author: text method: text Now I am unsure how I will store - ingedrients (list of ingredients each with a quantity) e.g. "2 eggs", "30g sugar" .... - tags (list of tags) e.g. "quick", "easy", "no-oven" .... Any suggestions? I am brand new to sql type things
  • How am I supposed to work with the getUser() method?
    g

    Giuseppe

    10/26/2022, 9:34 AM
    I need to initialize my user state to the value supabase.auth.user(), but that method doesn't exist anymore, and I can't initialize state with an async function inside If I don't initialize state with the user object then it gets reset every refresh
    s
    • 2
    • 3
  • Has anyone migrated a medium sized codebase from supabase v1 to v2 with Typescript?
    w

    wiesson

    10/26/2022, 11:00 AM
    We simply typed the request by ourselves (supabase.from("users")) ... but with v2 and the generated types, it feels incredible tedious and time consuming to type joins (nearly all my queries are joins) - do I miss sth? I'm shortly before going back to v1 😅
    s
    n
    m
    • 4
    • 6
  • 'PGRST102' Content-Type not acceptable applicationjson, textplain
    p

    Patres

    10/26/2022, 11:28 AM
    Copy code
    const {error, data} = await supabase.from('google_reviews').update({ name: 'Nepal' }).select().eq('id', 1)
    s
    • 2
    • 21
  • RLS get operation
    f

    FunHellion

    10/26/2022, 12:35 PM
    Hi there, I've been working on RBAC using RLS. It works quite well but there is something I'd like to improve on. Currently I have to create a policy for select, insert, update and delete instead of creating one for all. Therefore I need to check for .select separate instead of just putting a function in there and checking that behind the scenes.
    Copy code
    sql
    (
      (household_auth_for_heatpump(serial_number) AND has_permission(ARRAY['heatpumps.select.household'::text])) OR
      (team_auth_for_heatpump(serial_number) AND has_permission(ARRAY['heaptumps.select.team'::text])) OR
      (installer_company_auth_for_heatpump(serial_number) AND has_permission(ARRAY['heatpumps.select.company'::text]))
    )
    I was wondering if there is a way to get the operation from within the policy? Kind Regards, Bram
  • Database Functions - Auth
    t

    tpz

    10/26/2022, 12:41 PM
    Hello! Is it possible to determine if the caller is allowed to bypass RLS? I created a custom function that checks the updating of the row by using auth.uid(), it is always successful if I am logged in as a normal user. But when I update the rows using Supabase table editor in the dashboard, I get an error because auth.uid() returns null if I use the table editor. Thank you
    n
    • 2
    • 4
  • Tests failing on github after submitting a pull request
    b

    blimey

    10/26/2022, 1:06 PM
    Hi, I made a pull request on my fork of supabase/supabase and am getting an error during the Tests phase on Vercel:
    Copy code
    INFO: Deploy to supabase/test-reports
    ERROR: not found ACTIONS_DEPLOY_KEY, PERSONAL_TOKEN, or GITHUB_TOKEN
    Not sure where to define any of those to make it succeed - I tried in github secrets but firstly it won't let me define GITHUB_ anything, and secondly PERSONAL_TOKEN didn't seem to work either... It keeps trying every few hours to remind me - any hints? e.g. https://github.com/rscorer/supabase/actions/runs/3306672164 Thanks!
  • Error in createClient
    t

    tpz

    10/26/2022, 1:18 PM
    Hello, I am trying to create an edge function that connects to supabase. This is my code:
    Copy code
    import { createClient } from 'https://deno.land/x/supabase/mod.ts';
    
    const supabase = createClient(
      MY_SUPABASE_URL,
      MY_SUPABASE_SERVICE_ROLE,
    );
    And when running ``supabase functions serve supaconnect --debug`` I got these:
    Copy code
    Serving supabase/functions/supaconnect
    2022/10/26 21:16:13 Sent Header: Host [docker]
    2022/10/26 21:16:13 Sent Header: User-Agent [Go-http-client/1.1]
    2022/10/26 21:16:13 Sent Header: Content-Length [736]
    2022/10/26 21:16:13 Sent Header: Content-Type [application/json]
    2022/10/26 21:16:13 Send Done
    2022/10/26 21:16:13 Recv First Byte
    Watcher Process started.
    error: Uncaught TypeError: Cannot read properties of undefined (reading 'href')
      if (!url) url = window.location.href
                                      ^
        at getParameterByName (https://deno.land/x/gotrue@3.0.0/src/lib/helpers.ts:17:35)
        at new GoTrueClient (https://deno.land/x/gotrue@3.0.0/src/GoTrueClient.ts:94:57)
        at new SupabaseAuthClient (https://deno.land/x/supabase@1.3.1/src/lib/SupabaseAuthClient.ts:6:5)
        at SupabaseClient._initSupabaseAuthClient (https://deno.land/x/supabase@1.3.1/src/SupabaseClient.ts:166:12)
        at new SupabaseClient (https://deno.land/x/supabase@1.3.1/src/SupabaseClient.ts:69:22)
        at createClient (https://deno.land/x/supabase@1.3.1/src/index.ts:11:10)
        at file:///home/deno/functions/newhello/index.ts:4:18
    This error shows only when calling ``createClient()``, please note that I provided supabase api url, both tried inside variable and string directly in parameters Any help is greatly appreciated. Thank you
    s
    • 2
    • 2
  • Error Error starting shadow database ERROR syntax error at or near COMMIT
    f

    flapili (FR, bad EN)

    10/26/2022, 1:43 PM
    Hi, got an error:
    Copy code
    bash
    supabase db diff -f "add_functions" --debug > l
    Error: Error starting shadow database: ERROR:  syntax error at or near "COMMIT"
    LINE 6: COMMIT;
    any idea ?
    • 1
    • 3
  • Is there anyway to return count as a single value, not an object in an array?
    l

    lewisd

    10/26/2022, 2:19 PM
    When doing a join like so:
    Copy code
    const { data, error } = await supabase
            .from(LISTINGS_TABLE)
            .select("*, comments:listingComments(count), likes:listingLikes(count)", { count: "estimated" })
    I then have to access the amount of comments as
    listing?.comments[0]?.count
    . Same thing with the likes:
    listing?.likes[0]?.count
    I'd ideally like to just use
    listing?.likes?.count
    or even better
    listing?.likes
    o
    s
    • 3
    • 26
  • Testing RLS policies
    k

    kevmmm

    10/26/2022, 2:42 PM
    I am debugging a RLS policy and have a connection open to my Supabase db via a 3rd party tool. I'd like to execute a query as a particular user. Is there a guide on how to do this?
    g
    • 2
    • 22
  • Difference between offical JWT
    d

    dhruvraj

    10/26/2022, 3:16 PM
    Is there a way to differciate between a jwt by supbase and someone made a token ?
    d
    o
    • 3
    • 9
  • RLS Policy on a link table
    s

    Sarcodo

    10/26/2022, 4:12 PM
    Hey guys, I'm trying to create a SELECT policy on a link table which links to one of the tables which has a user_id field on it. My structure looks something like this: Link Table: routine_id, exercise_id Routine Table: routine_id, ...otherColumns, user_id (FK to the auth.users table) How can I setup a policy on the link table, something along the lines of "Show me rows in the link table where the link.routine_id joins to routine.routine_id which has a user_id of uid()" Sorry if that's not clear, unsure how to word this 😰 Basically, I want to do the standard policy of
    auth.uid() = user_id
    but with a link to another table which contains the user_id column
    g
    • 2
    • 2
  • requesting_user_id() function to get 'sub' from Clerk JWT
    r

    RoygieBoosh

    10/26/2022, 4:25 PM
    I'm simply trying to pull the user ID from Clerk into Supabase as the default value for user_id. I've made the requesting_user_id() sql funciton and placed it inside the default value for my user_id column but it remains blank. I've read the tutorials on Supabase and Clerk websites about grabbing the 'sub' from the Clerk token but i'm having no luck. Any suggestions? Thanks!
  • Selecting Row After Trigger
    d

    drewbie

    10/26/2022, 5:02 PM
    I have a database trigger that calls a function after a row is inserted. However, in my function I am not able to select the row as it hasnt been saved yet. The trigger is saying is an after insert, so shouldn't the record be saved? I am trying to just run a function after a row is inserted in the database. My suspicion is that it's because the function returns the record after the http call is made. So while the function may have the record attributes, they aren't actually there yet. For additional context, this is all trying to index records in my database to a search service after they are inserted (and eventually updated/deleted etc) Any help could be appreciated! Trigger
    Copy code
    create trigger index_products_to_search
      after insert on products
      for each row execute procedure 
      public.send_to_webhook( 'http://172.17.0.1:54321/functions/v1/hello' );
    Function
    Copy code
    create extension http with schema extensions;
    
    create or replace function send_to_webhook() returns trigger AS $trigger$
    declare
      rec RECORD;
      payload TEXT;
      column_name TEXT;
      column_value TEXT;
      payload_items JSONB;
    begin
      -- Set record row depending on operation
      CASE TG_OP
      WHEN 'INSERT', 'UPDATE' THEN
         rec := new;
      WHEN 'DELETE' THEN
         rec := old;
      ELSE
         RAISE EXCEPTION 'Unknown TG_OP: "%". Should not occur!', TG_OP;
      END CASE;
     
      payload_items := coalesce(row_to_json(rec),'{}')::jsonb;
      
      -- Build the payload
      payload := json_build_object(
        'timestamp',CURRENT_TIMESTAMP,
        'operation',TG_OP,
        'schema',TG_TABLE_SCHEMA,
        'table',TG_TABLE_NAME,
        'data',payload_items
      );
    
      -- Notify the webhook
      perform extensions.http((
        'POST',
        TG_ARGV[0]::varchar,
        ARRAY[http_header('Authorization','Bearer ANON_KEY')],
        'application/json',
        payload::varchar
      )::http_request);
    
      return rec;
    end;
    $trigger$ language plpgsql;
    Edge Function
    Copy code
    import { serve } from "https://deno.land/std@0.131.0/http/server.ts";
    import { adminSupabaseClient } from "../_shared/supabase.ts";
    
    serve(async (req) => {
      try {
        const payload = await req.json();
        const { data } = payload;
    
        const product = await adminSupabaseClient
          .from("products")
          .select("id")
          .eq("id", data.id)
          .single();
    
        // data.id is the ID of the return rec from the function, but trying to select it returns no results.  
    
        if (!product.data) {
          throw new Error(`No Product Found for ${data.id}`); // This error throws and it has the id from data
        }
    
        return new Response(JSON.stringify(data), { headers: { "Content-Type": "application/json" } });
      } catch (e) {
        throw new Error(e);
      }
    });
    And then in the above url it's an edge function that tries to select that product but no product is returned. The function has access to the record as its provided in the send_to_webhook function, but retrieving a record by that id returns no results.
    g
    n
    • 3
    • 11
  • Can't install supabase cli from NPM
    k

    killjoy

    10/26/2022, 5:11 PM
    When I try to install the supabase cli from NPM I get the error:
    Copy code
    > supabase@1.11.2 preinstall /Users/.../node_modules/supabase
    > node scripts/preinstall.js
    
    internal/process/esm_loader.js:74
        internalBinding('errors').triggerUncaughtException(
    After looking into it deeper it seems like the preinstall script attempts to download the binary from
    https://github.com/supabase/cli/releases/download/v0.0.0-automated/supabase_0.0.0-automated_darwin_amd64.tar.gz
    A path which indeed does not exist. Why is it trying to download from v0.0.0-automated instead of the actual desired release (1.11.2)?
  • How to get data back from an update?
    v

    Vik

    10/26/2022, 6:01 PM
    I have a function that updates the username for a user. But, the data returned is always null. Is this by design and I need to refetch the updated user profile or am I doing something wrong?
    Copy code
    export const handleUpdateUsername = async (id: string, username: string) => {
      const { data, error } = await supabase
        .from('profiles')
        .update({ username: username })
        .match({ id: id })
        .single();
    
      if (error) {
        console.log('error', error);
        return error;
      } else {
        console.log('data', data);
        return data;
      }
    };
    s
    • 2
    • 4
  • Application host recommendations for US-West-1
    l

    LawJolla (Dennis Walsh)

    10/26/2022, 6:24 PM
    Slightly off topic, but... Supabase is in US-West-1. My main hosting providers, Render and Railway, are in US-West-2. The latency is too much. Fly.io is too much overhead (only US customers.. don't need it's global offering). Can anyone recommend a Render like experience in US-West-1? I may drop Supabase and go back to RDS 😦
  • Migration problems - password authentication
    j

    jbergius

    10/26/2022, 6:34 PM
    Hey! I'm trying to set up a dev environment of an existing Supabase project. I've followed the "Migrating Between Projects"-guide but my migrate database script is failing with the following error: "pg_dump: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: FATAL: password authentication failed for user "jockebergius"" I get a prompt to enter a password after running the script, but I'm unsure on what password they're asking for?
    s
    n
    s
    • 4
    • 29
  • Launching a product - question about scaling
    f

    fadethegap

    10/26/2022, 6:42 PM
    We created a SaaS product offering video editing assets. It's a Next.js app hosted on Vercel, with supabase as the backend (authentication, data, assets, videos, etc). We've invited 50k of our current users to participate in a live-stream this Friday where we'll unveil the product. Our current supabase plan is the Small Add-on (2 CPUs | 2gb memory | 2,085Mbps Disk IO). Under normal user load I'm sure that would be find. But let's say we had a 1% conversion, and 500 people purchased at the end of the live stream. I know that is child's play for Postgress - but do you think our current supabase plan is adequate to handle a 500 person signup/authentication spike? Let's say 500 people tried to sign up in the same 60 seconds. Do you think our current plan is adequate?
    o
    n
    • 3
    • 6
  • Does anyone have a trycatch example?
    s

    silentworks

    10/26/2022, 8:26 PM
    The title isn't really saying much, do you have an example of what piece of code you are referring to and what you have tried?
  • Supabase Auth UI provider warning
    o

    Oliver W

    10/26/2022, 8:43 PM
    Using the Supabase Auth UI component in Next.js. adding
    prividers={["google"]}
    gets a warning message in the console: Warning: Received
    false
    for a non-boolean attribute
    loading
    . If you want to write it to the DOM, pass a string instead: loading="false" or loading={value.toString()}.
    s
    • 2
    • 2
  • How to filter on the Supabase v2 subscriptions ?
    z

    ZetiMente

    10/26/2022, 8:44 PM
    Hi, The goal is to have a subscription that filters for only that user's images. This was the code in Supabase v1 that worked. `supabaseSubscription = supabase .from(
    images:profile_id=eq.${profileId}
    ) .on('INSERT', (payload) => { outputPictureURL = payload['new']['image']; }); clearTimeout(timeoutId); }) .subscribe();` However, this new code now fails at filtering: `supabaseSubscription = supabase .channel(
    public:images:profile_id=eq.${profileId}
    ) .on( 'postgres_changes', { event: 'INSERT', schema: 'public', table: 'images' }, (payload) => { console.log('payload is: ', payload); outputPictureURL = payload['new']['image']; }); clearTimeout(timeoutId); } ) .subscribe();` Could someone please tell me the correct syntax now to do this?
    g
    j
    • 3
    • 6
  • Postgis query - function st_x(geography) does not exist
    p

    paxmx

    10/26/2022, 9:34 PM
    I have the following query:
    Copy code
    select 
     ST_X(location) AS x1, 
     ST_Y(location) as y1,
      location as loc
     from properties 
     where id = 1;
    However result shows:
    Failed to run sql query: function st_x(geography) does not exist
    I have tripled check that postgis extension is enabled, what else is a must for this query to work? Or maybe I have an error in my query? Regards.
    a
    g
    • 3
    • 5
  • `supabase db push` to local docker deployment
    p

    Profilüfter

    10/26/2022, 10:46 PM
    Hi, I just updated the supabase CLI (in a docker container, not dev) from 0.36.0 to a newer version (1.11.2). In the old version I executed
    supabase db remote set "..."
    to save the connection string of my docker-deployed database and then
    supabase db push
    to execute all migrations on the database. This all happened inside a docker container with the only purpose to run migrations. However the commands have changed (to be expected in such a huge version jump) but I cannot find a possibility to set a local database as the target for
    db push
    ... I looked at the source code of the CLI and it seems the only way to set the database is with
    supabase link
    but that only works with supabase-hosted projects. Is this now vendor lock-in, work in progress or am I missing something?
  • Does the Supabase Auth emails limit still apply for custom smtp?
    l

    lonelil

    10/27/2022, 4:35 AM
    title
    n
    • 2
    • 1
1...545556...230Latest