https://supabase.com/ logo
Join DiscordCommunities
Powered by
# help-and-questions
  • Trying to insert with RLS / Failing
    n

    nickbryant.fyi

    05/20/2023, 5:25 PM
    I saw with RLS I can only do a check instead of using so i wrote this policy and function:
    Copy code
    -- Function to check if the user is the creator of the organization
      CREATE OR REPLACE FUNCTION public.has_created_org(
        user_id UUID,
        organization_id UUID
      )
      RETURNS BOOLEAN AS
      $$
      DECLARE
        user_is_creator BOOLEAN;
        v_user_id UUID := user_id;
        v_organization_id UUID := organization_id;
      BEGIN
        SELECT COUNT(*) > 0
        INTO user_is_creator
        FROM public.organizations AS orgs
        WHERE orgs.id = v_organization_id AND orgs.created_user_id = v_user_id;
    
        RETURN user_is_creator;
      END;
      $$
      LANGUAGE plpgsql;
    Policy:
    Copy code
    CREATE POLICY "organization_roles_policy_org_level" ON "public"."organization_roles"
      FOR INSERT
      WITH CHECK ((has_created_org(auth.uid(), organization_id));
    The only other policies i have for the table organization_roles are for update/delete and select. they are different. I had my user successfully create an organization and i tested has_create_org via CLI and ensured that indeed
    organization_roles.organization_id
    and the user's
    auth.id
    do return TRUE from this function. This is the code im invoking:
    Copy code
    await client.from('organization_roles').insert({
        organization_id: newOrg.id,
        user_id: currentUser.id,
        role: 'OWNER',
      })
    And this is the result:``` "new row violates row-level security policy for table \"organization_roles\""``` I've been working on this for hours so any help would be very appreciated. I just want better ways to debug these policies and stuff.
    g
    • 2
    • 29
  • Failed to create trigger: failed to create pg.triggers: zero-length delimited identifier at or near
    c

    cyberpunq

    05/20/2023, 5:40 PM
    I basically want to create a database trigger for when something gets inserted into the "organizations" table, but whatever I do, I get this error:
    Copy code
    Failed to create trigger: failed to create pg.triggers: zero-length delimited identifier at or near """"
    See relevant screenshot.

    https://cdn.discordapp.com/attachments/1109536261682766017/1109536261909266462/pgtrigger.png▾

    g
    • 2
    • 2
  • Join function replacement?
    w

    Will_Buyers

    05/20/2023, 6:27 PM
    What can I use instead of SQL's join function? My query is SELECT movies.* FROM movies JOIN watchlist ON movies.id = watchlist.movie_id JOIN profiles ON profiles.id = watchlist.user_id WHERE profiles.id = user_id; I want to basically convert this into supabase-js's query to fetch data, how can I do that as there is no join function in supabase-js lib.
    g
    y
    • 3
    • 27
  • Ordering nested query
    z

    zerosodium

    05/20/2023, 6:44 PM
    Is there a way to order the bids array even though it's nested?
    Copy code
    js
    const { data, error } = await supabase
        .from("restaurants")
        .select(
          `
        *,
        reservations (
          *,
          bids (
            *
          )
        )
      `
        )
        .eq("venue_id", venue_id);
    g
    • 2
    • 5
  • How to subscribe to a table using 2 filters?
    o

    osamita

    05/20/2023, 7:10 PM
    In the supabase docs, in the filter sections, says that I can do a filter like 'column_one=eq.value,column_two=eq.other_value' and I need to do that but when subscribe to a channel... I'm doing something like that Generic example: let channel = await supabase .channel('any') .on( "postgres_changes", { event: "INSERT", schema: "public", table: "my_table", filter:
    column_one=eq.value,column_two=eq.other_value
    , }, () => { alert('row inserted'); } ) .subscribe() but the event does not execute the function with two filter, only with just one. is there a way to subscribe to a channel using more than one filter?
    g
    • 2
    • 3
  • How to get user id in postgres function?
    c

    cyberpunq

    05/20/2023, 7:54 PM
    As you know, you insert into tables in a postgres function by getting values from the
    new
    object. How does one get the
    user_id
    of the user who triggered the trigger that called this function? Help would be appreciated! This is my script:
    Copy code
    begin
    
    insert into public.members(user_id, organization_id, is_admin)
    values(???, new.id, true)
    
    end;
    g
    • 2
    • 2
  • Self-hosted edge functions crash on subsequent request
    n

    nicolasstrands

    05/20/2023, 8:20 PM
    Hello, does anyone have any experience regarding regarding self-hosted edge functions using Docker? I'm currently having a weird bug where my functions run fine the first time but whenever I try a second request to any of its endpoint, it crashes and I get a message saying the following:
    Copy code
    hyper::Error(User(Service), operation was canceled: connection was not ready
    
    Caused by:
        connection was not ready)
    Anyone knows where I should be looking to solve this by any chance?
  • Not getting realtime updates
    h

    Hugos

    05/20/2023, 9:12 PM
    I have this realtime channel setup using the javascript client but am not getting any updates when inserting records:
    Copy code
    ts
            const channel = supabase
                .channel('incoming-messages')
                .on(
                    'postgres_changes',
                    { event: 'INSERT', schema: 'public', table: 'messages', filter: `room_id=eq.${room.id}` },
                    (payload: Message) => {
                        console.log(payload);
                        messages.push(payload);
                    } 
                )
                .subscribe();
    g
    • 2
    • 5
  • nixos supabase
    p

    peter-lustig

    05/20/2023, 9:17 PM
    any idea why i have to prefix all supabase commands of the package supabase-cli with sudo? otherwise no permissions i just created a dev shell with supabase it uses docker so i also put virtualisation.docker.enable = true
    s
    • 2
    • 1
  • Is there any way to cancel launched queries?
    h

    heypex

    05/20/2023, 9:24 PM
    I'm curious if there is something like CancelToken from flutter 'dio' package that allows to cancel http requests but for supabase queries
    g
    • 2
    • 2
  • How to join on auth.users using the supabse js client
    h

    Hugos

    05/20/2023, 10:04 PM
    I have 2 tables that I created ``profiles`` and ``messages`` a message row has a column ``author`` which is a FK on auth.users a profile has a column ``user_id`` which is a FK on auth.users I was wondering if i can retreive the ``profiles.username`` using joins when retreiving all messages so something like:
    Copy code
    js
    await supabase
    .from('messages')
    .select(`
      *,
      auth.users (
        profiles (username)
      )
    `);
    But this does not work.
    g
    • 2
    • 14
  • Open.ai w/ supabase?
    b

    Ben-jam-in

    05/20/2023, 10:51 PM
    I have tried looking and have been unsuccessful finding if there is anyway to link GPT in a way to have it analyze some data in a table? Any help or tips are more than needed! Thanks in advance.
    c
    • 2
    • 3
  • Help setting up classes in C# for tables that reference other tables
    i

    Infraction

    05/20/2023, 11:15 PM
    I am having issues creating tables that reference related tables in c#. I tried following the example from postgrest-csharp and when I add the reference(typeof(releatedclass)) attribute and then go to add them to the database the id fields get left as null. I am sure I am missing something simple but not sure what it would be
  • For individual access to a storage files, do I also need to include the bucket_id?
    p

    Panda

    05/21/2023, 6:39 AM
    Supabase documentation: https://supabase.com/docs/guides/storage/access-control#allow-individual-access-to-a-file
    Copy code
    -- 1. Allow a user to access their own files
    create policy "Individual user Access"
    on storage.objects for select
    using ( auth.uid() = owner );
    Would applying a policy this way be applied to all storages? Should I specify the
    bucket_id
    if I want it applied to a specific bucket?
    g
    • 2
    • 4
  • What is aud column in auth.users table?
    e

    EKI

    05/21/2023, 7:11 AM
    I'm experimenting with the supabase and came across to auth.users table and want to know what does aud column means in auth.users table. And can i change "role" column in auth.users according to my need? Is it good idea or I shouldn't be touching this tables as they are maintained by supabase team?
    j
    • 2
    • 1
  • Is there any guide to using DrizzleORM with Supabase anywhere? Similar to the Prisma guide.
    p

    pjs

    05/21/2023, 7:29 AM
    I'm building a standalone API where I'm keen to have automatically typed entities and abstraction away from the supabase js client. I've looked into Prisma, but I prefer the syntax and typescript experience of Drizzle. Just wondering if there's anything special I need to do for auth here? Is there a guide to using this ORM with Supabase?
  • Storing secret in user_metadata
    k

    kenrhee

    05/21/2023, 7:54 AM
    I am wondering if it is OK / Not OK to store secret (e.g. 3rd party access token) in user_metadata. thanks for any advice.
    g
    • 2
    • 1
  • Do I need to access to the liste Stream ?
    p

    Philipp_Nut

    05/21/2023, 8:05 AM
    Hello, I am using a StreamProvider from RIverpod. I although using a stream there from the table. Do I need the .liste to listen to changes or is the .stream enough ?
    w
    g
    • 3
    • 4
  • Supabase Flutter Web OAuth Redirect Issue
    z

    zwarag

    05/21/2023, 10:13 AM
    Copy code
    dart
    import 'package:flutter/foundation.dart';
    import 'package:flutter/material.dart';
    import 'package:flutter_riverpod/flutter_riverpod.dart';
    import 'package:spacevault_cash/constants.dart';
    import 'package:supabase_flutter/supabase_flutter.dart';
    import 'package:supabase/supabase.dart' as supabase_;
    
    import '../services/supabase_service.dart';
    
    class TestPage extends ConsumerWidget {
      const TestPage({Key? key}) : super(key: key);
    
      @override
      Widget build(BuildContext context, WidgetRef ref) {
        final user = ref.watch(userProvider);
        print(supabase.auth.currentSession);
    
        // Use the user variable here
        return ElevatedButton(
          onPressed: () {
            ref.read(supabaseProvider).auth.signInWithOAuth(
                supabase_.Provider.github,
                redirectTo: kIsWeb ? null : authRedirectUrl);
          },
          child: Text(user != null ? 'Logged in' : 'Login'),
        );
      }
    }
    I'm having trouble authenticating users when using the web client. When clicking on the button, the user gets redirected to github. After entering valid credentials, the users gets sent back to the application, however
    supabase.auth.currentSession
    prints
    null
    . However, I can see the access_token in the url bar, so it should actually have everything it needs. Any Ideas? Just for context: This works fine for iOS and Android
    g
    • 2
    • 2
  • new row violates row-level security policy for table "stories"
    s

    statuscode200

    05/21/2023, 10:15 AM
    I am writing a script to scrap data from web and insert data into DB. https://stackoverflow.com/questions/76299325/new-row-violates-row-level-security-policy-for-table-stories
    g
    • 2
    • 3
  • How to export SQL schema as JSON?
    w

    Waldemar

    05/21/2023, 10:58 AM
    Currently I have a huge SQL script that I copy&paste and run in SB SQL Editor to (re)create our entire DB schema, including tables, FKs, indexes etc. I want to replace this hardcoded SQL script (as much as possible) with something more dynamic, so I can: 1) (Re)create the schema programmatically (e.g. by generating SQL from JSON and executing via
    pg
    ) 2) Extend it with some access control rules (RBAC) for checking on the server-side code (e.g. which user role can insert/update which tables and columns) We tried Postgresql RLS, but it doesn't work for us I looked into generic tools that can generate JSON from Postgresql schema, such as: https://github.com/tjwebb/pg-json-schema-export https://www.pg-structure.com/ ...but didn't manage to make them work and they seem too complicated for once-off use. Also I know there is https://supabase.com/docs/guides/api/rest/generating-types ...but it generates TypeScript, which I understand won't give me the 1) and 2) above. Then there are tools like Prisma, but again, I don't think I can do 2) wit it and it is a full blown ORM and also an overkill for what I need anyway. Can you recommend other ways / tools how I can do it? I imagine something like:
    Copy code
    {
      tables: [
        {
          name: orders,
          columns: [
            {
              name: 'id',
              type: 'TEXT'
            }
          ],
          constraints: [
            ...
          ]
        }
      ]
    }
    Thanks!
  • Cannot insert in table with RLS
    f

    FirePuffin

    05/21/2023, 11:09 AM
    Hello everyone. This is my first time with Supabase so it might be a simple question but I have trouble with RLS for authenticated users. I need a database in which only a JS script I have made could have insert access. For doing this I created a user "dev@my.app" and I set a RLS with this expression ((auth.jwt() ->> 'email'::text) = 'dev@my.app'::text). However, it does not work at all. In my app I still have new row violates row-level security policy for table "...". I wondered if the technique I am using is even good to do? How would you guys fix it or how would you proceed to make it so that only my script could insert to my DB. Thank you very much !

    https://cdn.discordapp.com/attachments/1109800047186558996/1109800047643721808/image.png▾

    a
    • 2
    • 7
  • How does a third party web app get Supabase Typescript Typing?
    u

    <hmmhmmhm/>

    05/21/2023, 12:04 PM
    I know that I can get the database Typescript Typing with the command below. Is there any way to get the type information of Web App Tool for Supabase Database with Web API? npx supabase gen types typescript --project-id "" --schema public > types/supabase.ts
    s
    • 2
    • 5
  • Can you perform a inner join inside realtime channel
    h

    Hugos

    05/21/2023, 12:16 PM
    I have a realtime channel and everytime an insert happens I would like to perform an inner join before the insert gets broadcast to the subscribed clients, is this possible?
    g
    • 2
    • 2
  • Can I send customized auth emails?
    l

    Lorenium

    05/21/2023, 1:47 PM
    I wanna send dynamic (localized) mjml email templates through supabase auth. Is there a way? I couldn't find enough info on the documentation. By auth emails I mean password reset, email confirmation etc..
    g
    • 2
    • 1
  • Cannot use Storage locally
    e

    ericrav

    05/21/2023, 2:02 PM
    I just upgraded local Supabase to
    1.62.3
    and when I visit the Storage page in my local Studio it displays "Internal Server Error" and I can't create buckets. Looking at the logs in docker, I see:
    Copy code
    DBError: new row violates row-level security policy
        at DBError.fromDBError (/app/dist/storage/database/knex.js:416:16)
        at Function.<anonymous> (/app/dist/storage/database/knex.js:351:31)
        at Function.emit (node:events:513:28)
        at Function.emit (node:domain:489:12)
        at Client_PG.<anonymous> (/app/node_modules/knex/lib/knex-builder/make-knex.js:299:10)
        at Client_PG.emit (node:events:525:35)
        at Client_PG.emit (node:domain:489:12)
        at /app/node_modules/knex/lib/execution/internal/query-executioner.js:46:12
        at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
        at async Runner.ensureConnection (/app/node_modules/knex/lib/execution/runner.js:300:14) {
      statusCode: 403,
      error: 'Unauthorized',
      originalError: error: 
              SELECT
                set_config('role', $1, true),
                set_config('request.jwt.claim.role', $2, true),
                set_config('request.jwt', $3, true),
                set_config('request.jwt.claim.sub', $4, true),
                set_config('request.jwt.claims', $5, true),
                set_config('request.headers', $6, true),
                set_config('request.method', $7, true),
                set_config('request.path', $8, true);
           - permission denied to set role "service_role"
          at Parser.parseErrorMessage (/app/node_modules/pg-protocol/dist/parser.js:287:98)
    t
    v
    • 3
    • 9
  • Server sided auth issue
    t

    Torwent

    05/21/2023, 2:03 PM
    I'm trying to login with email and password on a SvelteKit server and while the method returns successful if I try to do anything after or check the user is always null. This snipped recreated my issue:
    Copy code
    typescript
            const { data, error } = await supabase.auth.signInWithPassword({
                email: SERVICE_USER,
                password: SERVICE_PASS
            })
    
            if (error) {
                console.error(error)
                return fail(500, { form })
            }
    
            console.log(data) //prints the logged in user information correctly
            console.log((await supabase.auth.getUser()).data) //prints { user: null }
    Naturally, since the current user is null anything I try to do will work as if I wasn't logged in.
    @supabase/supabase-js 2.22.0
    Can anyone tell me if it's something I'm doing wrong? because this is driving me insane!
    j
    • 2
    • 20
  • Stripe integrations
    m

    Moeed

    05/21/2023, 2:04 PM
    I've been struggling to find a simple solution for stripe integration for supabase. Does something like that exists or is it something I'd have to do manually?
    g
    • 2
    • 2
  • About Using Supabase Auth with Next Helper (app directory)
    t

    tererun / てれるん

    05/21/2023, 2:32 PM
    I want to use the Supabase Auth Next Helper with app directory, so I refer to this article: https://supabase.com/docs/guides/auth/auth-helpers/nextjs-server-components However, I don't know how to define the "session" variable and SupabseListener component. What should I do? https://supabase.com/docs/guides/auth/auth-helpers/nextjs-server-components#supabase-provider
    Copy code
    ts
    import './globals.css'
    import SupabaseProvider from './supabase-provider'
    
    export const metadata = {
      title: 'Create Next App',
      description: 'Generated by create next app',
    }
    
    export default function RootLayout({ children }: { children: React.ReactNode }) {
      return (
        <html lang="en">
          <body>
            <SupabaseProvider session={session}> { /* <- here */ }
              <SupabaseListener serverAccessToken={session?.access_token} />
              {children}
            </SupabaseProvider>
          </body>
        </html>
      )
    }
    Thank you!
  • Create new row automatically when user signs up
    m

    Motz

    05/21/2023, 3:26 PM
    So my setup is the following: I have the standard user-profiles table from the template. Additionally, I created a second table called tokens, which is there to track how many tokens each user has left if they make requests to my API. I subtract from that number in an edge function. There's a column called 'id' which is mapped to the profiles table via a foreign key set to delete automatically if the profiles row is deleted. Now when a new user signs up or is created in some other way, I want a row to be inserted into that table with the default amount of tokens. I saw that there was a sql function called "handle_new_user", can I somehow add the functionality I want into there?
    g
    • 2
    • 1
1...221222223...230Latest