https://supabase.com/ logo
Join Discord
Powered by
# help-and-questions
  • Enable RLS for default tables created by the CLI? (extensions, schema migrations, tenants)
    j

    Jesse

    05/17/2023, 7:48 PM
    Currently using supabase cli that creates above tables automatically. How can I enable rls on them within my migrations?
    v
    t
    • 3
    • 5
  • help with permissions roles
    o

    osamita

    05/17/2023, 8:00 PM
    In supabase roles section, i created a new role named "chat_user". From an edge function, I created a new user with this function: await supabase.auth.admin.createUser({ email: "test_user@chat", password: "test_password", email_confirm: true, role: "chat_user", }); in chat_users table, i have this policy: CREATE POLICY "Enable select for authenticated and chat_user roles only" ON "public"."chat_users" AS PERMISSIVE FOR SELECT TO authenticated, chat_user USING (true) in other words, i give permission to select to authenticated and chat_user roles. but when I try to select from javascript using: let { data, error } = await supabase.from("chat_users").select("*"); supabase response is: "permission denied to set role \"chat_user\"" im I setting wrong the user role when creating him?

    https://cdn.discordapp.com/attachments/1108484119626780783/1108484119773593651/image.png▾

    g
    v
    • 3
    • 21
  • POST operations leading to egress traffic increase
    f

    fekdaoui

    05/17/2023, 8:27 PM
    I am seeing a big spike in my egress traffic on Supabase lately even though there is barely any usage of my application. I have a Python script that fetches real-time crypto data (50+ columns) for 2800 projects and inserts that data about every five minutes into my Supabase table. This is a POST operation and from my understanding should not be counted as egress traffic, correct? The dashboard under usage and egress traffic states: "Database egress contains any outgoing traffic (egress) from your database. Billing is based on the total sum of egress in GB throughout your billing period." So am I understanding correctly that POST operations should not be counted towards egress traffic? ChatGPT gave me following answer: *"The data inserted into your Supabase table - This is considered ingress from Supabase's perspective, because data is entering their service. However, Supabase also might count data as "egress" when it processes and stores the data you're inserting. This is because, from their perspective, the data is "leaving" the point at which it was received and being sent to their storage infrastructure. Egress costs in cloud storage often also include things like the overhead of storing the data, such as the metadata associated with the data, which can increase the total amount of data being transferred. Additionally, any processing, querying or modification to your data within Supabase might also lead to internal data transfer, which could be counted as egress traffic."* Appreciate your help with this and any possible solutions/ideas to reduce it. egress traffic is currently increasing with an average of 2GB/day.
    g
    • 2
    • 15
  • Session context provider for Qwik? supabase-auth-helpers-qwik?
    p

    P-a

    05/17/2023, 9:10 PM
    Hello everyone, I was wondering if anybody here have setup equivalent to react SessionContextProvider for qwik ? I'm kinda struggling trying to make this work... I know there is a supabase-auth-helpers-qwik now but is there any docs on it ? I did not have any luck with research...
    s
    • 2
    • 3
  • CUBE extension in postgresql instance
    p

    Parrybro

    05/17/2023, 9:16 PM
    I have enabled the cube extension on my postgresql instance. But I still get the error
    Failed to run sql query: function cube(vector) does not exist
    when I try to run a query with a cube_distance function? has anyone run into this issue before?
    g
    • 2
    • 14
  • Capture provider tokens without relying on the client
    h

    happenator

    05/17/2023, 9:26 PM
    I'd like to save
    provider_access_token
    and
    provider_refresh_token
    in the DB on auth/re-auth. It seems I could do this by adding logic to the client to detect when these values have changed and send them back to the server, but I'd love to find a simpler, more reliable and secure way by simply triggering on something server side. Has anyone found a way to do this?
    • 1
    • 1
  • middleware not working nextjs13.
    p

    phil

    05/17/2023, 10:05 PM
    when a user isnt authenticated the redirect doesnt go through, am i missing something?
    Copy code
    js
    import { createMiddlewareSupabaseClient } from "@supabase/auth-helpers-nextjs";
    import { NextResponse } from "next/server";
    
    
    export async function middleware(req) {
      const res = NextResponse.next();
      const supabase = createMiddlewareSupabaseClient({ req, res });
        
      const { data: { session } } = await supabase.auth.getSession(); 
      
      if (session === null) return NextResponse.redirect(new URL("/login", req.nextUrl));
      
        
      return res;
    }
        
    export const config = {
      matcher: [], 
    };
    b
    p
    • 3
    • 6
  • Supabase on RPI4b
    j

    J21TheSender

    05/17/2023, 10:44 PM
    I am attempting to set up supabase on a Raspberry Pi 4B and I have successfully launched it and logged into the studio and looked around. A lot of the logging features and some other features like webhooks are throwing 500 internal server errors.
    n
    • 2
    • 10
  • supabase.auth.signUp allow me to create existing users!
    r

    RubensNobre

    05/17/2023, 10:54 PM
    when I try to create an account for an existing email. I got signup success. and data is returning the real user data, not an obfuscated/fake user object, as explained on docs. I need to be able to handle if a user already has an account. Can anybody help me? const { data, error } = await supabase.auth.signUp({ email: email, password: password, options: { data: { language: language, referral: referral, }, }, }); if (error) { console.log('SIGN UP ERROR: ', error); } else { console.log('SIGN UP SUCCESS: ', data); } kindly Rubens Nobre
    g
    • 2
    • 10
  • OPTIONS to CORS function locally returns 408
    z

    zardoru / Agka

    05/18/2023, 12:44 AM
    Hey everyone. I'm having trouble running an edge function locally. I was reading how to allow CORS with edge functions and while testing them, the response to my OPTIONS request results in a 408. The relevant code that handles this is not dissimilar to that of the one on the supabase guides and the request clearly returns a 200, but that doesn't seem to matter, because the gateway decides to give me a 408 anyway. Does anyone know what's happening here?

    https://cdn.discordapp.com/attachments/1108555581314306098/1108555581553377280/image.png▾

    • 1
    • 1
  • Realtime not receiving events
    m

    Marty

    05/18/2023, 1:29 AM
    Hello, I have set up realtime in my Next.js app, and everything seems to connect and there are no errors. But my channel isn't receiving any updates. Things I have checked: - Replication is on - React strict mode is false - Tried removing RLS - Checked 'Enable Realtime' in each table I am using this in useEffect():
    Copy code
    supabase.channel('realtime slots')
          .on(
            'postgres_changes',
            { event: '*', schema: 'public', table: 'Time Slots' },
            (payload) => {
              console.log('Change received!', payload)
            }
          )
          .subscribe()
    Is there anything I'm missing? The supabase dashboard is receiving the realtime requests as well.
    g
    • 2
    • 15
  • Supabase AI is making up answers
    b

    Baorong Huang

    05/18/2023, 2:51 AM
    useUser
    hook does not exist in
    supabase-js

    https://cdn.discordapp.com/attachments/1108587735578578994/1108587735729590292/image.png▾

    g
    • 2
    • 1
  • Can NextJS 13.2 cache be used with Supabase client?
    z

    zadlan

    05/18/2023, 3:19 AM
    I'm using Supabase client with NextJS 13.2 (https://nextjs.org/blog/next-13-2#nextjs-cache). All I see on my server logs are cache misses. I'm assuming that Supabase client does not use fetch under the hood. Since Next JS only caches and dedupe fetch requests, caching will not work with the client. I should bypass the Supabase client, and use fetch against the PostgREST endpoints directly if I want to take advantage of the NextJS caching mechanism. Is this correct?
    g
    n
    • 3
    • 10
  • Issue with Setting Client JWT in Supabase API Middleware
    a

    Akkilah

    05/18/2023, 3:51 AM
    I have an API middleware (MW) between my frontend and backend, and I'm using the Supabase JS SDK in the middleware. What I want to achieve is, when a user logs in to the frontend (without using the middleware), I want to pass the JWT value to the API middleware, which will then use it for making requests. I would like to perform something similar to the following CURL command:
    curl -X DELETE 'https://liiusngzzaswexdpunjg.supabase.co/rest/v1/airport?idairport=eq.28' -H "apikey: SUPABASE_KEY" -H "Authorization: Bearer CLIENT_JWT_TOKEN"
    However, I'm facing an issue. I couldn't find a way in Supabase to set the client JWT for
    createClient()
    . Currently, I can only use either the anonymous key or the server key. I've searched and tried using the following code snippet:
    Copy code
    const { data: d, error: e } = supabase.auth.setSession({
      access_token: da.session.access_token,
      refresh_token: da.session.refresh_token
    });
    But it doesn't seem to have any effect. I also tried looking for other documentation, but I couldn't find anything specific (it seems that there was a way in SDK V1, but not in V2). Additionally, after an extensive search, I thought that maybe when I use the following code snippet:
    Copy code
    let { data: da, error: er } = await supabase.auth.signInWithPassword({
      email: 'akkilah@gmail.com',
      password: 'xxxxxxxx'
    });
    Supabase adds the client JWT to the Supabase client internally. However, it still doesn't behave as expected even when I tried doing this from inside the API middleware (meaning logging in from within the middleware). Any advice on how to archive what I want?
    n
    a
    • 3
    • 43
  • How would you login with a provider on the server?
    a

    auser

    05/18/2023, 5:13 AM
    Is it possible to use the callback route on a server? Would I redirect to my server and then call supabase with
    fetch()
    ? I assumed that would work, but I keep getting a 400/Bad Request when I try to call it that way. Is it possible to handle a "redirection" for the auth endpoint?
    g
    • 2
    • 7
  • How to insert only new records into a table
    a

    azza

    05/18/2023, 5:26 AM
    I am saving a list of cities into a table from an api feed. To ensure I don't get duplicates I do
    const { data, error } = await supabase.from("cities").select();
    and combine this data with my new entries from the API. Then I filter out the ones that have an
    id
    and insert the new data into supabase. This worked well initially but I found that the select call has a max of 1000 records so I am now getting duplicate records with my current logic. What is a better way scale this to ensure I don't get duplicates here.
    n
    v
    g
    • 4
    • 11
  • Creating an RLS policy for inserts on a public.organizations table
    o

    OyugoObonyo

    05/18/2023, 5:28 AM
    I have a public.users table which is referencing from auth.users, and a public.organizations table. The public.users table has a many-to-one relationship with the organizations table such that an organization can have many users while a user can only belong to one organization. I have enabled row level security in the organizations table and I would like to create a policy that enables only authenticated users who also have their is_org_creator column value set to true to be able to create an organization. How would I go about building an API that does this and could you please give code snippets from the server side to exactly show how I would make such a request from the supabase javascript client library.
    n
    v
    g
    • 4
    • 36
  • HELP needed - Edge function crashes - auth-helper library can not define res.headers.set()
    e

    Elofin

    05/18/2023, 7:03 AM
    I see the following error log in my NextJS server logs a lot and randomly, it blocks me from launching my project, so I need emergency help 🥲 [TypeError: Cannot read properties of undefined (reading 'set')] It is about createMiddlewareSupabaseClient in @supabase/auth-helpers-nextjs/dist/index.js setCookie(name, value, options2) { const newSessionStr = (0, import_auth_helpers_shared.serializeCookie)(name, value, { ...options2, httpOnly: false }); context.req.headers.append("cookie", newSessionStr); context.res.headers.set("set-cookie", newSessionStr); } There is also reported open issue: https://github.com/supabase/auth-helpers/issues/523

    https://cdn.discordapp.com/attachments/1108651063143321640/1108651063684382760/Screenshot_2023-05-18_at_09.58.58.png▾

  • URGENT Database crashing when having a trigger sending http_request
    a

    akub

    05/18/2023, 8:10 AM
    My database crashes and goes into recovery mode when i have a trigger active that sends a http_request, even authorization doesn't work, no request can go through. More details in pictures and here is my definition of the custom send http request function:
    Copy code
    DECLARE
          request_id bigint;
          payload jsonb;
          url text := TG_ARGV[0]::text;
          method text := TG_ARGV[1]::text;
          headers jsonb DEFAULT '{}'::jsonb;
          params jsonb DEFAULT '{}'::jsonb;
          keys text[] := string_to_array(TG_ARGV[3]::text, ',');
          timeout_ms integer DEFAULT 1000;
        BEGIN
          IF url IS NULL OR url = 'null' THEN
            RAISE EXCEPTION 'url argument is missing';
          END IF;
      
          IF method IS NULL OR method = 'null' THEN
            RAISE EXCEPTION 'method argument is missing';
          END IF;
      
          IF TG_ARGV[2] IS NULL OR TG_ARGV[2] = 'null' THEN
            headers = '{"Content-Type": "application/json"}'::jsonb;
          ELSE
            headers = TG_ARGV[2]::jsonb;
          END IF;
      
          IF keys IS NULL THEN
            params = '{}'::jsonb;
          ELSE
            params = get_query_parameters(VARIADIC keys);
          END IF;
      
          IF TG_ARGV[4] IS NULL OR TG_ARGV[4] = 'null' THEN
            timeout_ms = 1000;
          ELSE
            timeout_ms = TG_ARGV[4]::integer;
          END IF;
          url := get_env(url);
          CASE
            WHEN method = 'GET' THEN
              SELECT http_get INTO request_id FROM net.http_get(
                url,
                params,
                headers,
                timeout_ms
              );
            WHEN method = 'POST' THEN
              payload = jsonb_build_object(
                'old_record', OLD, 
                'record', NEW, 
                'type', TG_OP,
                'table', TG_TABLE_NAME,
                'schema', TG_TABLE_SCHEMA
              );
      
              SELECT http_post INTO request_id FROM net.http_post(
                url,
                payload,
                params,
                headers,
                timeout_ms
              );
            ELSE
              RAISE EXCEPTION 'method argument % is invalid', method;
          END CASE;
        
          INSERT INTO supabase_functions.hooks
            (hook_table_id, hook_name, request_id)
          VALUES
            (TG_RELID, TG_NAME, request_id);
            
          RETURN NEW;
        END

    https://cdn.discordapp.com/attachments/1108667802111459369/1108667802757374022/image.png▾

    https://cdn.discordapp.com/attachments/1108667802111459369/1108667803155824710/image.png▾

    s
    • 2
    • 4
  • supabase resumable upload , endpoint not found 404
    m

    Mhamad Othman

    05/18/2023, 11:11 AM
    The Resumable upload method is not working for me i get 404 error , my supabase storage link is like this 👇 const supabaseUploadURL =
    https://${projectId}.supabase.co/storage/v1/upload/resumable
    g
    • 2
    • 4
  • Trigger not possible on foreign key fields?
    o

    OyugoObonyo

    05/18/2023, 12:08 PM
    I have a public.users table(an image with its schema is attached) that references auth.users. Public.users is auto-populated by a trigger that inserts a row into it any time there's an insert into the auth.users. The insert_user trigger is as follows:
    Copy code
    create or replace function public.handle_new_user()
    returns trigger
    language plpgsql
    security definer
    as $$
    begin
      insert into public.users(id, phone_number, password_hash, created_at, updated_at)
      values (new.id, new.phone, new.encrypted_password, new.created_at, new.updated_at);
      return new;
    end;
    $$;
    
    drop trigger if exists on_auth_user_created on auth.users;
    
    create trigger on_auth_user_created
      after insert on auth.users
      for each row execute procedure public.handle_new_user();
    Also, I have another trigger that fires when auth.users is updated. The trigger effects any update on auth.users to public.users. The update trigger is as follows:
    Copy code
    create or replace function public.handle_user_update()
    returns trigger
    language plpgsql
    security definer
    as $$
    begin
      update public.users
      set
      first_name=new.raw_user_meta_data ->> 'first_name',
      last_name=new.raw_user_meta_data ->> 'last_name',
      -- designation_id=new.raw_user_meta_data ->> 'designation_id',
      -- organization_id=new.raw_user_meta_data ->> 'organization_id'
      updated_at=new.updated_at
      where id=new.id;
      return new;
    end;
    $$;
    
    drop trigger if exists on_auth_user_updated on auth.users;
    
    create trigger on_auth_user_updated
      after update on auth.users
      for each row execute procedure public.handle_user_update();
    This trigger works but until I uncomment .
    designation_id=new.raw_user_meta_data ->> 'designation_id
    OR
    organization_id=new.raw_user_meta_data ->> 'organization_id'
    . Upon uncommenting them, the update user logic returns
    {"user": null}
    . What could be the reason why my trigger stops working as excepted as soon as I include either of them? Is sit because they're foreign keys and I'm not handling them in the right manner?

    https://cdn.discordapp.com/attachments/1108727740644995252/1108727740770828411/public_users_schema.png▾

    g
    • 2
    • 4
  • Cannot find SupabaseListener
    b

    brain

    05/18/2023, 1:05 PM
    I'm following the NextJs (app) tutorial for Supabase Auth and when adding the SupabaseProvider to
    Layout.tsx
    I'm running into an error of
    Cannot find name 'SupabaseListener'.
    and
    Cannot find name 'session'.
    . I've been unable to find any documentation on the SupabaseListener component. Any help would be apprciated https://supabase.com/docs/guides/auth/auth-helpers/nextjs-server-components
    g
    • 2
    • 1
  • Is there a GUI-based combinator that makes Supabase RLS easier?
    u

    <hmmhmmhm/>

    05/18/2023, 1:42 PM
    Explaining to others how to write an RLS Policy is often a bit complicated. A.I is often used to write and solve this problem, but this is often a problem when spreading Supabase to other developers. If I use a Supabase Edge Function to avoid writing a complex RLS, is that an anti-pattern...?
    v
    v
    g
    • 4
    • 15
  • Nextjs 13 & Supabase: I don't know how to verify Supabase env. variables based on the new example
    k

    KennStack01

    05/18/2023, 2:25 PM
    Following this guide: https://github.com/supabase/supabase/tree/master/examples/auth/nextjs I am trying to implement User Authentication. 1) How to add NEXT_PUBLIC_SUPABASE_URL & NEXT_PUBLIC_SUPABASE_ANON_KEY as easily as we did in the past? 2) I can't find where to add them, I've added all the details, but can't connect with my Supabase project. Any help? PS: i am new to Nextjs 13. 😦
    t
    s
    g
    • 4
    • 7
  • sunscribe to sql query
    v

    Viky

    05/18/2023, 3:24 PM
    I want to subscribe to query result in supabase from browser / client side. So my query will always in sync to postgres. Is there a way to do that ?
    g
    r
    • 3
    • 36
  • Changing a JSON element in a JSON object without overwriting other elements
    w

    WaviestBalloon

    05/18/2023, 3:51 PM
    First time posting here, sorry. Might be a completely stupid question, but recently I have decided to move from Enmap to Supabase, so far I'm in love with this service but I've only encountered one roadblock. Sometimes I need to change one part of a JSON object:
    Copy code
    javascript
    {
        messageCount: x,
        commandCount: x <-- only want to modify this element
    }
    I have a very inefficient way of combating this issue, fetching the JSON from the row, then changing the elements that I need to change and then writing it to the row. This works decently, even if it's sending about 2-3 completely unnecessary requests on every requested change, but I can live with it. Another issue pops up, sometimes two changes are made and they conflict and overwrite each other:
    self: { commandCount: 14, messageCount: 1355 }
    self: { commandCount: 15, messageCount: 1356 }
    self: { commandCount: 14, messageCount: 1357 }
    First time posting here, sorry if I got anything wrong! Appreciated
    g
    • 2
    • 3
  • Run new migrations on local with CLI
    b

    bombillazo

    05/18/2023, 3:53 PM
    Hello, on local dev, how can we run incoming new migrations with the supabase CLI? We don't want to use
    supabase db reset
    because it destroys the local DB, we simply want to run the missing migrations on our local so we can be on par with our deployed schema.
    s
    v
    • 3
    • 4
  • How to debug "Invalid refresh token: Refresh token not found" error?
    m

    Miles

    05/18/2023, 4:19 PM
    Using the Supabase client library on iOS, I frequently get logged out of the app with the following error:
    GoTrue.GoTrueError.APIError(message: nil, msg: nil, code: nil, error: Optional("invalid_grant"), errorDescription: Optional("Invalid Refresh Token: Refresh Token Not Found")
    What does refresh token not found mean exactly? How could I go about debugging why this happens, as the client library should be handling refreshing automatically? Before any authenticated request I call
    let session = try await supabaseClient.auth.session
    , and this error happens on that line.
    g
    • 2
    • 41
  • CLI login
    p

    P-a

    05/18/2023, 4:54 PM
    I am unable to write anything in the password field when using pnpm supabase login or pnpm supabase link... any idea why ?
  • OOM when running API fuzzing locally
    d

    Dan Rumney

    05/18/2023, 5:08 PM
    I've been running an API fuzzer locally against my endpoints (Mayhem for API) I run my functions with this command:
    Copy code
    supabase functions serve --env-file .functions.env
    The fuzzing works fine, but I invariably end up with this error:
    Copy code
    <--- Last few GCs --->
    
    [1:0xfffe394987d0]      272 ms: Scavenge 13.3 (14.3) -> 13.1 (14.3) MB, 0.8 / 0.0 ms  (average mu = 1.000, current mu = 1.000) allocation failure; 
    [1:0xfffe394987d0]      280 ms: Scavenge 13.3 (14.3) -> 13.2 (14.3) MB, 2.2 / 0.0 ms  (average mu = 1.000, current mu = 1.000) allocation failure; 
    [1:0xfffe394987d0]      284 ms: Scavenge 13.2 (14.3) -> 13.2 (14.3) MB, 3.0 / 0.0 ms  (average mu = 1.000, current mu = 1.000) task; 
    
    
    <--- JS stacktrace --->
    
    
    #
    # Fatal javascript OOM in NewSpace::EnsureCurrentCapacity
    #
    
    Error: error running container: exit 133
    I don't think the fuzzer is submitting any requests that would, on their own, result in OOM. Has anyone else seen anything like this while serving their functions locally for an extended period of time or after a certain number of requests? Are there any known memory leaks in the local implementation?
1...218219220...230Latest