https://supabase.com/ logo
Join Discord
Powered by
# help-and-questions
  • Supabase client not giving timeout when DB fails (infinite promise) + randomly fails
    s

    Sacha

    11/16/2022, 9:29 AM
    Hello! Supabase JS client sometimes never resolves promises, which is super inconvenient. We had to build our own timeout system. Moreover, the DB sometimes never resolves a specific query for hours, even re-querying it several times, from a specific client. But launching this specific query on my personal computer works fine, or even restarting the distant client on which it fails makes it. Super weird.. 🙂
    n
    g
    • 3
    • 5
  • signInWithPassword does not sign in in v2, but signin in v1 works fine
    d

    Dennis

    11/16/2022, 9:33 AM
    I have a problem with the signin method in supabase-js. If i call the signInWithPassword method with an email and password, the response i get has no errors and has a session and a user. However if i try calling getSession afterwards the session i get from it is null. I also have an rls policy set up on a table and if i try to select from the table i get 0 result as if i was not authenticated. If i use v1 of supabase-js and use the signIn method, then i can select from the table just fine and get the results that i should. As far as i can see from the docs it does not looke like i am missing something.
    Copy code
    const res = await supabase.auth.signInWithPassword({
          email: 'test@email.com',
          password: '12345678',
        });
    
        const { data, error } = await supabase
          .from('test')
          .select();
        
        expect(data?.length).toBe(1);
    Am i doing something wrong?
    i
    • 2
    • 3
  • Not able to access logged in Supabase user
    i

    Its-a-meMario

    11/16/2022, 9:53 AM
    FIXED: Turns out the tutorial was using V1 syntax, the docs have updated me on what to use (GetSessions Hook)
  • Realtime updates stopped working on existing app
    i

    irreal

    11/16/2022, 9:56 AM
    Hi, we have an app deployed that uses Supabase JS SDK V1 and gets realtime updates when rows are inserted or updated in a specific table. We set this up months ago and the app was happily working in production. This morning around 8 AM the app stopped receiving any realtime messages. The user logs in without any issues, and if I execute a query using the supabase sdk to select rows in that table, I pass the RLS check and get the results back all fine. But no realtime events are showing up anymore. no one logged into the supabase dashboard, let alone messed with any settings.
    Copy code
    const subscription = client
          .from("agent_query")
          .on("*", (payload) => {
            console.log("got a payload", payload); //never triggers
    }).subscribe();
    console.log("initial state", subscription.state); //prints joining
        subscription.onError(() => {
          console.log("error!"); // never triggers
        });
        subscription.onClose(() => {
          console.log("closed!"); //never triggers
        });
        subscription.onMessage(() => {
          console.log("message!"); // never triggers
        });
        setInterval(() => {
          console.log(subscription.state); // always prints "joined", so it succesfully joined but gets no messages
        }, 2000);
    I'm stumped, we made no changes whatsoever, in code or through the dashboard. Any chance something is down on the supabase side?
    g
    • 2
    • 16
  • Local supabase api is returning 400 bad request when I am using the SDK client
    k

    Kurdiez

    11/16/2022, 10:39 AM
    I've passed the right local API URL and Service Role API key to create the client object. Then I used the
    supabase.auth.admin.createUser
    function to create a user and I am keep getting the
    400 Bad Request
    from the local API server. What's happening here? I can't find anything wrong.
    s
    • 2
    • 1
  • See if Magic Link email delivered?
    e

    Evostance

    11/16/2022, 11:29 AM
    Is there a way to see if a magic link email is getting delivered? I'm having some issues with some domains, but everything appears to be OK from a code perspective
    s
    • 2
    • 3
  • Hostname-IP error to connect supabase db via js library
    s

    sylar815

    11/16/2022, 12:12 PM
    { message: "FetchError: request to https://db.xxxxxxxxx.supabase.co/rest/v1/hourly?select=* failed, reason: Hostname/IP does not match certificate's altnames: Host: db.xxxxxxxx.supabase.co. is not in the cert's altnames: DNS:*.supabase.co, DNS:*.supabase.in", details: '', hint: '', code: 'ERR_TLS_CERT_ALTNAME_INVALID' }
    g
    • 2
    • 2
  • Importing Data into a Table
    m

    Moshe

    11/16/2022, 12:38 PM
    I am wondering -- is it possible to import data into a table in supabase? For example if I have either a csv file or a json file -- can I import that data into a table via the backend of supabase? If so, how? Thanks :).
    s
    • 2
    • 1
  • Protect routes in nextjs
    i

    ismael1234

    11/16/2022, 1:13 PM
    How to protect routes in nextjs without withPageAuth? because I'm also using getStaticProps.
    n
    m
    • 3
    • 2
  • Difference between edge functions and webhooks
    m

    MaGnezij

    11/16/2022, 3:26 PM
    Could anyone try and explain in simple terms the difference between webhooks and edge functions in supabase?
    g
    • 2
    • 4
  • Some way to test if listening to changes is active?
    m

    MDobs

    11/16/2022, 3:53 PM
    I have
    Copy code
    var room = supabase
     .channel(`public:room:id=eq.${id}`)
     .on('postgres_changes', {
        event: '*', 
        schema: 'public', 
        table: 'room', 
        filter: `id=eq.${id}`,
      }, payload => {
         console.log('Change received!', payload)
            changeCallback(payload)
         }).subscribe()
    however if I immediately change a value on the DB sometimes I don't receive the change, if I delay the call by 200-500ms then I constantly get the callbacks from the changes. But this is prone to race-conditions, is there a way to de-facto now that the site is listening to DB changes?
    g
    • 2
    • 2
  • Synchronising schema changes across multiple projects
    m

    mrmikardo

    11/16/2022, 4:52 PM
    I'm running several Supabase projects, one as a dev environment and several as production environments for different clients, and I'd like to keep the schemas in sync. I.e., if I make changes to the dev project's DB schema, I'd like a way to make an identical change to all production servers. Similar to running a migration script using something like Alembic: https://alembic.sqlalchemy.org/en/latest/. What strategies do people here have for keeping schemas in sync in such a way? Relatedly, do people have any strategies for versioning various DB/SQL snippets, e.g. keeping these in their repos? Keen to hear how you guys approach this!
    n
    • 2
    • 1
  • How to query text column that is ilike one or more array items?
    s

    Smardrengr

    11/16/2022, 5:00 PM
    e.g.,
    Copy code
    select * from profiles where name ilike in ('%jim%','%dave%', '%mary%');
    Of course, this query doesn't work, but that's I'm trying to do with Supabase client. Any ideas?
    g
    • 2
    • 8
  • How to query arrays?
    c

    Cheqo

    11/16/2022, 5:21 PM
    I am getting this error whilst trying to make a query for array values.
    could not find array type for data type text[]
    here is my query:
    Copy code
    const { data, error } = await supabase
          .from('recipes')
          .select('*')
          .in('tags', ['Snack']);
    Also, I converted my column from JSONB to Text[], does that make any difference?
    g
    • 2
    • 4
  • How to correctly set typescript for nested tables
    c

    cdedreuille

    11/16/2022, 6:22 PM
    I tried to set it up following the docs but for some reasons typescript is complaining on
    setProducts(data);
    as the function doesn't return the new types. I'm a bit confused as to what could be the best way to set this up. Any idea where I'm doing something wrong?
    Copy code
    const [products, setProducts] = useState<ProductsResponseSuccess[]>([]);
      const supabaseClient = useSupabaseClient<Database>();
    
      async function getProducts() {
        return await supabaseClient.from("products").select("*, vendor(*)");
      }
    
      type Vendors = Database["public"]["Tables"]["vendors"]["Row"];
      type ProductsResponse = Awaited<ReturnType<typeof getProducts>>;
      type ProductsResponseSuccess = ProductsResponse["data"] & {
        vendor: Vendors;
      };
    
      useEffect(() => {
        async function loadData() {
          const { data } = await getProducts();
          if (data) setProducts(data);
        }
        loadData();
      }, []);
  • RLS & privacy
    s

    Smardrengr

    11/16/2022, 6:26 PM
    RLS is very cool, but I'm perhaps wrongly concerned that it can expose all user data to anyone with some technical know-how. For example, given a
    profiles
    table that references with RLS policies...
    Copy code
    create table profiles (
      id uuid primary key references auth.users on delete cascade,
      name text,
      email text,
      avatar_url text,
      constraint name_length check (char_length(name) >= 2)
    );
    
    alter table profiles enable row level security;
    
    create policy "User profile can be read by everyone."
      on profiles for select
      using ( true );
    
    create policy "Users can create their own profile."
      on profiles for insert
      with check ( auth.uid() = id );
    
    create policy "Users can update own profile."
      on profiles for update
      using ( auth.uid() = id );
    It appears to me that any user can, using the
    supabaseClient
    fetch all user emails (in addition to
    name
    and
    avatar_url
    )? If my app has 10,000 users, that's kind of a problem, isn't it? That said, users of my app need to look up other users by email in order to add them as friends, so I sort of need a select RLS on email, I just don't want the client to be able to
    Copy code
    const { data, error } = await supabaseClient.from('profiles).select();
    Any thoughts on how to best approach this?
    g
    • 2
    • 4
  • Implement redirect in the edge function
    a

    Andrey Delov

    11/16/2022, 6:53 PM
    Hi all, could you tell me if it is possible to implement "redirect" in edge functions, I want to use one of the functions as a webhook and do redirection for deeplink in the mobile app, i try to used deno Response.redirect() method, but i get the whole page , not redirect.
  • HIPPA COMPLIANCY
    s

    sterbenc8

    11/16/2022, 7:46 PM
    Hey, we have a client that needs to be HIPAA compliant, which i saw is an option with Business associate agreement. What are the steps for that? Do they need to purchase any special plans? How can they sign that agreement?
    n
    s
    • 3
    • 4
  • Anyone know how to turn off Rate Limiting on auth attempts while in local development?
    z

    ZaDeR47

    11/16/2022, 7:56 PM
    Looks like with the latest version of the supbase cli (I'm on 1.14.0) added rate limiting on user creation requests, which started messing up my e2e tests. Is there a way to turn this off locally?
    n
    • 2
    • 9
  • Trouble with RLS and a custom authorize function
    a

    Atrox

    11/16/2022, 8:10 PM
    I have the following function defined to use as an authorization method in my RLS policies:
    Copy code
    js
    CREATE OR REPLACE FUNCTION authorize(requested_permission app_permission, profile_id uuid, project_id uuid) RETURNS boolean AS $$
    DECLARE
        bind_permissions int;
    BEGIN
        SELECT count(*)
            FROM public.role_permissions as p
            INNER JOIN public.projects_users as pu on p.role = pu.role
        WHERE p.permission = authorize.requested_permission
            AND pu.profile_id = authorize.profile_id
            AND pu.project_id = authorize.project_id
        INTO bind_permissions;
        RETURN bind_permissions > 0;
    END;
    $$ LANGUAGE plpgsql SECURITY DEFINER;
    In the
    roles_permissions
    table I have added a single permission:
    project.view
    for a role
    owner
    . In the
    projects_users
    table I have a row with
    project_id
    ,
    profile_id
    , and
    role
    . Calling the
    authorize
    function manually works fine and returns true as I would expect. However, the RLS policy never passes. The
    projects
    table has a SELECT policy defined as
    authorize('projects.view'::app_permission, uid(), id)
    . Does anyone have any idea what's going wrong here?
    g
    n
    • 3
    • 9
  • Supabase trying to push duplicated primary key ID
    s

    Sacha

    11/16/2022, 8:29 PM
    I'm inserting some data in a table, without ANY 'unique' stuff but the primary ID, I'm not specifying the ID on my query, but I'm getting message: 'duplicate key value violates unique constraint "0xd_pkey"' In return, with, in the details, a random ID that is incremented by 1 each time I retry the call. Code example: import { MetaSupabase } from "../supabase"; const supabase = new MetaSupabase(); (async () => { supabase .from("0xd") .insert({ address: "0xd79b4d1bd46a998b89e462b780fd0875c60e3bfe", token0_address: "0x52bb5ad0f59a35a7bf7f111f57cfd25dc0ccecea", token0_type: "other", token0_decimals: 9, token0_priceUSD: 0, token0_id: 330, token1_address: "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c", token1_type: "eth", token1_decimals: 18, token1_priceUSD: 0, token1_id: null, pair_data: { volumeToken0: 0, volumeToken1: 0, volumeUSD: 0, reserve0: 0, reserve1: 0, reserveUSD: 0, }, created_at_date: "2022-10-20T12:17:02.000Z", created_at_block: 22338794, blockchain: "BNB Smart Chain (BEP20)", }) .then(console.log); })();
    g
    • 2
    • 7
  • Confusion when combining createServerSupabaseClient and clientside auth helpers (Next.js).
    j

    JH175

    11/16/2022, 9:02 PM
    Just want to clear up some confusion that I have. I am using createServerSupabaseClient at the bottom of a component to fetch data with getServerSideProps... then I'm using useSession and useSupabaseClient to listen for session changes with useEffect at the top, (redirecting with router.push if no session.) Am I jacked up here? Thanks -Jake
    n
    • 2
    • 1
  • Twilio verify api
    k

    Klosiek

    11/16/2022, 9:03 PM
    Hi, I would like to use verify api from twilio and integrate it with supabase. Is it even an option? For now from what i can see, supabase supports only messaging service, but could i make custom authorization based on that verify api?
  • How to structure match() with semi-complex conditions
    s

    Smardrengr

    11/16/2022, 9:33 PM
    Trying to do
    Copy code
    select * from profiles where id = '1234' and status in (true,null);
    I tried
    Copy code
    const { data: requests, error: rErr } = await supabaseClient
            .from('friends')
            .select(
                'id, accepted, sender:user_id (id, name, bio, avatar_url), recipient:friend_id (id, name, bio, avatar_url)'
            )
            .match({ friend_id: session.user.id, accepted: null });
    But I get the error
    Copy code
    null {
      code: '22P02',
      details: null,
      hint: null,
      message: 'invalid input syntax for type boolean: "null"'
    }
    So is there some special where to specify a column is null/true/false within
    match()
    ? Can't find it in the docs... ¯\_(ツ)_/¯
    g
    • 2
    • 13
  • Error When Migrating Database schema extensions does not exist when migrating database
    a

    aaronksaunders

    11/16/2022, 10:06 PM
    I have followed the information found here, #1416, and exported from my old database using the command below
    Copy code
    pg_dump \
      -h db.thedatabase.supabase.co \
      -U postgres --schema-only \
      --clean --if-exists --schema=public \
      > supabase_schema.sql
    > when I try to import into my new database, I am getting the error above
    psql --dbname "$MAINDB" --single-transaction --variable ON_ERROR_STOP=1 --file supabase_schema.sql
    on this statement in the SQL file
    id uuid DEFAULT extensions.uuid_generate_v4() NOT NULL,
    I have been googling around for the last few hours so any help will be appreciated
  • Upload avatar to profile
    s

    Smardrengr

    11/17/2022, 5:22 AM
    Can anyone point me to a guide to creating the SvelteKit flow for adding an image to
    profiles
    for a user?
    o
    • 2
    • 1
  • How to communicate Errors in Edge Functions
    e

    Exa

    11/17/2022, 8:50 AM
    Hi, Edge functions returns json, which shows up as the data field. How do I communicate an error within the function (like a missing field in the request json)? Superbase API only lets us consume 200 error codes, complains otherwise. So now if there was an error, we have a structure like: {error: null, data: {error:"blablabla"}} which is a bit awkward as we have to do 2 error checks everytime we access data thats coming back. Or is this by design & on purpose (for layer separation or so?)?
  • Mailing Lists with Supabase?
    b

    brayden²

    11/17/2022, 9:19 AM
    Hey, I want to use Supabase as a rough mailing list collection for an upcoming project, so users can sign up with their email to the mailing list (NOT CREATING AN ACCOUNT) But I can't seem to find any outside resources on this This is what I have at the moment, I want to check if the email is in the mailing_list table already, and if it is I'll just show a message "ALREADY SIGNED UP" or something. But if the email address hasn't been added to the mailing_list already, I want to add that to the table.
    Copy code
    jsx
    const addNewEmail = async (emailAddress: string) => {
        if (!emailAddress || !emailAddress.includes("@")) return;
    
        console.log(emailAddress);
        // check to see if the email address is already in the database
    
        const { data, error } = await supabase
          .from("mailing_list")
          .select("email_address")
          .eq("email_address", emailAddress);
    
        if (data === null || data.length === 0) {
          console.log("email address is not in the database");
          const { data, error } = await supabase
            .from("mailing_list")
            .insert({ email_address: emailAddress });
          if (error) {
            console.log(error);
          }
          return data;
        }
    
        return data;
      };
    Any ideas would be great 😄
    s
    z
    • 3
    • 4
  • List DDL changes on database
    n

    nuno.joao.andrade

    11/17/2022, 11:13 AM
    I've tested the default postgresql system queries, and they don't seem to work, I need to check on every deploy if there where any DB changes. Can anyone help me on this ?
    s
    • 2
    • 1
  • Safe to change the way UUIDs are generated for the auth.users `id` column?
    t

    tkrunning

    11/17/2022, 11:17 AM
    Hi, is it safe to create a postgres function (specifically this one: https://gist.github.com/kjmph/5bd772b2c2df145aa645b837da7eca74?permalink_comment_id=4306020#gistcomment-4306020) and set that as the column_default for the
    id
    column in the
    auth.users
    table?
    Copy code
    ALTER TABLE "auth"."users" ALTER COLUMN "id" SET DEFAULT 'uuid_generate_v7()';
    Will it even work?
    s
    • 2
    • 2
1...656667...230Latest