https://supabase.com/ logo
Join Discord
Powered by
# help-and-questions
  • Return type of joined tables
    i

    Idicious

    01/23/2023, 8:48 AM
    I'm using the following query with the javascript client, it fetches a room based on the unique column name, and selects all polls that have a foreign key to that room which is a one to many relationship. This works, however the typing of polls in data is a poll object or an array of poll objects. From what I can tell the actual return type is always an array, and this seems to be a TS typing issue. Is there a way to make this always be an array type? I think this would make sense since it's a one to many relationship. This is using v2.4.1 of the @supabase/supabase-js package.
    Copy code
    ts
    const { data, error } = await this.supabase
                .from('rooms')
                .select('*, polls(*)')
                .eq('name', name)
                .maybeSingle();
    
    // data has type similar to
    type Data = {
      id: string,
      polls: Poll | Poll[] | null
    } | null;
    s
    • 2
    • 2
  • subscribe on condition
    u

    _Zaizen_

    01/23/2023, 10:41 AM
    Hey everyone I was wondering what is the right way to subscrive a certain client to a channel only if a certain condition is met. For example: I have a certain element that need live updates but is rarely open so I wanted to subscribe the client only after the section has been opened the first time. should I just subscribe the client since the beginning or is there a way to do the subscribtion conditionally? Thanks!
    g
    • 2
    • 2
  • trigger to update auth when table is updated
    z

    Zerkia

    01/23/2023, 12:40 PM
    Hello I'm trying to figure out how exactly to do this. I have a table named 'users' and my auth called 'Users' (superb naming I know, sorry in advance) I want to, when updating my profile on my react app, also have it update the email in auth via a trigger. An example would be: - User logs in to their profile - User goes to their profile page - User updates their email from 'user@gmail.com' to 'user1@gmail.com' When that email gets changed, I want it to also change the auth.users email. How exactly would I go about doing this? My table does have RLS if that matters. Sidenote: I have a trigger already that creates a user in my public.users table when a user in auth.Users is made, and they have a FK relation.
    s
    • 2
    • 2
  • How do you connect image and video resources to Supabase?
    a

    AntDX316

    01/23/2023, 12:40 PM
    How do you connect image and video resources to Supabase?
    s
    • 2
    • 1
  • Best way to achieve an 'activity log' in my application?
    c

    CaptCuddleFish

    01/23/2023, 1:59 PM
    Hi guys, I'm building an application in NextJS using Supabase as the backend. It's going great, but I'm stumped by the final task - which is to build an activity log where users can see what other users (and themselves) have been doing. This is essentially a list of the action performed, the data it was performed on, and when. Is this achievable in Supabase, and if so, how? Thanks!
    g
    • 2
    • 3
  • Non-nullable view columns?
    d

    dextah

    01/23/2023, 2:31 PM
    Is there any way to indicate to the type generator that a view's output will not have nullable columns? I tried adding a
    where
    clause to explicitly filter for
    not null
    , but my generated types are still nullable.
  • sveltekit auth helper client fails to initialize but only on one route
    h

    hachoter

    01/23/2023, 2:33 PM
    I have a weird situation, this is the client
    Copy code
    import { createClient } from '@supabase/auth-helpers-sveltekit';
    import { PUBLIC_SUPABASE_ANON_KEY, PUBLIC_SUPABASE_URL } from '$env/static/public';
    console.log('PUBLIC_SUPABASE_URL', PUBLIC_SUPABASE_URL);
    export const client = createClient(PUBLIC_SUPABASE_URL, PUBLIC_SUPABASE_ANON_KEY);
    The log shows the url, but in one file I get an error
    supabaseUrl is required
    this is the full trace
    Copy code
    client:dev: Error: supabaseUrl is required.
    client:dev:     at new SupabaseClient (/Users/isaac/Desktop/projects/all-simchas/node_modules/.pnpm/@supabase+supabase-js@2.4.1/node_modules/@supabase/supabase-js/dist/main/SupabaseClient.js:55:19)
    client:dev:     at Proxy.createClient (/Users/isaac/Desktop/projects/all-simchas/node_modules/.pnpm/@supabase+supabase-js@2.4.1/node_modules/@supabase/supabase-js/dist/main/index.js:35:12)
    client:dev:     at /Users/isaac/Desktop/projects/all-simchas/packages/utils/lib/client.ts:4:22
    client:dev:     at processTicksAndRejections (node:internal/process/task_queues:96:5)
    client:dev:     at async instantiateModule (file:///Users/isaac/Desktop/projects/all-simchas/node_modules/.pnpm/vite@4.0.0/node_modules/vite/dist/node/chunks/dep-ed9cb113.js:53246:9)
    It's weird because in other files I am able to query even though it's the same client this is the file that doesn't work
    Copy code
    import { client } from '$lib/db';
    import type { PageLoad } from './$types';
    import type { Poster } from 'types/posters';
    
    export const load: PageLoad = async ({ params }) => {
      console.log('params', params);
      const { data, error } = await client.from('posters').select().eq('id', params.id).single();
      return {
        poster: data
      };
    };
    s
    • 2
    • 5
  • Supabase auth + Existing graphql express server
    k

    kuipou

    01/23/2023, 3:15 PM
    I'm currently building a Express GraphQL server with Apollo Server and Prisma but I want to intergrate auth server side but I don't find any documentation to do this could anyone point me in the right direction
  • Supabase / PostgreSQL
    y

    Yakkek

    01/23/2023, 5:19 PM
    Can I connect my PostgreSQL DB in Supabase ? Example: I connect Supabase to my PostgreSQL DB and the changes I make in Supabase will also be applied to my PostgreSQL DB.
    s
    k
    • 3
    • 6
  • Emoji message reactions…
    g

    Gregory

    01/23/2023, 5:49 PM
    I have a messages table with realtime updates for my live chat web app. I want to add discord style message reactions in the form of 6 different emojis. What is the most efficient way to store these reactions? As a separate table or as a column on my messages table? Since the messages are already subscribed to realtime Changes, I thought that if the emojis are added as an update to each message then that approach might make sense, despite increasing the size of each message.
  • Using OAuth generated provider_token as Twitter API request authentication?
    u

    1voy

    01/23/2023, 6:38 PM
    Please correct me if I'm wrong - is provider_token that can be retrieved from current session the Access Token used to make Twitter API (or any OAuth token requiring API) requests? I'm trying to build an app that will use user context to complete processes on their behalf. If this provider_token is the token needed for this, is it possible to request additional scopes when signing in with the signInWithOAuth() function? And how could that be done? My ultimate confusion is how to integrate the generated provider_token to make requests using the Twitter SDK or v2-API
    s
    • 2
    • 3
  • Session is always null
    m

    Mopsior

    01/23/2023, 6:40 PM
    My session is always null, I'm using nextjs and follow nextjs (no app version) tutorial. Please, I need answer asap
    s
    j
    • 3
    • 7
  • processing more than one record Deno function
    t

    Toño

    01/23/2023, 7:09 PM
    I have configured and working https://github.com/supabase/supabase/tree/master/examples/edge-functions/supabase/functions/send-email-smtp this found perfect to send one record from webhook or invoking function. Ok, but get error 500 when trying process more than one record. Tried Deno pool but had error too. Someone had same issue? Thanks for helping I know that project https://github.com/burggraf/supabase-mailer but right wanna try Deno cause has aws ses configured
    g
    • 2
    • 1
  • Encrypting Supabase JWTs
    h

    hotshoe

    01/23/2023, 7:51 PM
    Hello1 🙂 Supabase signs but does not encrypt JWT cookie. Is there an option or pattern for encrypting?
    g
    d
    • 3
    • 14
  • Reset password flow in Next.js
    d

    debabrata

    01/23/2023, 8:10 PM
    Hello, I'm facing some problems regarding resetting passwords.
    Copy code
    js
      useEffect(() => {
        supabase.auth.onAuthStateChange(async (event, session) => {
          if (event == "PASSWORD_RECOVERY") {
            const newPassword = prompt("What would you like your new password to be?");
            const { data, error } = await supabase.auth.updateUser({
              password: newPassword || "",
            })
    
            if (data) alert("Password updated successfully!")
            if (error) alert("There was an error updating your password.")
          }
        })
      }, [])
    Whenever I click on the password reset link that's sent in the email, I'm redirected to the proper page, but the page gets refreshed automatically and I can no longer accept the new password.
    • 1
    • 1
  • How to do migrations with supabase
    j

    Jaaneek

    01/23/2023, 9:09 PM
    I was thinking of using prisma but I guess there is a simpler way to do that with supabase. Can you link any articles/youtube videos explaining on how do that step by step? I can't find anything that would guide me well enough
    g
    • 2
    • 1
  • :latest tags on docker are 6 months out of date
    b

    Brad Dwyer

    01/23/2023, 9:13 PM
    We're testing out self-hosting Supabase & running into CORS issues (Request header field x-client-info is not allowed by Access-Control-Allow-Headers in preflight response). It looks like this is because we ended up running really old versions because if you don't specify a version for a Docker image, the :latest tag is pulled by default and :latest is not actually tied to the latest version, it's tied to a 5-6 month old version (depending on which container you're looking at) in Supabase's Dockerhub. Now that we know this is the problem we're explicitly specifying versions in our helm chart (which was originally based off of the supabase-community/supabase-kubernetes repo), but we wasted several hours trying to understand what was going wrong. https://github.com/supabase-community/supabase-kubernetes/blob/main/charts/supabase/values.yaml
    g
    s
    • 3
    • 2
  • \copy statement timing out
    g

    Galen Winsor [gwinsor]

    01/23/2023, 9:26 PM
    Hi! I'm trying to import a 7 GB CSV file into my database, and when I try the "Import via file" option in the GUI, I get network errors. When I try to use
    \copy
    from the terminal, I get a
    canceling statement due to statement timeout
    error. It looks like the maximum time for a query is 2 minutes; is there a way to increase this? Given the amount of data I'm trying to upload, I think it will take longer than 2 min.
    g
    • 2
    • 3
  • How to initialize the supabase client with a session
    d

    Dbugger

    01/23/2023, 9:57 PM
    If I reload my application, obviously the client will lose its session, and nobody wants to have to re-login every time they refresh the page. I assume that I have to save the Access Token and the Refresh Token in a cookie for this, but then... how does one initialize the client with the session from before refreshing the page? I saw that there is a third parameter in
    createClient
    and I suspect that might have something to do with it (maybe no...), but I did not see any example of how to do this anywhere. Anyone knows?
    s
    • 2
    • 5
  • Supabase / PostgreSQL
    y

    Yakkek

    01/23/2023, 10:27 PM
    How do I connect my Supabase DB to a already existing PostgreSQL DB?.. in a way that the changes that I apply in the Supabase also changes the PostgreSQL DB and vice-versa. Is that even possible ?
    g
    • 2
    • 6
  • Default Value && Not Null
    a

    AlanK

    01/23/2023, 11:27 PM
    I have a trigger that inserts a new row when a user is added. One field is defined as a
    Copy code
    smallint [] NOT NULL DEFAULT '{}'::smallint[]
    When the trigger runs I get a
    Copy code
    null value in column "stay_in_touch_choices" of relation "user_profile" violates not-null constraint
    error. Is there something I am missing?
    g
    • 2
    • 35
  • How to make an http request in SQL to another local web service when running supabase locally?
    c

    cayblood

    01/24/2023, 12:22 AM
    I have a local surrogate API service that mocks a remote API for my local SQL tests. I want to tell my local supabase instance to connect to it on localhost:, but because supabase is running inside of docker, it can't access my surrogate service. Is there any way I can configure supabase to bridge my docker network with the host os or somehow open up a specific port?
    • 1
    • 1
  • Edge function FunctionsFetchError
    g

    Guy Rozen

    01/24/2023, 12:34 AM
    After triggering a specific edge function through the supabase SDK, I keep on receiving this following error message: "FunctionsFetchError: Failed to send a request to the Edge Function" The function itself is being triggered successfully, and the client even receives a 200 successful status, but the response body is never returned, and the browser behaves as if the request had failed. Other edge functions under the same project are working successfully, and maintain the same structure of this specific edge function. Cors options alongside cors headers are set correctly, as otherwise other edge functions would end up failing. The edge functions logger doesn't report about anything being wrong whatsoever, and it is even stated there that there is a 200 status response. I assume this is just a random error that isn't actually related to the issue itself. What might cause FunctionsFetchError to be thrown, or for no response message to return? return new Response(JSON.stringify("done"), { headers: { "Content-Type": "application/json" }, }); That's pretty much the response code in the edge function itself, so nothing here has any actual reason to fail, atleast I don't think so myself...
    r
    r
    • 3
    • 2
  • new row violates row-level security policy for table \"users\"
    u

    .davdi

    01/24/2023, 1:05 AM
    Hello! Im pretty new to supabase and i don't really know why im getting this error when i want to insert.
    g
    • 2
    • 17
  • Limit amount of sessions in db?
    y

    yayza_

    01/24/2023, 1:53 AM
    Is this something I should even be concerned with? Would Supabase remove old sessions rows in db after an amount of time anyway? I can only do it manually if I have a session and pass it to signOut, otherwise if user deletes the cookie it becomes null and I cant use signOut anymore Maybe I'm doing something wrong, but if a user deletes their cookie, they can log in again and it creates a new session in the database, only if they log in and they finally hit log out button does it remove all of their sessions. Is there a function in supabase-js that can check if a user already has other sessions? maybe if they have more the N then I can delete the oldest one so they , so they dont keep spamming log in.. [SvelteKit]
    Copy code
    js
    // hooks.server.js
    export const handle = async ({ event, resolve }) => {
        const { session, supabaseClient } = await getSupabase(event)
        event.locals.supabase = supabaseClient
        const authPaths = ['/login', '/register', '/verify', '/logout']
        if (!session && !authPaths.includes(event.url.pathname)) {
            throw redirect(302, '/login')
        }
        if (session && !authPaths.includes(event.url.pathname)) {
                    // use auth.refreshSession because it checks the db (auth.getSession doesn't)
            const { data, error } = await supabaseClient.auth.refreshSession(session)
            if (error) {
                throw redirect(302, '/logout')
            }
        }
        return resolve(event)
    }
    Copy code
    js
    //+layout.server.js
    import { getServerSession } from '@supabase/auth-helpers-sveltekit'
    export const load = async (event) => {
        const session = await getServerSession(event)
        return { session }
    }
    g
    • 2
    • 12
  • Does Supabase Storage support object versioning?
    z

    zadlan

    01/24/2023, 2:40 AM
    I'm evaluating if Supabase would be suitable for my use case. I need to access older versions of the same image in my app. The API supports a PUT method to update the object at an existing key: PUT /object/{bucketName}/{wildcard} To get the object, I can: GET /object/public/{bucketName}/{wildcard} My question is, can I add a versionId parameter to get an older version of the object? i.e. GET /object/public/{bucketName}/{wildcard}?versionId=L4kqtJlcpXroDTDmpUMLUo This is documented in AWS documentation https://docs.aws.amazon.com/AmazonS3/latest/userguide/RetrievingObjectVersions.html but I don't know if Supabase will pass the query param over to S3.
  • How to connect to Supabase pg-bouncer pool from JS
    u

    user8923

    01/24/2023, 5:02 AM
    So far I've been using the pg package to connect to my Supabase DB and the Pool object that ships in that package. This is for serverless functions BTW. Upon learning that Supabase uses pg-bouncer I'm wondering if I should still use Pool? If the pool is provided by pg-bouncer, then surely I do not need to maintain a pool on the JS side as well? Should I direct-connect from pg to port 6543 of my Supabase DB?
  • time to leave after 15 minutes
    c

    Chidhu

    01/24/2023, 5:07 AM
    Is there any option or policy to delete the record from table after 15 minutes? #table
    w
    s
    • 3
    • 4
  • Function does not exist error even though it exists.
    m

    Muezz

    01/24/2023, 6:52 AM
    I have a postgres function that is giving this error (see the attached image) when I call it. This error does not make any sense even though the function exists. Here is the function itself:
    Copy code
    sql
    CREATE OR REPLACE FUNCTION upsert_meal(
      arg_id_meal INT4, 
      arg_id_user UUID, 
      arg_name_meal VARCHAR, 
      arg_servings INT2
      )
      RETURNS INT4
      SECURITY DEFINER
      LANGUAGE plpgsql
      AS
      $$
      DECLARE
        meal_id INT4;
      BEGIN
        IF EXISTS (SELECT 1 FROM "Meal" WHERE "Meal".id_meal = arg_id_meal) THEN
          UPDATE "Meal"
          SET 
          "name_meal" = COALESCE(arg_name_meal, "Meal".name_meal), 
          "servings" = COALESCE(arg_servings, "Meal".servings)
          WHERE "id_meal" = arg_id_meal
          RETURNING "id_meal" INTO "meal_id";
          RETURN "meal_id" AS "updated_meal_id";
        ELSE
          INSERT INTO "Meal" 
          ("id_user", "name_meal", "servings")
          VALUES
          (
            arg_id_user,
            arg_name_meal,
            arg_servings
          )
          RETURNING "id_meal" INTO "meal_id";
          RETURN "meal_id" AS "new_meal_id";
        END IF;
        
      END;
    $$;
    s
    g
    • 3
    • 27
  • Update a user metadata
    a

    Ape R Us

    01/24/2023, 6:55 AM
    Hey does anyone know how to properly call the
    Copy code
    await supabase.auth.updateUser({
                data: { age: 20 }
            });
    in a +page.server.ts file (svelte) the docs says that it needs to be in a json format. what im trying to do is when a customer registers and logs in i want to automatically update their metadata to include the stripe id one time.
    j
    • 2
    • 1
1...106107108...230Latest