https://supabase.com/ logo
Join Discord
Powered by
# help-and-questions
  • On Delete Cascade
    n

    nahtnam

    09/02/2022, 8:35 PM
    Hello! Is there a way to do
    ON DELETE CASCADE
    in the UI or does it need to be done through SQL?
    g
    • 2
    • 1
  • Is the JWT stored in local storage?
    w

    Wickey

    09/02/2022, 9:21 PM
    Hey, it looks to me (just investigated js library) that under the hood for Auth, it's authenticating and then storing that jwt returned in local storage for its entirety until it's invalid and you need to login again. Is this a correct interpretation? If so, I thought it wasn't secure to do so as it creates XSS risks? Thanks in advance, just learning!
    g
    • 2
    • 1
  • Using custom uuid field in auth for group RLS policies
    i

    iLikeBikes

    09/02/2022, 10:43 PM
    Hey All, I am looking to create some grouping polices based on the authenticated users' group id that I have added. In the
    auth.user
    table I have added a uuid field that corresponds with another table's uuid field in attempt to create group permissions. I have been following this template, but I have not been able to get it to work. are there others trying to setup grouping rls policies. is this something that supabase is working on? https://github.com/supabase/supabase/discussions/1148
    Copy code
    -- step 1: add agency_id to raw_user_meta_data
    UPDATE auth.users
    SET raw_user_meta_data  = auth.users.raw_user_meta_data::jsonb - 'agency_id' || '{"agency_id":"df56814f-46ab-4d1c-9e4e-6393e727b212"}' 
    where auth.users.email = 'walter.k.jenkins@gmail.com'
    
    -- step 2: create function
    create or replace function auth.orgid() returns uuid as $$
         select nullif(
                ((current_setting('request.jwt.claims')::jsonb ->> 'raw_user_meta_data')::jsonb ->> 'agency_id'),    
                '')::uuid
    
    $$ language sql;
    
    -- step 3: set policy
    create policy "allow read/write access to boards for users of the same organization"
      on public.notes for all using (
        (auth.orgid() = notes.agency_id)
      );
    g
    • 2
    • 7
  • Failing to insert due to policy?
    n

    n10000k

    09/02/2022, 11:12 PM
    Copy code
    sql
    -- create teams table
    create table teams (
      id bigint generated by default as identity primary key,
      creator uuid references users not null default auth.uid(),
      title text default 'Untitled',
      created_at timestamp with time zone default timezone('utc'::text, now()) not null
    );
    
    -- teams row level security
    alter table teams enable row level security;
    
    -- policies
    create policy "Users can create teams" on teams for 
      insert to authenticated with check (true);
    Copy code
    ts
      const createTeam = (title: string) =>
        supabase
          .from('teams')
          .insert({ title });
    Is returning
    Copy code
    code: "42501"
    details: null
    hint: null
    message: "new row violates row-level security policy for table \"teams\""
    g
    • 2
    • 24
  • subscription
    o

    owonwo

    09/02/2022, 11:38 PM
    Please what's does the RETRYING_AFTER_TIMEOUT error status represent? I'm expecting it to reconnect after a the timeout like the error status displays. But that's not the case, I would like to know the default TIMEOUT for reconnection. Thanks!
    g
    p
    • 3
    • 8
  • How to optimize a simple join
    p

    Peanut

    09/03/2022, 5:11 AM
    I have table "assets":
    Copy code
    CREATE TABLE assets (
      id TEXT PRIMARY KEY,
      title TEXT
    )
    I have table "assetmeta":
    Copy code
    CREATE TABLE assetmeta (
      id TEXT PRIMARY KEY,
      accessstatus TEXT
    )
    I have a view "getpublicassets":
    Copy code
    CREATE VIEW getpublicassets AS
    SELECT * FROM assets LEFT JOIN assetsmeta ON assetsmeta.id = assets.id
    WHERE accessstatus = 'public'
    Then I run it:
    SELECT * FROM getpublicassets LIMIT 100
    When I EXPLAIN ANALYZE it says it is performing a loop for each row and it's slow. What can I do to optimize my view? Tried adding an index:
    Copy code
    CREATE INDEX asset_public ON assetmeta (
        accessstatus ASC
     );
    Doesnt seem to matter
    j
    • 2
    • 11
  • DB functions for production
    h

    Haus Of Alejandro

    09/03/2022, 7:32 AM
    Hello everyone ! I noticed that recently a warning indicating that “DB functions” are not production ready, that was the case before for Edge Functions, which now these don’t have the warning. So I’m a little bit confused on what should I use for production? DB functions or Edge Functions.
    g
    a
    • 3
    • 5
  • Signup with additional metadata
    g

    gbb

    09/03/2022, 8:33 AM
    Hey, I've also posted this yesterday and got a tip but doesn't work. I have the Users table (The default one) And a profile table with the following fields: id, firstName, lastName, email, registeredToExam, paymentId All of them are nullable except ID so I dont get errors at write I have the following function put in place and the trigger:
    Copy code
    create or replace function public.handle_new_user()
    returns trigger
    language plpgsql
    security definer set search_path = public
    as $$
    begin
      insert into public.profiles (id, email, lastName, firstName)
      values (new.id, new.email, new.raw_user_meta_data->>'lastName', new.raw_user_meta_data->>'firstName');
      return new;
    end;
    $$;
    
    -- trigger the function every time a user is created
    drop trigger if exists on_auth_user_created on auth.user;
    create trigger on_auth_user_created
      after insert on auth.users
      for each row execute procedure public.handle_new_user();
    During the signup I send the following data:
    Copy code
    const { user, error } = await supabase.auth.signUp(
        {
          email,
          password,
        },
        {
          data: {
            lastName,
            firstName,
          },
        }
      );
    I made sure to validate the first and last name before I do this. yet, I get an error when creating the db, but I don't know why..
    Copy code
    error in createUser { message: 'Database error saving new user', status: 500 }
    Id really need some help here
    u
    g
    k
    • 4
    • 4
  • uint for positive value
    t

    tonyhart

    09/03/2022, 11:11 AM
    so I want make a balance type on profile account generally I want use it as uint because I dnt want user over order something is this possible with supabase ? because I want limit if its reaches zero or sum balance isnt enough, it cancel the order/transaction
    g
    • 2
    • 6
  • Migrations fail without feedback
    n

    Nin

    09/03/2022, 12:12 PM
    The migrations that work on my local DB aren't being pushed and I have no feedback as to why. Below is the migration file it's currently erroring on:
    Copy code
    CREATE OR REPLACE FUNCTION public.tid(
        )
        RETURNS uuid
        LANGUAGE 'sql'
        COST 100
        STABLE PARALLEL UNSAFE
    AS $BODY$
    select
          coalesce(
            (nullif(current_setting('request.jwt.claims', true), '')::jsonb #>> '{user_metadata, tenant_id}')
        )::uuid
    $BODY$;
    
    ALTER FUNCTION public.tid()
        OWNER TO supabase_auth_admin;
    
    GRANT EXECUTE ON FUNCTION public.tid() TO PUBLIC;
    
    GRANT EXECUTE ON FUNCTION public.tid() TO anon;
    
    GRANT EXECUTE ON FUNCTION public.tid() TO authenticated;
    
    GRANT EXECUTE ON FUNCTION public.tid() TO dashboard_user;
    
    GRANT EXECUTE ON FUNCTION public.tid() TO service_role;
    
    GRANT EXECUTE ON FUNCTION public.tid() TO supabase_auth_admin;
    
    COMMENT ON FUNCTION public.tid()
        IS 'Returns the currently logged in users tenant id';
    • 1
    • 1
  • Supabase + Prisma migration fails unexpected response from login query
    m

    Mat

    09/03/2022, 1:29 PM
    I was following this article https://supabase.com/docs/guides/integrations/prisma#resources however once I try to migrate the database it fails at connecting to the db with the error
    unexpected response from login query
    any ideas?
    n
    • 2
    • 16
  • Can't create a storage bucket
    m

    mathewcst

    09/03/2022, 2:47 PM
    Everytime I open the Storage tab, I receive this message: "Migration failed. Reason: An error occurred running 'pathtoken-column'. Rolled back this migration. No further migrations were run. Reason: column "path_tokens" of relation "objects" already exists"
    g
    • 2
    • 7
  • What's the best way to get data from another table when you receive an event from realtime?
    k

    KTibow

    09/03/2022, 5:08 PM
    I'm making a chat app, and for the purpose of this question I have two tables,
    chat
    and
    users
    .
    chat
    has some columns like where the message was sent in, the message contents, and the email of the person who sent the message.
    users
    has a user's email, name, and profile picture URL. Right now I have some code like this:
    Copy code
    js
    export const connectToMessages = async (channelGetter) => {
      return supabase
        .from("chat")
        .on("INSERT", async (payload) => {
          const newMessage = payload.new;
          console.debug("recieved message", newMessage);
          if (newMessage != channelGetter()) return;
          const { data } = await supabase
            .from("chat")
            .select("contents, users ( name, profile_picture )")
            .eq("id", payload.new.id);
          messages.set([...get(messages), data[0]]);
        })
        .subscribe();
    }
    But this means it's laggy because it has to make a whole new query for each message. Is there a way to fetch the user and send it in realtime, or does anyone have any other recommendations?
    g
    t
    • 3
    • 42
  • Increasing pgBouncer pool size
    t

    TrueTrader

    09/03/2022, 6:10 PM
    Hi guys, i'm using pgBouncer with my supabase project but the Pool Size is limited to 15. is there anyway to increase this ?
  • how do i find my db connection string?
    c

    capezolo

    09/03/2022, 8:40 PM
    i haven't used supabase in a while. last time there was a settings section that had the db connection string. now that seems to be gone.
    d
    g
    • 3
    • 10
  • Realtime not working
    f

    FunHellion

    09/03/2022, 9:07 PM
    Hey there. I want to update my list of events when a user has made an update to it. Realtime seems to be the correct option for that but it's not working for me. I used the docs as an example and edited some of the variables. https://supabase.com/docs/reference/javascript/next/subscribe#listening-to-a-specific-table
    Copy code
    typescript
    supabase
        .channel("public:events")
        .on("postgres_changes", { event: "*", schema: "public", table: "events" }, (payload: any) => {
            console.log("Change in events", payload);
        })
        .subscribe();
    When I make a change nothing seems to be popping up in the console. Environment: - React v18.2.0 - Supabase-js v2.0.0-rc.6
    g
    d
    • 3
    • 6
  • Stuck on import { createClient } from 'supabasesupabase-js'
    h

    Honeyandtoast

    09/03/2022, 10:00 PM
    I dont get it keeps saying Cannot use import statement outside a module, I'm using node.js with vanilla JavaScript, but i insist on this being on the backend for security rather than using the cdn, which has worked, any help
    d
    o
    p
    • 4
    • 6
  • Number of requests at once
    t

    tEjAs

    09/03/2022, 10:45 PM
    If I get around 200 requests at once, around 5 times each day (but only 1 day), will the free tier be able to handle it? I will be creating a row with an id and a small array of text as well as fetching around 60 rows from a table (storing an image url and a text description).
    k
    o
    g
    • 4
    • 9
  • Please merge PR 227 on the auth-helpers repo
    h

    http418

    09/03/2022, 11:30 PM
    Next.js 12.2 has been out since May, and we still do not have support for the new edge middleware with Supabase auth helpers. @User
    g
    s
    • 3
    • 2
  • Session not working from `sb-access-token` cookie
    k

    Kasper

    09/04/2022, 12:02 AM
    I've been trying to get SSR working by passing the
    sb-access-token
    cookie value to
    createClient
    in
    supabase-js
    v2, but it's not returning a session. Any ideas why this isn't working?
    Copy code
    ts
    const supabaseClient = createClient<Database>(PUBLIC_SUPABASE_URL, PUBLIC_SUPABASE_ANON_KEY, {
        global: {
            headers: accessToken ? { Authorization: `Bearer ${accessToken}` } : undefined,
        },
    })
    const session = await supabaseClient.auth.getSession() // returns null
  • Update table with Edge function but not with client side
    l

    lanbau

    09/04/2022, 1:36 AM
    Hi friends, i tried to enable RLS for service_role. Then called the Edge function however i'm unable to get any data back. I tried the example code here https://github.com/supabase/supabase/blob/master/examples/edge-functions/supabase/functions/select-from-table-with-auth-rls/index.ts recommended by @garyaustin But with no success... when i disable RLS, it works The main purpose is to use the edge function to update the table.. and prevent client side users from updating it
  • I just got Cloudflared while trying to connect to supabase
    k

    KTibow

    09/04/2022, 1:52 AM
    I was trying to make a simple select query on SSR in sveltekit, but in the error section it gives me a Cloudflare HTML page with the "id.supabase.co needs to review the security of your connection before proceeding." stuff. Anyone know the solution?
    g
    • 2
    • 10
  • Why is this uploaded as text format instead even tho it's from static url, anyone knows to fix this
    h

    Honeyandtoast

    09/04/2022, 2:49 AM
    supabase.storage .from("pics-profile") .upload("client\img\A029.jpg") any clean and beautiful code to the solution ?
    g
    s
    • 3
    • 14
  • Use supabase locally without migrations?
    n

    nahtnam

    09/04/2022, 4:31 AM
    Hello, I was wondering if its possible to pull the latest database changes from the remote and apply them locally without using migrations? I.e. like a straight dump?
    s
    • 2
    • 4
  • installation supabase in docker
    a

    Autarch

    09/04/2022, 6:55 AM
    hello i get error
    c
    • 2
    • 18
  • Export createuser as rpc
    a

    arch

    09/04/2022, 7:14 AM
    Hey there. I would like to create an rpc that lets me create a new user when it is ccalled theough client side js. How do i do it?
    t
    s
    t
    • 4
    • 4
  • upload filelist supabase storage
    s

    samuele

    09/04/2022, 7:58 AM
    Somebody knows how to upload a filelist of file on supabase, currently im on nextjs with typescript and i only know how to upload one single file at a time😫
    g
    • 2
    • 4
  • how to setup eslint for supabase functions?
    j

    jxyz

    09/04/2022, 8:12 AM
    Hi, any ideas how to setup eslint for supabase .ts functions? Not familiar with deno ecosystem and I'm getting the error on my hello-world function: An import path cannot end with a '.ts' extension. Consider importing 'https://deno.land/std@0.131.0/http/server.js' instead.
    • 1
    • 6
  • Move command fails for some files but not others
    a

    ash

    09/04/2022, 8:33 AM
    Using the JS Supabase client I'm trying to rename multiple files by calling storage.from("bucketname").move(oldpath, newpath); My issue is that some of the requests succeed with a 200 response and others fail with a 500 error stating Internal Server Error : Access Denied. In spite of this the rename/move operation still works as expected on all the files. I can't spot any obvious differences between the files or paths, same folder, same bucket with the same access permissions. Super weird. I could work around the issue by just ignoring 500 responses but if I can sort this out I can provide better error handling/notification to users when an actual failure occurs. Any help is much appreciated 🤔
    g
    • 2
    • 3
  • Transactions in Edge Functions
    h

    Haus Of Alejandro

    09/04/2022, 8:52 AM
    Hello everyone! 👋🏻 I was wondering if there's any way to write an Edge Function that behaves like a transaction. I do have logic in my Database Functions and what I really find valuable of this way is that if any operation inside that function fails; the entire transaction fails and "reverse" any other writes to the database, ensuring that I perform an atomic operation once calling that RPC. On the other hand, what I don't enjoy a lot of this is that I need to write all of that logic in pgplsql, I'll prefer to have it written in TypeScript. But as long as I understand, the Edge Functions doesn't behave like a transaction when I have multiple operations inside (eg. a couple of inserts and updates), if any of these fails, the others that succeed will not rollback, ending with inconsistent data and undesired results. So, is there any way to this approach, or any other recommendation? Thanks a lot!
    n
    t
    • 3
    • 6
1...141516...230Latest