https://supabase.com/ logo
Join Discord
Powered by
# help
  • m

    mikebarkmin

    10/15/2021, 3:16 PM
    You need a foreign key constraint on the user_uploaded_contents table. Then you can use this:
    Copy code
    js
    supabase.from("user_public").select("*, contents:user_uploaded_contents(*)")
    If you are getting a could not find a relationship, be sure to add a foreign key on the user_uploaded_contents table for the user_public table.
    z
    h
    • 3
    • 15
  • a

    AlanK

    10/16/2021, 2:12 AM
    I am very new to DaaS security and I have two basic questions in relation to access from a Javascript front-end. 1: Is it acceptable to execute all my SQL as the postgres user? 2: Is there increased security in creating a specific schema for my data tables?
  • m

    MyNameIsRickZero

    10/16/2021, 4:14 AM
    All all, is there a way to create (yes, it's alpha) function hooks on storage? I want to trigger an image post-processor in Lambda to generate a thumbnail when a file is added to a storage bucket.
  • e

    Eryou Hao

    10/16/2021, 4:52 AM
    Hi all, I have a project using Next.js + Nest.js I want to do the Supabase login in Next.js and then send the sb:token to Nest.js for other operations. But I get an
    Invalid authentication credentials
    in Nest.js, when performing select. The createClient I executed in Nest.js uses the session after the user has logged in. Is there something wrong with me?
  • e

    Eryou Hao

    10/16/2021, 5:18 AM
    when I run this, it works fine.
    Copy code
    const sbToken = req.cookies['sb:token']
    supabase.auth.setAuth(sbToken)
  • m

    mikebarkmin

    10/16/2021, 7:03 AM
    I think you should be able to use postgres triggers and the http extension or create a cron job https://supabase.io/blog/2021/03/05/postgres-as-a-cron-server
  • m

    mikebarkmin

    10/16/2021, 7:04 AM
    Here is how it is done https://github.com/supabase/supabase/blob/master/examples/nextjs-auth/pages/api/auth.js Do not forget to set the cookie on sign in
    Copy code
    ts
    export const signOut = async () => {
      await supabase.auth.signOut();
      await fetch("/api/account/auth", {
        method: "POST",
        headers: new Headers({ "Content-Type": "application/json" }),
        credentials: "same-origin",
        body: JSON.stringify({ event: "SIGNED_OUT" }),
      });
    };
    
    export const signIn = async (email: string, password: string) => {
      const { data, error, session } = await supabase.auth.signIn({
        email,
        password,
      });
      await fetch("/api/account/auth", {
        method: "POST",
        headers: new Headers({ "Content-Type": "application/json" }),
        credentials: "same-origin",
        body: JSON.stringify({ event: "SIGNED_IN", session }),
      });
    
      if (error) {
        console.error(error.message);
        throw error;
      }
    
      return data;
    };
  • c

    cataxcab

    10/16/2021, 11:17 AM
    Hi, quick question: The image is the simplified structure of my tables - 2 main tables, one relation table. What's the best way to handle an API for this? If I just have a Client and Supabase:
    Copy code
    - First API call to insert book and get ID
    - Second API call to insert genre and get ID
    - Third API call to insert book-genre relation
    This is what I can think of, but 3 API calls seems wrong. Is there a way where I can do insert into these 3 tables with a single API call from my client? Image
  • c

    cataxcab

    10/16/2021, 11:18 AM
    Or if I can use something like functions in Supabase, could someone share a quick sample? Thanks!
  • d

    Deleted User

    10/16/2021, 12:24 PM
    I don't have an example right now, but, implementing a Postgres function and using an rpc call I think it is possible
  • y

    YogurtDrinker

    10/16/2021, 12:45 PM
    Hi there i have no ideas why my query doesn't work
    Copy code
    await supabaseClient.from('Udemy')
      .select()
      .contains('title', ['html']);
  • y

    YogurtDrinker

    10/16/2021, 12:45 PM
    Returns me something like
    Copy code
    GEThttps://wtccvsqohflpzaqdjzdn.supabase.co/rest/v1/Udemy?select=*&title=cs.{html}
    [HTTP/2 404 Not Found 16ms]
    
    Object { error: {…}, data: null, count: null, status: 404, statusText: "Not Found", body: null }
  • y

    YogurtDrinker

    10/16/2021, 12:49 PM
    Am i supposed to use
    textSearch()
  • c

    cataxcab

    10/16/2021, 12:57 PM
    I thought so, but - isn't this a common use-case? Which is why I thought I'd find some templates, hopefully
  • y

    YogurtDrinker

    10/16/2021, 1:19 PM
    Okay i settled with
    textSearch
    which works but not exactly. If i search for
    scrum
    it works
  • y

    YogurtDrinker

    10/16/2021, 1:20 PM
    However if i search for
    scrum master
    it doesn't return any result
  • y

    YogurtDrinker

    10/16/2021, 1:21 PM
    Okay i'm dumb i need to filter using javascript https://supabase.io/docs/guides/database/full-text-search
  • m

    mikebarkmin

    10/16/2021, 1:58 PM
    Maybe this example from my code base helps:
    Copy code
    sql
    CREATE OR REPLACE FUNCTION public.upsert_flow(flow json)
        RETURNS uuid
        LANGUAGE 'plpgsql'
    AS $BODY$
    DECLARE
        node json;
    BEGIN
      INSERT INTO flows (id, user_id, name, zoom, position, language, description, visibility, draft) VALUES(
        ($1->>'id')::uuid,
        auth.uid(),
        ($1->>'name'),
        ($1->>'zoom')::bigint,
        ($1->>'position')::jsonb,
        ($1->>'language')::allowed_language,
        ($1->>'description'),
        ($1->>'visibility')::visibility,
        ($1->>'draft')::boolean
      )
      ON CONFLICT (id) DO 
         UPDATE SET 
             name=COALESCE($1->>'name', flows.name),
             zoom=COALESCE(($1->>'zoom')::bigint, flows.zoom),
             position=COALESCE(($1->>'position')::jsonb, flows.position),
             language=COALESCE(($1->>'language')::allowed_language, flows.language),
                    description=COALESCE(($1->>'description'), flows.description),
             visibility=COALESCE(($1->>'visibility')::visibility, flows.visibility),
             draft=COALESCE(($1->>'draft')::boolean, flows.draft);
    
      DELETE FROM flow_nodes WHERE flow_id = ($1->>'id')::uuid;
    
      FOR node IN SELECT * FROM json_array_elements($1->'nodes') LOOP
        INSERT INTO flow_nodes (id, position, data, type, flow_id)
        VALUES (
          (node->>'id')::uuid,
          (node->>'position')::jsonb,
          (node->>'data')::jsonb,
          (node->>'type')::flow_node_types,
          ($1->>'id')::uuid
        )
        ON CONFLICT (id) DO 
               UPDATE SET
                   position=(node->>'position')::jsonb,
                   data=(node->>'data')::jsonb,
                   type=(node->>'type')::flow_node_types;
      END LOOP;
      RETURN $1->>'id';
    END;
    $BODY$;
  • c

    cataxcab

    10/16/2021, 2:12 PM
    Really helpful, thanks! Could you add the API call that calls this too please? And feel free to post this in my StackOverflow question too, I'll accept your answer. https://stackoverflow.com/questions/69595895/how-to-insert-in-multiple-tables-with-a-single-api-call-in-supabase
  • m

    mikebarkmin

    10/16/2021, 2:13 PM
    Sure:
    Copy code
    ts
    export const upsertFlow = async (
      id: string,
      flow: Flow &
        Pick<
          definitions["flows"],
          "draft" | "visibility" | "language" | "description"
        >,
      userId?: string
    ) => {
      const [data] = await supabase
        .rpc<string>("upsert_flow", { flow: decamelize({ id, ...flow, userId }) })
        .single()
        .then(handleSupabaseError);
      return data;
    };
    I like to work in JavaScript with camelCase and in supabase with snake_case, therefore the decmelize function.
  • c

    cataxcab

    10/16/2021, 2:30 PM
    Makes sense, thanks! 😄
  • l

    Lio

    10/16/2021, 9:30 PM
    Am I able to point a custom domain to supabase for my storage buckets?
  • m

    mikebarkmin

    10/17/2021, 7:53 AM
    I think this is not currently not present in Supabase, if you are not self-hosting, but you could create an api endpoint, which proxies the request to the supabase server. Another possible option could be to use Cloudflare for this. For my last project I proxied a Backblaze B2 bucket with the Cloudflare CDN following this guide: https://help.backblaze.com/hc/en-us/articles/217666928-Using-Backblaze-B2-with-the-Cloudflare-CDN. I think this could be applicable to Supabase as well.
  • l

    Lio

    10/17/2021, 8:31 AM
    rn I'm using Wasabi for my S3 buckets, sadly i can't define different S3 configs in the supabase package
  • e

    erik_flywheel

    10/17/2021, 11:16 AM
    Hey everyone, I have a reservation app, let's just call it airbnb since the functionality is similar. I need to show available listings (listings without reservations during the time period the user selects: start date - end date). I have a sql script that'll return the available listings, but how can I call that via the api? Should I use a stored procedure? A view doesn't work because I'd have to create one for every query
    s
    • 2
    • 23
  • s

    silentworks

    10/17/2021, 11:54 AM
    How to call SQL via the client library
  • u

    ~emma~

    10/18/2021, 1:29 AM
    I'm very new to supabase... I'm trying to figure out a good workflow when using "magic link" auth. Here's my pain point: when I'm developing locally, I want the url in the email template to redirect me to
    localhost:3000
    . But, of course, I don't want to use
    localhost
    on my deployed app. Currently I am just switching between the two urls (localhost of prod) in Auth > Settings > Site URL. This is kinda painful, and obviously won't work once anyone other than me uses this thing. So how are people getting around this? Thanks in advance!
  • k

    khacvy

    10/18/2021, 2:49 AM
    I think the easiest way is create two supabase project, one for development and one for production.
  • x

    Xzeta

    10/18/2021, 2:50 AM
    so created the profile table from the template. would u create a user profile after user confirms account or after user registers
    s
    • 2
    • 6
  • u

    ~emma~

    10/18/2021, 3:14 AM
    Ah, okay. Thx! Was hoping there was an easy way to set local env variables to "log in" a user without going through the auth flow, or something like that.
1...111112113...316Latest