https://supabase.com/ logo
Join Discord
Powered by
# help-and-questions
  • Should I use jsonb in this case or simply add more columns to my table?
    l

    Lukas V

    02/07/2023, 4:24 PM
    Hello, I haven't worked with production projects, so I don't really know what to choose. I have a products and prices tables that represent stripe prices and products. For some products I want to add offers, which would be a limited time offer that instead of the
    default_price
    an offer price would be used during checkout. Using first method, I would simply create 2 more columns
    offer_price_id
    and
    offer_price_valid_until
    , on my front end I would check if offer_price_until exists and timestamp is not expired, then I would render ui accordingly and would use offer price in the checkout. Second method would be the same, but store both of these values in the single jsonb object. Honestly it seems simple, but would i be missing something out in the future if I choose jsonb, maybe some queries such as list all users that have discounted subscriptions Also, when discounts do expire, should I create automated task to "clean up" these values in the columns or not is it not necessary?
  • Webhook question
    m

    monks1975

    02/07/2023, 4:29 PM
    I need to create a webhook that triggers a http request (to an edge function on supabase) when a row is inserted, updated or deleted on table 'tokens'. How would you go about it if this table is updated frequently (sometimes a large group of token rows could be added at once) and the function that is triggered runs an async training process? I don't want the function to trigger like 900 times so wondering how I should debounce the process. Any ideas?
  • cleaner implementation for sending scheduled twilio SMS from supabase table
    d

    Domcario

    02/07/2023, 5:14 PM
    stack: nextjs + supabase deployed on vercel i have a table in supabase of texts to send out. the table includes columns for send time, recipient phone number, and message that will be sent would the cleanest implementation of this be: 1. make a vercel serverless/edge function that runs every 1 minute to send out the twilio messages or 2. make a supabase edge/serverless function that runs every 1 minute, but how would this be connected to twilio's API? or 3. somemthing else? i've heard and read a little about
    pg_cron
    supabase extension, but is it meant for a use case like this?
    f
    • 2
    • 1
  • database webhook - local development
    w

    wes_goulet

    02/07/2023, 5:16 PM
    Does the supabase CLI support sending webhooks to localhost? I know the stripe CLI has a
    --forward-to
    option that is used to develop/test locally. Anything like that available or coming to supabase cli?
  • Simultaneous queries makes it not work.
    a

    AntDX316

    02/07/2023, 5:43 PM
    I'm trying to query multiple things at the same time on multiple apps then it just stops working. I see Supabase is using AWS, it's great they are generous with it being free but is there anyway to remove the limit such using AWS instead or does the $25 plan allow this to not be limited?
    g
    • 2
    • 5
  • Property Data in RPC return
    c

    chickenmcnooble

    02/07/2023, 5:46 PM
    Hello! So iI am currently working on an app that uses typescript in conjunction with supabase. I am having some issues however when not returning an array from my postgres function. I'm trying to return a uuid, and then use it in my code, but typescript says that its type is any[]. However when I check the type through console.log it says string. Is there any way to treat the return type as something other than any[] ?
    • 1
    • 1
  • 404s When Using NextJS + Docker
    h

    humblecoder

    02/07/2023, 6:00 PM
    Hi All, Currently have the base
    Supabase
    instance running in
    Docker
    . I can access
    Studio
    and manipulate items from the UI. However, when I attempt to do anything "useful" from my
    NextJS
    app with the
    supabase
    object, (e.g. access
    authUrl
    or
    storageUrl
    ) I receive a
    404 Not Found
    error. Currently, the only change I've made to the configuration is changing
    Studio
    to port 3131 (since the majority of my base applications already make use of 3000). I've tried the following for
    SUPABASE_URL
    values:
    Copy code
    - http://localhost
    - http://localhost:3131
    - http://localhost:8000
    - http://localhost:9999
    ... none of them change the outcome. Hitting any of the
    auth/v1
    endpoints always results in 404. Any chance we could get a detailed and precise writeup of how exactly the pieces fit together in
    Docker
    without assuming default settings always?
  • logs explorer only showing 100 results?
    a

    abaum

    02/07/2023, 6:21 PM
    no matter how I query in the logs explorer, it seems like there is a limit of 100 on my query results. is there a setting I'm missing or is this a bug? separate meta point, would be nice to have a logs tag for these types of questions? Example query shown, or accessible here: https://app.supabase.com/project/[PROJECT_ID]/logs/explorer?q=select+id%2C+timestamp%0A++from+edge_logs%0A++cross+join+unnest%28metadata%29+as+m%0A++cross+join+unnest%28m.request%29+as+request%0A++cross+join+unnest%28m.response%29+as+response%0A++limit+200&its=2023-02-04T05%3A00%3A00.000Z&ite=
  • Row Level security but allow for updates from server-side as well
    m

    mansedan

    02/07/2023, 6:38 PM
    Hey, We currently have an RLS policy that allows only a user/owner of the row to update a row in a table.
    (uid() = profile)
    But we'd like to alter this so that we can also make updates from a Cron job that is running on a node-server that will occasionally poll & update the table. How can we alter the policy, or set up the supabase-js client to be in an authenticated state?
    g
    • 2
    • 4
  • supabase.auth.setSession not working
    a

    ali

    02/07/2023, 6:58 PM
    Hello, I am trying to auth on behalf of a user sever side. According to the docs this can be done by passing a refreshToken and an accesToken to setSession. For some reason this is not working. The following code produces the error " invalid claim: missing sub claim". Does anyone have any suggestions of what might be wrong. Thanks. 🙏 Code: `` const refreshToken = request.body.refresh_token; const accessToken = request.body.access_token; if (refreshToken && accessToken) { await supabase.auth.setSession({ refresh_token: refreshToken, access_token: accessToken, }); let user = await supabase.auth.getUser(); console.log("user", user); } else { // make sure you handle this case! throw new Error("User is not authenticated."); } `` Error: ``user { data: { user: null }, error: AuthApiError: invalid claim: missing sub claim at /Users/aliagha/Documents/AliProjects/minutescribe/minutescribe/node_modules/@supabase/gotrue-js/dist/main/lib/fetch.js:41:20 at processTicksAndRejections (internal/process/task_queues.js:95:5) { __isAuthError: true, status: 401 } }``
    g
    j
    • 3
    • 8
  • Need help with setting up third party oauth with flutter app
    w

    Wizzel

    02/07/2023, 7:40 PM
    I am trying to set up discord auth for my flutter windows app but I am stuck. I saw that windows oauth support was implemented with this PR https://github.com/supabase/supabase-flutter/pull/136 but I don't know how to set up the redirection.
    g
    • 2
    • 8
  • No Vector Extension?
    a

    awill

    02/07/2023, 7:57 PM
    Hey, I've seen the new post about using pgvector on supabase (https://supabase.com/blog/openai-embeddings-postgres-vector). Is there a way to use this on a project created before the release date? It's not showing up as an available extension at the moment.
    g
    d
    • 3
    • 4
  • Supabase + Slack message API
    j

    jbergius

    02/07/2023, 8:42 PM
    Hey! Does anyone know if it's possible to use the Slack API to post a message to a Slack channel on insert/updates on a specific table!?
    g
    l
    • 3
    • 4
  • Piping remote assets into my bucket via edge function
    z

    zeedee

    02/07/2023, 9:32 PM
    Good day. I'm trying to upload Files from http://example.com into my bucket using edge function. The docs are very unclear here. How do I upload a file using base64 to an arraybuffer.
    Copy code
    js
                const fetchedPDF: any = await fetch(pdfUrl, {
                    method: 'GET'
                })
                    .then(response => response.blob())
                    .then(blob => blob.arrayBuffer())
    
    
                console.log("🚀 ~ file: supabaseClient.ts:126 ~ supabaseClientHandler ~ fetchedPDF", typeof fetchedPDF)
                const { data, error } = await supabaseClient
                    .storage
                    .from('samsara-documents')
                    .upload(`fuel/${createDocument.data.id}.pdf`, base64.toString(fetchedPDF), {
                        upsert: true,
                        contentType: 'application/pdf'
    
                    })
    If I understand it, I need to decode the url into a blob, then cast that into an arrayBuffer() When I decode it with the import { base64 } from "https://cdn.jsdelivr.net/gh/hexagon/base64@1/src/base64.js"; library, nothing happens Is there a mistake here?
    l
    • 2
    • 4
  • I think syntax issue?
    d

    DDupasquier

    02/07/2023, 11:47 PM
    Using the UI, I'm creating a trigger function that increments likes when a row is added to the likes table. Here is the function:
    Copy code
    sql
    BEGIN
      IF NOT EXISTS (SELECT 1 FROM stories WHERE id = NEW."storyId") THEN
        RAISE EXCEPTION 'Story with id % does not exist', NEW."storyId";
      END IF;
    
      UPDATE stories
      SET likes = likes + 1
      WHERE id = NEW."storyId";
    
      RETURN;
    END;
    Pretty straight forward. But I'm getting a syntax error from the UI? Failed to create function: failed to update pg.functions with the given ID: missing expression at or near ";" Not sure if I'm missing something lol. This looks perfectly fine, to me.
    g
    • 2
    • 4
  • Multiple functions in SQL Command
    j

    Jim

    02/07/2023, 11:47 PM
    Hi im new to SQL, trying to hack the 'User Management' template to also add user ids to a
    roles
    table. But struggling with the syntax:
    Copy code
    sql
    DROP TRIGGER on_auth_user_created ON auth.users;
    
    create or replace function public.handle_new_user_role()
    returns trigger as $$
    begin
      insert into public.roles (id)
      values (new.id);
      return new;
    end;
    
    create or replace function public.handle_new_user()
    returns trigger as $$
    begin
      insert into public.profiles (id, full_name, avatar_url)
      values (new.id, new.raw_user_meta_data->>'full_name', new.raw_user_meta_data->>'avatar_url');
      return new;
    end;
    
    $$ language plpgsql security definer;
    create trigger on_auth_user_created
      after insert on auth.users
      for each row execute procedure public.handle_new_user(), public.handle_new_user_role();
    Im getting
    Failed to validate sql query: syntax error at or near "begin"
    g
    • 2
    • 2
  • [question] - Long request best practice
    o

    Olyno

    02/08/2023, 12:45 AM
    Hi This is a simple best practice question, but what's the best to manage long-running jobs from edge functions, and notify users when it's done? I was thinking about using realtime, but realtime can't manage a big amount of users. Is there any other way?
    j
    • 2
    • 34
  • Save query as plpgsql function
    j

    jinsley8

    02/08/2023, 12:45 AM
    I have this select query which works and returns "value", trait_type", and "count" for each row in the results when I use it in the SQL Editor (see image attached) I want to turn this into a plpgsql function to re-use but not having any luck. Not sure how to return it.
    Copy code
    sql
    select x.value->>'value' as value,
      x.value->>'trait_type' as trait_type,
      count(*)
    from public.items,
      lateral jsonb_array_elements(metadata->'attributes') as x
    where x.value->>'trait_type' in ('coat_color', 'level', 'class')
    group by value, trait_type
    ORDER BY trait_type ASC;
    My Function is like this right now. I want exactly what this select query above returns but this function is currently returning an error:
    SELECT * FROM get_trait_count()
    Failed to run sql query: query has no destination for result data
    Copy code
    sql
    CREATE OR REPLACE FUNCTION public.get_trait_count()
    RETURNS setof items
    AS $$
      BEGIN
        select x.value->>'value' as value,
          x.value->>'trait_type' as trait_type,
          count(*)
        from public.items,
          lateral jsonb_array_elements(metadata->'attributes') as x
        where x.value->>'trait_type' in ('level', 'class')
        group by value, trait_type
        ORDER BY trait_type ASC;
      END;
    $$
    LANGUAGE plpgsql
    SECURITY DEFINER SET search_path = public;
    g
    • 2
    • 4
  • npm install ERR on Windows
    o

    oyinkan

    02/08/2023, 12:53 AM
    Hello, Please did anyone have issues with
    npm install
    on windows 11 coming back with a
    node-gyp ERR
    ? I've not found a way around it after trying some suggested solutions on the internet. Any help will be appreciated, Thanks.
    o
    s
    g
    • 4
    • 35
  • Getting a 500 server error when trying to upload to a bucket
    s

    suitedcode

    02/08/2023, 3:19 AM
    Hi, Here's my short snippet to upload:
    Copy code
    const { error: uploadError } = await supabase.storage
        .from('attachments')
        .upload(`${file.name}`, file, { upsert: true })
    I've tested with policies enabled, I've tested by making the bucket public, but I keep getting a
    500
    server error. I tested to make sure that the
    supabaseClient
    is set up correctly. I'm able to list buckets successfully. Any guidance or debug tips would be greatly appreciated. Please let me know if there are additional details I can provide if need be.
    g
    • 2
    • 30
  • Github Actions: issues with migrations
    n

    nimo

    02/08/2023, 3:19 AM
    Hey all, Following the docs to setup CI DB migrations. I've run into this error: https://supabase.com/docs/guides/cli/managing-environments#permission-denied-on-db-push.
    Copy code
    Error: ERROR: must be member of role "supabase_admin" (SQLSTATE 42501)
    At statement 18: ALTER TYPE "public"."call_status" OWNER TO "supabase_admin"
    It seems to be hotly debated (https://discord.com/channels/839993398554656828/1034366730593644565), but i'm not sure what immediate next steps are. Should I be editing the migration file directly and just change all lines that read:
    ALTER TYPE "public"."call_status" OWNER TO "supabase_admin";
    to read
    ALTER TYPE "public"."call_status" OWNER TO "postgres";
    ? How do you handle this longer term?
    s
    g
    • 3
    • 10
  • Sensitive financial information
    s

    sbr

    02/08/2023, 3:43 AM
    Hi, can we use Supabase to store financial information like account numbers, SSNs, bank account passwords etc (excluding card information)?
    g
    c
    n
    • 4
    • 17
  • Is it possible to export edge function logs to be analyzed outside of log explorer?
    j

    Ju Li

    02/08/2023, 4:43 AM
    Log explorer is great and all but letting me export it to a postgresql db, logtail, datadog, etc, would allow me to set up automated alerts and dashboards
    s
    • 2
    • 2
  • Deployed Edge Functions Will Randomly Fail To Fetch
    i

    Isological

    02/08/2023, 6:21 AM
    I have a deployed edge function that works 90% of the time. But I noticed that there are random periods of downtime when my app tries to POST to it. It's a "Failed to fetch" error, but the endpoint's status is up and even works if I don't pass an auth header. No errors client side, seems to be a network issue. Only error is "POST net::ERR_CONNECTION_CLOSED" The downtime lasts 10mins-1hr sometimes, then it will work again with the exact same body. Restarting supabase does not fix the issue. Region: aws-us-west
    g
    • 2
    • 7
  • JWT Secret Restart
    d

    DisamDev

    02/08/2023, 6:32 AM
    Hi, I have seen that if I reset the JWT Secret all keys are reset but are all tables, data and users also reset? Or only the keys are reset.
    s
    • 2
    • 1
  • Pusher support? is it the same as Supabase real-time?
    a

    AntDX316

    02/08/2023, 7:00 AM
    I was looking into Websocket support which Pusher does but I assume Supabase real-time is the same thing?
  • Updating the default `auth.users` table
    a

    Amor Fati

    02/08/2023, 7:29 AM
    Is that possible through supabase dashboard? I want to add a new column to the
    auth.users
    table but can't see how through the dashboard. I can see a way to do it using external SQL editors. Any thoughts on that? Mainly I want to know if doing so will break anything or if it's fine.
    s
    • 2
    • 3
  • Using only authentication without other features
    d

    Dobroslav

    02/08/2023, 8:42 AM
    Hey, Is it good idea to use only supabase authentication for my app to manage users and other stuff handle on my side (database, etc.)?
    m
    • 2
    • 2
  • SvelteKit: auth with Playwright returns an empty session
    m

    mrmikardo

    02/08/2023, 9:46 AM
    I'm having an issue attempting to run Playwright tests against a SvelteKit app which uses
    auth-helpers-sveltekit
    to authenticate against a Supabase backend. My issue boils down to the following: although I am authenticating with a test user at the start of the test, and then navigating to another page - against which I'm running some assertions - it appears that no session is being returned. And so the page under test isn't displayed. What's particularly strange about this situation is that if I do
    npm run build && npm run preview
    - which is what I do before running the Playwright tests - I am able to log in and access the page in question without issue. Has anybody got any experience testing SvelteKit + Supabase apps with Playwright?
    s
    • 2
    • 30
  • How to query deeply nested value from jsonb
    j

    jinsley8

    02/08/2023, 10:02 AM
    I'm using jsonb column to store metadata as a nested object and I'm having issues figuring out how to query nested values using the Javascript client. The metadata looks like this: column:
    metadata
    Copy code
    js
    {
        "attributes": [
            { "trait_type": "color", "value": "blue" },
            { "trait_type": "breed", "value": "herder" },
            { "trait_type": "gender", "value": "male" },
        ],
    }
    Copy code
    js
    const { data, error } = await supabase
          .from('items')
          .select()
          .eq('for_sale', true)
          .contains('metadata->attributes', { color: "blue" })
    -- this still isn't correct because "color" is the value of "trait_type" in the object. It's responding with an error from the .contains() part. How can I get the matching data here? Also, sometimes the query could have two values, how would I accomplish filtering with multiple string values for the same "trait_type"?
    Copy code
    js
    const query = "blue,red"
    const splitQuery = query..split(', ')
    
    const { data, error } = await supabase
          .from('items')
          .select()
          .eq('for_sale', true)
          .contains('metadata->attributes', { color: splitQuery }) // can I do an OR operator here?
    s
    g
    • 3
    • 9
1...123124125...230Latest