https://supabase.com/ logo
Join Discord
Powered by
# help-and-questions
  • Supabase with Next.js 13
    g

    garyaustin

    11/08/2022, 12:13 AM
    try searching for next.js 13 up top. Also

    https://www.youtube.com/watch?v=QH0P5xZt5wY▾

    u
    • 2
    • 2
  • TS settings for VSCode
    r

    rlightner

    11/08/2022, 12:23 AM
    Any suggestions for TS mappings with function sin VSCode? Tired of seeing red squiggles everywhere and having it bomb when I try to deploy bucause it can't figure out mappings for db columns. I'm already importing my Database type and creating the client with that, and also adding
    .returns<{ stripe_customer_id: string | null }>()
    but its not respecting this for some reason
  • Do webhooks or triggers really work?
    l

    lewisd

    11/08/2022, 1:06 AM
    I am migrating my 350 users from firebase to supabase. When I bulk import them into my auth, I have a trigger that listens for inserts and copies to my own public users table. Works fine when I just import 1 user. Any more than one and it fails to complete any
    g
    • 2
    • 22
  • Next.js 13 select from table works but after initial refresh it returns null
    u

    ${fence}

    11/08/2022, 2:08 AM
    I followed this video

    https://www.youtube.com/watch?v=QH0P5xZt5wY&ab_channel=Supabase▾

    and I have data fetching from the the database table working. But when I refresh the page I get returned null. I have to rerun the project for it to then fetch data again.
    l
    • 2
    • 7
  • Validate user permissions
    l

    Lukas

    11/08/2022, 2:48 AM
    I was wondering what the best way is to validate user permissions. Let's say I have a user table that says what permissions they have. In this example, we'll say its creating new documents. The user posts a insert request to the documents table to create a new document. How can I validate that they have this permission?
    g
    • 2
    • 9
  • change auth.users.user_metadat values with trigger function
    u

    ((()))

    11/08/2022, 5:01 AM
    auth.users.user_metadata stores muni_id::int and office_id::int that correspond to munies and offices tabless. How can I delete values for that user or set them to null when I delete munies row or offices row with those ids/
  • change data variable to another name .
    k

    Khalifa007

    11/08/2022, 6:52 AM
    how to change variable from data to data 2 or data2 as i want in typescript . code :
    Copy code
    const { data, error } = await supabase
      .from('users')
      .select(`*`)
      .eq('id', id)
      .limit(1)
      .single()
    j
    • 2
    • 1
  • How do we make a storage.bucket public using an SQL script?
    p

    pvineet44

    11/08/2022, 7:02 AM
    Basically, I intend to write an sql migration to create a storage bucket and make it public.
  • Upload file with full url in table
    k

    kvnfo

    11/08/2022, 8:18 AM
    I'm wanting to add user avatars with full url in the profiles table. I have the following code, how could I do this? instead of /03402043920320avatar.jpg I'd like the entire url
    s
    g
    • 3
    • 6
  • Is Postgres Function rpc() counted as Edge Functions in terms of price?
    w

    wolf5

    11/08/2022, 8:24 AM
    I wonder if the edge function price is applied with Postgres function: rpc()
    g
    • 2
    • 1
  • Select with a match and eq() are not working
    a

    alx90

    11/08/2022, 8:54 AM
    Hey guys, I have a simple data base structure like | BlogId | ArticleId | URL | ... ... ... I try to select from the table like:
    Copy code
    const { data, error } = await supabase
        .from("Articles")
        .select()
        .eq("URL", pageSlug)
        .match({ BlogId: blogId });
    Result is [] <-- Im totally sure my blogId and my URL, pageSlug are identical. Some help maybe :D?
  • bigint value comes back rounded in a query
    r

    Relisora

    11/08/2022, 11:37 AM
    Hi, I use a bigint to store the ID of my user as I want it to match discord Ids (and they are LONG). When I look at my db, they are stored correctly with the exact number. However, once I query them, they are coming back to me with some approximations. I do not want that, I need the exact ID. How do I fix this ? Table:
    Copy code
    "id"                 "name"    "rank"    "grade"
    111204161931972608   "reli"    12         5001
    Request:
    Copy code
    js
    let {data} = await supabase
          .from("User")
          .select("*")
    Response:
    Copy code
    js
    { id: 111204161931972600, name: 'reli', grade: 5001, rank: 12 }
    See how my user id got rounded for the decimals?
    g
    • 2
    • 2
  • Help with the db setup
    k

    Kenbak

    11/08/2022, 12:00 PM
    Hello, I'm brand new to supabase and wanted to use it for a new app I want to build. I would like to know if it's do-able using supabase. My app has users that can sign in, log in, log out etc... These users, once they are signed in can generate images via AI prompt(API call). They can have many images. The images can be shared or stay private. Can I do this with supabase? And how should I proceed? Thx a lot
    s
    • 2
    • 1
  • 401 when accessing table in DB from browser library (SDK)
    c

    config_wizard

    11/08/2022, 1:18 PM
    I am not quite sure what I'm doing wrong, I have row locking security disabled, and I have grabbed the URL and the public anon key from here however I am getting 401 every time:
    Copy code
    curl --location --request GET 'https://unique-code.supabase.co/rest/v1/table_name' \
    --header 'apikey: eyJhbGciOiJIUzI1NiIs-apikey' \
    --header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIs-apikey'
    {"code":"42501","details":null,"hint":null,"message":"permission denied for table categories"}
    is there anything else that I could have missed?
    g
    • 2
    • 9
  • Get session data server side
    p

    peak

    11/08/2022, 1:57 PM
    From server side (an async function in reaction to a webhook) I would like to get a specific user's session (for the refresh token) so that I can make service API calls on-behalf of a user. How do I get the user session data server side?
    s
    g
    n
    • 4
    • 34
  • Realtime subscription callback not working as expected
    h

    Hermes

    11/08/2022, 2:59 PM
    the callback logs the id of the comment for which it runs, I had 2 comments and that happened when I deleted one
    g
    • 2
    • 5
  • Returning usage in stored function
    z

    ZaDeR47

    11/08/2022, 3:09 PM
    Creating a stored procedure to call via supabase client's rpc method. My sql:
    Copy code
    sql
    create function create_new_post("userId" uuid, "title" text, "content" text)
        returns boolean
        language plpgsql
        as $$
        begin
              with "insertedPost" as (
                insert into posts ("user_id", "path") values ($1, 'root')
                returning "id"
              )
              insert into post_contents
                ("post_id", "title", "content") values
                ((select "id" from "insertedPost"), $2, $3);
              insert into post_score
                ("post_id", "score") values
                ((select "id" from "insertedPost"), 0);
            commit;
            return true;
        end; $$
    When I call the rpc from the supabse client, I'm getting the error "Relation \"insertedPost\" does not exist". Can anyone see what I'm doing wrong here?
    g
    • 2
    • 12
  • unable to connect directly through db connections
    y

    Yuito

    11/08/2022, 4:29 PM
    I created my first project about 2 weeks ago, after building and testing my project with the final version of my discord bot, I deleted the test project I was using this whole time directly through db connections but after deleting the the test project and creating the new project I can't connect to the db directly through db connections with same discord bot code which was working fine with the test project but now with the new production project. why?
    • 1
    • 1
  • Adding one to many records when creating one record
    d

    drewbie

    11/08/2022, 5:50 PM
    Trying to figure out the best way to model this and wanted to see if anyone had any advice. I am aiming to create an
    orders
    table that has a
    buyer_id
    and a
    seller_id
    , both referencing/associated with the
    accounts
    table. That part so far is fine
    Copy code
    CREATE TABLE orders
    (
      id uuid default uuid_generate_v4() primary key,
      created_at timestamp default now() not null,
      updated_at timestamp default now() not null,
      state "order_state" default 'IN_PROGRESS' not null
    );
    
    ALTER TABLE "orders" ADD COLUMN "buyer_id" UUID NOT NULL;
    ALTER TABLE "orders" ADD CONSTRAINT "orders_buyer_id_fkey" FOREIGN KEY ("buyer_id") REFERENCES "accounts"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
    
    ALTER TABLE "orders" ADD COLUMN "seller_id" UUID NOT NULL;
    ALTER TABLE "orders" ADD CONSTRAINT "orders_seller_id_fkey" FOREIGN KEY ("seller_id") REFERENCES "accounts"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
    The next part is where I am finding it tricky. I want to be able to add many products to the order, via an
    order_products
    table which would look like this --
    Copy code
    CREATE TABLE order_products
    (
      id uuid default uuid_generate_v4() primary key,
      created_at timestamp default now() not null,
      updated_at timestamp default now() not null
    );
    
    ALTER TABLE "order_products" ADD COLUMN "order_id" UUID NOT NULL;
    ALTER TABLE "order_products" ADD CONSTRAINT "order_products_order_id_fkey" FOREIGN KEY ("order_id") REFERENCES "orders"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
    
    ALTER TABLE "order_products" ADD COLUMN "product_id" UUID NOT NULL;
    ALTER TABLE "order_products" ADD CONSTRAINT "order_products_product_id_fkey" FOREIGN KEY ("product_id") REFERENCES "products"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
    However, I want to make the order_products / products for the order record required, and eventually I will create constraints or policies around making sure that the product belongs to the seller/account within the order. How would I go about setting up the requirement of the order_products, or products for the order when creating the order record, specifically with the js client? I imagine it looking something like this ->
    client.from("orders").insert({buyer_id: buyer.id, seller_id: seller.id, order_products([{product_id: productOne.id}, {product_id: productTwo.id}])
    , but this obv doesn't work, but something Im after? Any help on this would be appreciated, and I'm also all ears for any suggestions on a better schema what I'm after. Thanks!
  • How to fetch data from Supabase to Email template
    s

    shantanubharadwaj

    11/08/2022, 6:31 PM
    I want to fetch the user first name from Supabase and use it inside custom email template when user login's using magic link. It would be great if anybody can help me with this. Thanks.
    g
    • 2
    • 16
  • Depth First Traversal with LTREE extension
    z

    ZaDeR47

    11/08/2022, 7:32 PM
    Looking to implement nested comments, with a function to call via rpc to return all comments via a depth first traversal. My posts table:
    Copy code
    sql
    create table posts (
        id uuid primary key default uuid_generate_v4() not null,
        user_id uuid references auth.users (id) not null,
        created_at timestamp with time zone default now() not null,
        path ltree not null
    );
    On inserts to this table, the
    path
    field is set to
    root
    for original posts. All comments then append
    '.<parent's uuid>'
    for their path values. My function then looks like:
    Copy code
    sql
    create function get_single_post_with_comments(post_id uuid)
    returns table (
        id uuid,
        -- depth int, <== not sure how to get... could determine from path in frontend
        path ltree,
    )
    language plpgsql
    as $$
    begin
        return query
        select posts.id, posts.path
        from posts
        where posts.path <@ post_id
        -- order by p.created_at desc <== need depth-first ordering here....
    end;$$
    Any ideas on how to get order properly?
  • Studio Function Support
    d

    Dallas

    11/09/2022, 7:18 PM
    So, I'm aware the studio doesn't currently support DB Functions as listed here: https://supabase.com/docs/guides/cli/local-development#limitations Has there been any official communications (or GH tickets to follow) related to when this will be implemented? I've been looking to utilize the local instance to manage migrations between multiple environments, however because I make use of DB functions, this is not possible, since there's no way to sync my local instance with my existing hosted instance. While not super pressing, I can just manage various sql scripts and make use of pgAdmin, I'd love to move to the more managed migrations that the tooling is capable of providing. So mostly just looking to get a pulse on this.
    g
    • 2
    • 7
  • Supabase NextJS Auth Helpers on Vercel Edge functions
    a

    Angelo

    11/10/2022, 12:54 PM
    Hi guys, I tried to use
    createServerSupabaseClient
    inside a Vercel Edge function, but it's not working. I think that
    {req, res}
    values are different inside Edge Runtime, does anyone know a "manual" way to get it authenticated with session cookie?
    n
    r
    • 3
    • 22
  • Return array of objects grouped by date
    b

    bingbong

    11/10/2022, 8:26 PM
    Want to group entries based on their date (see screenshot), and so far I'm solving this on client-side with a reduce function. Is it possible to achieve the same with maybe a view or something else directly from "server"-side/supabase? Would appreciate links to examples or which postgresql function I should look into!
    n
    a
    • 3
    • 5
  • What is the best way to manage password reset in Remix?
    j

    jkohlin

    11/10/2022, 8:28 PM
    I'm trying to figure out how to use the function resetPasswordForEmail() without putting my auth keys on the client browser. Is it possible? if so, how? Can I set the Confirmation URL
    {{ .ConfirmationURL }}
    to something different than my root URL? I'd like to change it for testing on localhost.
    t
    • 2
    • 1
  • Get supabase project name using SQL query
    e

    eyk

    11/10/2022, 8:55 PM
    Is there actually a way to get the name (or/and ID) of the project using a SQL query?
    g
    r
    • 3
    • 4
  • Too often outage nowadays. Can't sign in to my dashboard.
    a

    arcavid

    11/11/2022, 6:39 AM
    What is going on?
    f
    a
    +3
    • 6
    • 19
  • Angular Login with Google
    d

    DaLink

    11/11/2022, 9:51 AM
    I followed the instructions (https://supabase.com/docs/guides/auth/auth-google) and everything worked. Now when I click on Login I am redirected to Google where I can log in. After that I get back to my project URL (https://localhost:4200). In the URL it says access_token=xxxx. How can I now create a session for a user? From where can i get the Google username? Unfortunately I didn't find any instructions on the internet. Can someone help me?
    o
    a
    • 3
    • 15
  • How do do insert access to anyone
    t

    TARS

    11/11/2022, 10:22 AM
    Hello, I'm trying to add a policy for anyone to post to public.hosts. But I just don't seem to get it working. Can you please point me in the right direction. I'm attaching images/code please tell me if you need more info.
    Copy code
    CREATE POLICY "policy_name"
    ON public.hosts
    FOR INSERT USING (
      true
    );
    u
    n
    m
    • 4
    • 27
  • useUser and page flashing
    d

    dalxds

    11/11/2022, 10:39 AM
    Hello. I am using Supabase with Next.js I've created a navbar in my pagelayout component. Based on whether the user has signedin (there is session) I want to show an "account menu". The go-to solution for this seems to be the
    useUser()
    hook from the react auth helpers. So, I use the user to check if a user exists and then go with
    user ? <AccountMenu> : <SignInButton>
    The problem is that the page flashes instantly with the sign in button before showing the
    <AccountMenu>
    component. Also, when changes between pages that use the same page layout the state doesn't persist and the flashing happens on every page. How would be the way to go about it without getting the flashing? Also, if I wanted to bring in some user data as well (name, avatar) what would be the way to do it and not request it for every page change? Thanks
    n
    • 2
    • 2
1...636465...230Latest