https://supabase.com/ logo
Join Discord
Powered by
# help-and-questions
  • Any way to change the port that pgBouncer uses?
    a

    anderjaska

    08/31/2022, 3:59 PM
    above
    g
    • 2
    • 18
  • Why is current_setting not recognized in the SQL editor?
    f

    florian_engl

    08/31/2022, 5:04 PM
    I try to implement this function and it seems current_setting is not available.
    g
    • 2
    • 1
  • Supabase gen types fails
    j

    Julien

    08/31/2022, 5:57 PM
    I have linked my project using: ``supabase link --project-ref myProjectRef`` But then, when I do: ``supabase gen types typescript > src/app/entities/database-definitions.ts`` I get: ``Error: Could not find the linked project for the logged-in user. Try running supabase link again`` Any idea on how to solve that?
    s
    • 2
    • 10
  • How to make storage send back raw html document
    q

    Qiushi

    08/31/2022, 6:06 PM
    I am using supabase storage to store some user-generated html files. When I enter the object url in my browser, I get back the HTML source code instead of the rendered content. I also tried to use the object URL in a iframe's
    src
    attribute, but it loads all the html content in a
    pre
    tag, so it ends up showing the code again. Is there a option to let storage sends back the raw html code?
    j
    g
    • 3
    • 14
  • RLS not working on my roles table
    j

    jxyz

    08/31/2022, 6:38 PM
    I'm trying to implement RBAC. My RLS works on my "permissions" and "user_roles" table, but not on my "roles" table. Any ideas why?
    Copy code
    sql
    CREATE TYPE "role" as enum ('administrator', 'moderator');
    CREATE TYPE "scope" as enum ('authentication', 'authorization');
    CREATE TYPE "action" as enum ('read', 'write');
    
    CREATE TABLE "roles" (
      "id" bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
      "name" role NOT NULL
    );
    CREATE TABLE "permissions" (
      "id" bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
      "role_id" bigint REFERENCES "roles" ON DELETE CASCADE NOT NULL,
      "scope" scope NOT NULL,
      "actions" action[] NOT NULL
    );
    CREATE TABLE "user_roles" (
      "id" bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
      "user_id" uuid REFERENCES auth.users ON DELETE CASCADE NOT NULL,
      "role_id" bigint REFERENCES "roles" ON DELETE CASCADE NOT NULL
    );
    
    ALTER TABLE "roles" ENABLE ROW LEVEL SECURITY;
    ALTER TABLE "permissions" ENABLE ROW LEVEL SECURITY;
    ALTER TABLE "user_roles" ENABLE ROW LEVEL SECURITY;
    
    -- let users see their roles based on their user_roles
    -- [ ] OK
    CREATE POLICY "roles: select" ON "roles" AS PERMISSIVE
    FOR SELECT TO authenticated USING (
      EXISTS (
        SELECT 1 FROM "user_roles" as user_role
        WHERE user_role.role_id = "id"
        AND user_role.user_id = auth.uid()
      )
    );
    
    -- let users see their permissions based on their user_roles
    -- [x] OK
    CREATE POLICY "permissions: select" ON "permissions" AS PERMISSIVE
    FOR SELECT To authenticated USING (
      EXISTS (
        SELECT 1 FROM "roles" as role
        WHERE role.id = "role_id"
        AND EXISTS (
          SELECT 1 FROM "user_roles" as user_role
          WHERE user_role.role_id = role.id
          AND user_role.user_id = auth.uid()
        )
      )
    );
    
    -- let users see their user_roles
    -- [x] OK
    CREATE POLICY "user_roles: select" ON "user_roles" AS PERMISSIVE
    FOR SELECT To authenticated USING (
      "user_id" = auth.uid()
    );
    g
    • 2
    • 6
  • Invalid project ref
    h

    hard2kill

    08/31/2022, 11:48 PM
    Hey guys! When I firstly deployed edge function to the production, I wrote an invalid project ref. For further deployments I use --project-ref flag to override that ref, but there is no such flag in the secrets commands. So every time I use secrets command, I get the error
    Copy code
    Error: Invalid project ref format. Must be like `abcdefghijklmnopqrst`.
    . How can I fix that?
  • Normalizing SQL Data
    l

    luke90275

    09/01/2022, 6:25 AM
    Hi, I just read this article: https://redux.js.org/usage/structuring-reducers/normalizing-state-shape and it resolved a lot of problems I was contemplating. Which packages (if any) would you suggest for normalizing SQL data from supabase? (I'm also using typescript, react query, and zustand if helpful)
  • Error invalid input syntax for type bigint
    w

    whiskeywizard

    09/01/2022, 7:20 AM
    Hi, I have a many-to-one relationship, both using generated UUIDs as the primary keys, and the foreign key. Using the JS library I'm doing this to get the foreign elements: await supabase.from('invoice_item').select('*').eq('invoice_id', sInvoiceID); But I'm getting this JS error: invalid input syntax for type bigint: "89d3477e-6044-42ae-bc6f-de1d9a763fg8" I've double checked that the primary keys and foreign key are all UUID type and valid. Any ideas? Thanks.
    g
    • 2
    • 3
  • User roles permissions
    k

    kresimirgalic

    09/01/2022, 7:59 AM
    Whats the best way to integrate user roles permissions?
    o
    u
    g
    • 4
    • 6
  • Auth Ui
    s

    Satou kuzuma

    09/01/2022, 8:35 AM
    I'm trying to use the Auth component from the Auth ui library. I saw the example on the docs and a just copied but I'm getting something completely different from what showed in the video in the docs.
    o
    • 2
    • 2
  • What AWS service does supabase use to automatically provision new cloud for new projects?
    g

    Guru

    09/01/2022, 3:16 PM
    Which AWS service can provision new instances to new projects programmatically?
  • is server down
    l

    LEGEND

    09/01/2022, 4:16 PM
    please help me
    g
    • 2
    • 2
  • How do I filter a table with foreign key using postgrest?
    s

    stha_ashesh

    09/01/2022, 4:45 PM
    TLDR: I am looking postgrest equivalent of
    Copy code
    SQL
    SELECT * 
    FROM "movie_database"
    WHERE "movie_database"."mov_id" IN (
      SELECT "genre".mov_id
      FROM "genre"
      where "genre".genre_val=[some_value]
    )
    --- I have two tables -
    movie_database
    table and
    genre
    table.
    movie_database
    table has
    mov_id
    primary key.
    genre
    table has
    mov_id
    (foreign key referring to movie_database) and
    genre_val
    . Right now I am doing
    xyz.supabase.co/rest/v1/genre?genre_val=eq.[some_value]&select=movie_database(*)
    It would seem okay but I feel like it is joining rather than just pure filtering. Because when we do just filter without foreign key, I get
    Copy code
    [
        {movie_database item 1},
        {movie_database item 2}
    ]
    But right now I am getting following structure.
    Copy code
    [
        {
            "movie_database": {movie_database item 1},
        },
        {
            "movie_database": {movie_database item 1},
        },
    ]
    v
    • 2
    • 3
  • Hey ppl quick question, how do i return the columns of a table in js even if the table has no rows
    a

    arch

    09/02/2022, 5:32 AM
    Hey people so how do i return the column names of a specific table in js, even if the table has no rows.
    o
    t
    • 3
    • 4
  • How to use composite key as foreign key in another table?
    u

    ํ˜„์šฐHyeon

    09/02/2022, 5:43 AM
    I have a room table which has composite keys (creator_id, editor_id) as primary keys and I want to point them from another table called message but there's no option for designating composite keys for foreign key relation. What's the practical way of doing this? Do I need to create a new column in room table with unique id?
    j
    • 2
    • 1
  • Something's funky with Postgres Triggers
    j

    jaitaiwan

    09/02/2022, 6:42 AM
    Hi Folks, when trying to create a trigger if I use
    CREATE OR REPLACE TRIGGER
    there's a syntax error for
    TRIGGER
    but if I remove
    OR REPLACE
    then it works perfectly. According to
    SELECT version()
    I'm using postgres 14 so I don't understand why it's not working. Supabase Cloud
    u
    g
    • 3
    • 9
  • Authenticate login with tiktok
    s

    slurp

    09/02/2022, 7:06 AM
    does anyone on the @User know if there are plans to add tiktok to the list of authentication options?
    m
    • 2
    • 1
  • Supabase function invite user
    d

    DevThoughts

    09/02/2022, 8:46 AM
    I would like to invite user from Supabase dashboard, then as soon user click on Accept invitation, new email should send for create password. Any one?
  • auth helper not allowing pages to load
    c

    CANDY

    09/02/2022, 8:51 AM
    I am getting the "TypeError: authListener.unsubscribe is not a function" error when trying to load any page after setting up the auth helper as described here: https://github.com/supabase/auth-helpers/blob/main/packages/nextjs/README.md
    s
    g
    • 3
    • 6
  • (solved) Edge Function that sends an HTTP request
    b

    boeledi

    09/02/2022, 9:10 AM
    Hi All, I am totally new to Supabase and I have a very basic/stupid question. How can I send an HTTP (POST) request inside an Edge Function? I have imported 'node-fetch' and wrote a very basic code, but when I try to either 'serve' or 'deploy' the function, it tells me that there is a problem with the way I am importing 'fetch' Here is the code I have which even does not invoke the 'fetch'
    Copy code
    import { serve } from "https://deno.land/std@0.131.0/http/server.ts";
    import fetch  from "../../../node_modules/node-fetch";
    
    console.log("Hello from Functions!")
    
    serve(async (req) => {
      const { name } = await req.json()
      const data = {
        message: `Hello ${name}!`,
      }
    
      return new Response(
        JSON.stringify(data),
        { headers: { "Content-Type": "application/json" } },
      )
    })
    Many thanks for your help
    o
    • 2
    • 2
  • (solved) Define custom domain specific `PostgrestFilterBuilder` operation in typescript
    b

    bent

    09/02/2022, 10:20 AM
    I have this snippet
    Copy code
    ts
    .or(`discord.eq.${user.username}#${user.discriminator}, discord_id.eq.${user.id}`)
    that I'd like to replace with
    .user(user)
    . I think I'm looking for extension methods / blanket implementations, but I'm struggling to pull it off. I was able to do this simpler one
    Copy code
    ts
    declare global {
      interface Array<T> {
        pickAny(): T;
      }
    }
    Array.prototype.pickAny = function <T,>() { return (this as Array<T>)[Math.floor(Math.random() * (this as Array<T>).length)] }
    export { }
    but this principle doesn't seem to work with `PostgrestFilterBuilder`s. basically I want to do stuff like this https://diesel.rs/guides/composing-applications.html
    • 1
    • 1
  • how to properly upload image then update relative row in database?
    l

    Lukas V

    09/02/2022, 1:13 PM
    Hello, I am trying to create a post which contains an image. Currently I am: 1. creating a post in the database 2. uploading an image to storage with created post id 3. updating the post row with my storage baseUrl + the stored image data
    Key
    Here is my code: Is this how it's supposed to be done? What happens if one of the api calls fail? How would I handle these errors?
    Copy code
    const onSubmit: SubmitHandler<Inputs> = async (data) => {
      try {
        if (file && user?.id) {
          new Compressor(file, {
            quality: 0.8,
            height: 1350,
            width: 1080,
            resize: 'cover',
            convertTypes: 'image/png', // here it converts to jpg after size exceeds 50kb
            convertSize: 50000,
            async success(result) {
              const { data: postsData } = await supabase
                .from('posts')
                .insert({
                  caption: data.caption,
                  created_by: user.id,
                  image_url: 'placeholder'
                });
              const { data: imageData } = await supabase.storage
                .from('user-content')
                .upload(`${user.id}/posts/${postsData?.[0].id}.jpeg`, result, {
                  contentType: 'image/jpeg'
                });
                await supabase
                .from('posts')
                .update({
                  image_url: `https://smldlcomasdasdddnjg.supabase.co/storage/v1/object/public/${imageData?.Key}`
                })
                .eq('id', postsData?.[0].id);
            }
          });
        }
      } catch (error) {
        console.log(error);
      }
    };
    g
    • 2
    • 1
  • hi did supabase-js v2 remove redirectTo from signInWithPassword function?
    g

    gaIaxy

    09/02/2022, 2:34 PM
    previously I could do const { error } = await supabase.auth.signIn({ email, password, {redirectTo: window.location.origin} });
    g
    a
    • 3
    • 9
  • Typing completely broken since Supabase 2.0
    j

    Julien

    09/02/2022, 2:37 PM
    Supabase 2.0 has broken the typing everywhere I use Supabase in my code
    t
    t
    • 3
    • 5
  • Possible to generate precise types for postgres functions?
    e

    Embm

    09/02/2022, 2:37 PM
    Using the CLI's type generation workflow, I can see the result includes some return type for postgres functions, but the generated types aren't that useful when it comes to cases of functions using
    json_build_object(...)
    as it looks like it's not parsing the inner contents of the query and simply outputs a basic
    Record
    type:
    Copy code
    ts
    some_postgres_function: {
        Args: Record<PropertyKey, never>;
        Returns: Json;
    };
    Is there any way to generate more precise types or do I need to manually define some interface/type and make sure to keep it in sync with the function's content?
  • Sign up with additional user metadata
    g

    gbb

    09/02/2022, 2:46 PM
    Heyy, I am working on my project, and it's on Remix (nice react framework). I use supabase for authentication and supabase provides a nice way to signup up users using the email and the password, and there is also another field called "data". I have a second table called Profiles and whenever a new user signs up, a function is called that will put that info into the new Table, where I can also add custom fields, as opposed to the default Users table provided by supabase. My question is, how do I actually reference the data in the data field, with postgresql queries? I haven't found a way to reference it. Function that runs when a new user joins: - I want to insert into public.profiles, the info that I receive in the data field sent with the example signup call that I have provided below the sql query.
    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)
      values (new.id, new.email);
      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();
    Example auth:
    Copy code
    const { user, session, error } = await supabase.auth.signUp(
      {
        email: 'example@email.com',
        password: 'example-password',
      },
      {
        data: {
          first_name: 'John',
          age: 27,
        },
      }
    )
    g
    • 2
    • 3
  • Network error when uploading to storage bucket
    y

    ymahmo

    09/02/2022, 3:20 PM
    Hi, for the longest time I was uploading snapshots from my app to a storage bucket but suddenly it stopped working and is now giving me a network error when I try. I use 3 different buckets in different areas and the other 2 still work properly and are almost identical. I tried to create a new bucket and use that instead, it worked for the first two uploads then it started failing again. If anyone else has run into this or something similar, any help would be greatly appreciated. Here's my code and error below: This is using react native and supabase js
    Copy code
    let { data, error: uploadError } = await supabase.storage
                .from("snapshots")
                .upload(response.name, response);
    > Upload Error: [TypeError: Network request failed]
    g
    • 2
    • 1
  • Getting 502 when trying out Auth
    k

    Kylar

    09/02/2022, 5:15 PM
    I'm trying out Supabase Auth again after toying around with it a year ago or so, and when I try to login using the JS sdk I'm getting a 502 error from the upstream server
    Copy code
    error: {
        message: 'An invalid response was received from the upstream server',
        status: 502
      }
    Any ideas on how to debug what is going on?
    g
    • 2
    • 20
  • NextJs SSR `withPageAuth` from `supabaseauth-helpers-nextjs` doesn't pick up the authenticated user
    t

    try_catch.js

    09/02/2022, 6:59 PM
    This is a NextJs project. If I have this button handler code on my SignIn page: ` const { error } = await supabase.auth.signIn( { email }, { redirectTo:
    http://localhost:3000/user/asd
    , } )` Then I click on my email the 'magic link', and then When my protected page
    pages/user/[id].js
    attempts to get the already authenticated user with this
    Copy code
    export const getServerSideProps = withPageAuth({
      redirectTo: '/auth/sign_in_or_create_account',
      async getServerSideProps(ctx) {
        const { user } = await getUser(ctx)
        return { props: { user: user } }
      },
    })
    I'm redirected back to login page when I should stay at
    /user/[id]
    route. How does the server side page can 'know' that the user already clicked the magic link from the email?
    s
    • 2
    • 4
  • Supabase JS-RC8 Inner Join Types
    n

    nahtnam

    09/02/2022, 8:24 PM
    Hello, Is there any way to get the types to work on an inner-join? Supabase is pretty close to getting it. Here is the code I have:
    Copy code
    return supabaseAdminClient.from("feeds").select("*,sources!inner(*)").eq("enabled", true)
    The type is
    { ... feed stuff here } & { sources: unknown }
    so it looks like it recognizes the join but its not filling in the type.
    s
    u
    • 3
    • 3
1...131415...230Latest