https://supabase.com/ logo
Join Discord
Powered by
# help-and-questions
  • No results from JS client calls to storage in local env edge-function
    j

    jarnold

    03/15/2023, 12:49 PM
    Hello, I'm working locally and am trying to get calls to the storage API in an edge-function to work. I've tried a couple of different calls like getBucket, listBuckets, etc.. and they all behave the same way where they return a 200 and no results. For example, I've tried to get a buckets details by doing:
    const { data, error } = await supabaseClient.storage.getBucket("test");
    This gives a status code 200 but no results. The bucket is there, has images in it and is public. I'm new to this so maybe it's policy related or config. related. Hoping that it's not a bug in the local env.
    g
    • 2
    • 3
  • Getting reviews on my PR to supabase/postgres-meta
    j

    joeally

    03/15/2023, 12:53 PM
    I created a PR to the supabase/postgres-meta to fix a bug where
    unknown
    is generated for table types by the types generator (issue: https://github.com/supabase/postgres-meta/issues/534). My PR is at https://github.com/supabase/postgres-meta/pull/533 and it's a pretty small change so it shouldn't be too hard to review. I appreciate that you're all busy and this might not be the highest priority but I just thought I'd ask anyway. Thanks
    g
    • 2
    • 4
  • CORS all of a sudden
    d

    dmayo2

    03/15/2023, 1:38 PM
    Hello. So, I've been developing my SoildJS app on localhost:3001 for the past couple of days. Things have been going well. I query the db using
    "asupabase/supabase-is": "^2.10.0"
    , with GET and POST to update a table with RLS. I have my
    sb-db-auth-token
    in my localStorage. Then suddenly I start getting CORS error of
    Response to preflight request doesn't pass access control check: Redirect is not allowed for a preflight request.
    Reading lots, but just can't figure out why it started, let alone how to solve it now. I plan to host my app on Netlify. I guess I could use a CORS browser extension during development, but that just sounds counter intuitive to me. If I have to setup a server(less) function on Netlify, A). I have no clue how to do that and haven't found a good tutorial. Am I correct in my thinking that the supabase.co server should be handling requests correctly? Did I change something in my code? Did I change something in my supabase dashboard? Since they didn't answer thought I should come here. Comments/Thoughts/Suggestions would all be greatly appreciated.
    g
    • 2
    • 16
  • Will joins in a view obide by RLS?
    u

    49Ryann

    03/15/2023, 1:54 PM
    I have this view:
    Copy code
    create view all_conversations_view WITH (security_invoker) as
      SELECT 
        c.id, 
        c.conversation_sid, 
        c.last_message, 
        CASE                              
          WHEN ct.mobile IS NOT NULL THEN json_build_object('id', ct.id, 'full_name', ct.full_name, 'name', ct.name, 'surname', ct.surname, 'profile_image', ct.profile_image, 'phone', ct.phone, 'mobile', ct.mobile)
          ELSE NULL
        END AS contact, 
        CASE 
          WHEN u.id IS NOT NULL THEN json_build_object('id', u.id, 'full_name', u.full_name, 'name', u.name, 'surname', u.surname, 'profile_image', u.profile_image, 'phone', u.phone, 'mobile', u.mobile)
          ELSE NULL
        END AS user,
        CASE 
          WHEN o.id IS NOT NULL THEN json_build_object('id', o.id, 'twilio_phone_number', o.twilio_phone_number)
          ELSE NULL
        END AS organisation
      FROM conversations c
      INNER JOIN organisations o ON c.organisation_id = o.id
      INNER JOIN users u ON c.user_id = u.id
      LEFT JOIN contacts ct ON c.contact_mobile = ct.mobile AND c.organisation_id = ct.organisation_id;
    If you notice on the left join on the very bottom I'm finding a mobile number match & ensuring organisation_id is equal, is this necessary to do the organisation_id check if I already have RLS enabled on that contacts table? It's possible two different organisations have a contact with the same mobile, I also have an index to ensure organisation_id & mobile is unique.
    g
    • 2
    • 4
  • Best practices for database boilerplate setup script?
    l

    louis030195

    03/15/2023, 2:00 PM
    Hi, I'm trying to automate the setup of a Supabase database in Python (enable some extensions, create tables, etc.) This is my current code that only contains the sql queries that I had to run through clicks in app.supabase.com https://github.com/different-ai/embedbase/blob/main/scripts/supabase.py Any idea how I could do this? Maybe in Python or some CLI thing?
    • 1
    • 1
  • Problem updating table
    c

    chrtravels

    03/15/2023, 2:17 PM
    Hey all, Any thoughts on getting a table row update to work? Trying to update the profile of the logged in user. In this case specifically full_name. I tried the "upsert" method in the auth tutorial but act didn’t work. Violates row level security. For some reason it’s trying to create a new row, rather than updating the existing but I was just using the code from the tutorial:

    Copy code
    const updates = {
            id: user.id,
            username,
            website,
            avatar_url,
            updated_at: new Date().toISOString(),
          }
    
          let { error } = await supabase.from('profiles').upsert(updates)
    

 So I tried this method with update, where "id" column matches id:

    Copy code
    let { error } = await supabase
          .from('profiles')
          .update({username, full_name: fullName, website, avatar_url, bio, banner_img_url})
          .eq("id", id)
    
 I can tell it does try to post something. The refresh spins on Supabase and I get no errors in the console but the name doesn’t update, as if nothing was submitted for full_name. However I console.log full_name right before submission and it does have the correct value.
 Now I did create “supabase” from “@supabase/supabase-js” instead of auth-helpers but don’t think that should be a problem.
    g
    • 2
    • 2
  • Question regarding supabase
    e

    ewic

    03/15/2023, 2:20 PM
    I'm planning to build web app and mobile app. It is possible to use one postgres sql database/one endpoint for both flutter and nextjs with prisma Like i will use
    auth
    of supabase for flutter but on nextjs i will use
    next-auth
    . to lessen creating a backend server for both platform. Sorry i'm still new with supabase. Thank you for response 🙏
  • Query with optional equality check?
    c

    chrtravels

    03/15/2023, 3:22 PM
    Howdy! Wondering if it possible to have an optional equality check in a supabase query. I believe you can do this with "Where" in postgreSQL but it doesn't look like you can use where with Supabase. Something like the following where .eq is optional. The idea being to make a reusable function so that I don't need multiple functions for all different types of get requests.
    Copy code
    export async function getPosts(val, equals, equalTo) {
      let { data: posts, error } = await supabase
      .from('posts')
      .select(val)
      .eq(equals, equalTo)
    
      return posts;
    }
    I did try to use "or" for filtering but not exactly sure how to make that work. For example in the case where the equality check is to see if the id matches the current user. https://supabase.com/docs/reference/javascript/or Thanks!
    g
    • 2
    • 6
  • supabase storage not starting
    d

    Derock

    03/15/2023, 4:42 PM
    Copy code
    2023-03-15T15:37:56: PM2 log: Launching in no daemon mode
    2023-03-15T15:37:56: PM2 log: App [server:0] starting in -fork mode-
    2023-03-15T15:37:56: PM2 log: App [server:0] online
    running migrations
    Error: getaddrinfo ENOTFOUND supatest_db
        at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:107:26) {
      errno: -3008,
      code: 'ENOTFOUND',
      syscall: 'getaddrinfo',
      hostname: 'supatest_db'
    }
    running nslookup in the container works fine
    e
    • 2
    • 1
  • Failed to update pg.tables with the given id must be owner of table supabase
    k

    kvnfo

    03/15/2023, 5:03 PM
    Getting this error when trying to update the users table, I used the nextjs supabase stripe starter. Looked around and unable to solve this, does anyone have any suggestions? Thank you
    g
    m
    h
    • 4
    • 41
  • Send additional data on sign up with GitHub
    a

    andrijan

    03/15/2023, 5:11 PM
    Hello, I have a multi-step form from which I collect data from before the user signs up and I am curious how I would send the data to the database when I use GitHub as an auth provider? I am aware that when a user signs up with a username and password, we can pass additional metadata, but I can't figure it out when using GitHub as a sign up method. Thank you.
    g
    • 2
    • 5
  • Custom Role Based Auth
    a

    acho01

    03/15/2023, 5:24 PM
    Hi, I'm currently trying to implement current role based Auth using supabase. All I need is 1 admin user and this admin user should create ordinary users. SignUp should only be available for admin user. It's like ordinary enterprise thing. Admin registers other users. Is something like this possible using built in authentication? Also is it possible to set custom roles to users?
    g
    • 2
    • 3
  • Make a CSV from the tables.
    d

    dev Joakim Pedersen

    03/15/2023, 6:16 PM
    I want to copy products to a csv that I will store in a bucket
    Copy code
    COPY (
        SELECT * 
        FROM product_table_prod_v2 
        WHERE store_id = 193
    ) TO 'storage/buckets/csv' WITH CSV HEADER;
    but neither 'storage/buckets/csv' works it gives me invalid SQL query. or storage.buckets.csv either, then I get an error at or near storage. since it expects a string. Is this possible to do?
    g
    • 2
    • 6
  • Storage - retrieving public URL for file that doesn't exist?
    c

    chrtravels

    03/15/2023, 6:45 PM
    I am retrieving a public URL for an image in storage but it should only return the url if that image actually exists right!? Apparently not so much.
    Copy code
    export async function getImage(bucket, imageName) {
        const { data } = await supabase
        .storage
        .from(bucket)
        .getPublicUrl(imageName)
    
        return data;
      }
    Then retrieving with:
    Copy code
    const banner = await getImage('banner-images', `${session.user.id}.jpg`).then(data => data.publicUrl);
    That returns this format:

    https://myurl/storage/v1/object/public/banner-images/image-that-doesnt-exist.jpg▾

    So even though there is no such file, it's still returning a URL? Beginning to think I made a mistake using the Supabase API and should stick to the regular REST API.
    g
    • 2
    • 7
  • Row Level Security target roles
    e

    edgaras

    03/15/2023, 6:52 PM
    I am a little confused about RLS again. What's the difference between having
    (auth.uid() = profile_id)
    only VS. also targeting
    authenticated
    role via dropdown?
    g
    • 2
    • 23
  • Remove storage path triggered by DELETE in public table?
    s

    sudoramen

    03/15/2023, 7:48 PM
    I'm trying to write a trigger function to clean up a folder in a bucket that corresponds to a public table. When a user deletes a row, it should delete the corresponding path in storage. I'm not very savvy with how postgres db interacts with S3 buckets so I'm not sure if this is possible but I figured I'd ask if anyone has experience with this? Can you delete things in S3 from the database?
    g
    • 2
    • 1
  • RPC call to function does not modify database records and returns no errors
    b

    Bizzare

    03/15/2023, 8:01 PM
    I have a function as shown in the attached picture. If I run it from the web sql editor inside my project, everything works and I get the deleted row returned properly. When I use the RPC call from my front-end, nothing changes in the database, I get a record with all fields set to 'null' and no errors. Is there something I'm missing here?
    g
    • 2
    • 6
  • How to update non-authenticated user password (password recovery)?
    k

    kuba

    03/15/2023, 8:07 PM
    Previously I was using code below in which I was using jwt from recovery password email link:
    Copy code
    dart
    await ref.read(authRepositoryProvider).auth.**api**.updateUser(
                  jwt,
                  UserAttributes(password: password),
                );
    But after supabase package update I can't use auth.api
    Copy code
    dart
    await ref.read(authRepositoryProvider).auth.updateUser(
                  // No jwt field in updateUser().
                  UserAttributes(password: password),
                );
    g
    • 2
    • 4
  • Restored Project - Authenticator error
    m

    mansedan

    03/15/2023, 8:55 PM
    Hey team, We recently restarted/restored a project on Supabase and are getting an error we havn't seen on the project before. relation "public.profiles" does not exist This makes sense as we do not have a profiles table. But as far as we can tell, nothing is referencing a profiles table.
    r
    g
    • 3
    • 7
  • Python API for updating user
    n

    nateland

    03/15/2023, 9:11 PM
    I can only see
    Fetch
    and
    Insert
    , but not
    Update
    . Thoughts?
    g
    • 2
    • 7
  • Sign in with Apple error
    r

    robertn702

    03/15/2023, 9:16 PM
    I'm trying to set up Sign in with Apple on my React Native Expo app but am running into this error:
    oidc: expected audience "{ServiceID}" got ["{AppBundleID}"]
    I am using `expo-apple-authentication`'s
    AppleAuthentication.signInAsync()
    to get the idToken, which seems to work fine. Then passing the token to
    supabase.auth.signInWithTokenId({ provider: "apple", token: idToken })
    throws the error. I've followed these instructions[0], but I'm wondering if there is a difference in setup between using Sign in with Apple on the web vs native. Supabase's docs don't cover usage with native apps it seems. 😕 [0]: https://supabase.com/docs/guides/auth/social-login/auth-apple
  • Update user e-mail from GUI
    n

    nateland

    03/15/2023, 9:17 PM
    Is there a way to do this? I can't seem to find it.
    s
    • 2
    • 1
  • multiple select policies for storage items
    g

    goldyman

    03/15/2023, 9:29 PM
    Can I have multiple select policies set on a bucket. For example one for the owner of the asset and one for the other users. Can they act as OR. Or Only one of them is working.
    g
    • 2
    • 2
  • In RLS policies, should I generally apply the same condition in using to with check ?
    z

    zszszsz

    03/15/2023, 11:21 PM
    Answer: Is it is for update or for all, no: https://www.postgresql.org/docs/current/sql-createpolicy.html#:~:text=ALL%20policies%20will%20be%20applied%20to%20both%20the%20selection%20side%20of%20a%20query%20and%20the%20modification%20side%2C%20using%20the%20USING%20expression%20for%20both%20cases%20if%20only%20a%20USING%20expression%20has%20been%20defined. > ALL policies will be applied to both the selection side of a query and the modification side, using the USING expression for both cases if only a USING expression has been defined. https://www.postgresql.org/docs/current/sql-createpolicy.html#:~:text=If%20only%20a%20USING%20clause%20is%20specified%2C%20then%20that%20clause%20will%20be%20used%20for%20both%20USING%20and%20WITH%20CHECK%20cases. > Any rows whose updated values do not pass the WITH CHECK expression will cause an error, and the entire command will be aborted. If only a USING clause is specified, then that clause will be used for both USING and WITH CHECK cases. And this is nothing about for select and for insert, since for select has no
    with check
    and for insert has no
    using
    . Eg. in [this part of the doc](https://supabase.com/docs/guides/auth/row-level-security#restrict-updates) it writes
    Copy code
    sql
    create policy "Users can update their own profiles."
      on profiles for update using (
        auth.uid() = id
      )
    Would it be better to
    Copy code
    sql
    create policy "Users can update their own profiles."
      on profiles for update using (
        auth.uid() = id
      ) with check ( 
        auth.uid() = id
      )
    Besides if it is
    for insert
    or
    for all
    but inserting to the table, is the
    using
    just skipped and only the
    with check
    condition is applied to the inserted row ? So generally if it is a
    for all
    you may just repeat
    using
    condition in
    with check
    again ?
    g
    • 2
    • 12
  • Insert into (public) "users" based on (auth) users and sign up page.
    u

    𝙲𝚑𝚞𝚞𝚔

    03/15/2023, 11:50 PM
    Along with the users table in auth, I have a users table in public. On my site, I have the following register form [form.png]. How can I have it so that when a user is created, the rest of the information is passed along with the email and pasword? The picture "Notes_230315_194712.jpg" gives a better visualization. Also, hello. Im new here. current code
    Copy code
    async function _signUp() {
        const { user, session, error } = await supaClient.auth.signUp({
            email: document.getElementById('email').value,
            password: document.getElementById('cPassword').value,
        })
    }
    function signUp() {
        function fail() {
            console.log('invalid password or username')
        }
        if (document.getElementById('cPassword').value < 8) {
            fail();
            return;
        }
        if (document.getElementById('email').value == '') {
            fail();
            return;
        }
        _signUp().then(
            function(value) {
                document.getElementById('form').style.visibility = "hidden";
                document.getElementById('succ').style.visibility = "visible";
            },
            function(error) {console.log('?')}
        )
    }
    async function _signIn() {
        let { data, error } = await supaClient.auth.signInWithPassword({
            email: document.getElementById('userID').value,
            password: document.getElementById('password').value
        })
    }
    function signIn() {
        function fail() {
            console.log('invalid password or username')
        }
        _signIn().then(
            function(value) {window.location.href = "app/dashboard.html";},
            function(error) {console.log('?'); fail();}
        )
    }
    async function _signOff() {
        let { error } = await supaClient.auth.signOut()
    }
    function signOff() {
        _signOff().then(
            function(value) {window.location.href = "/";},
            function(error) {console.log('?')}
        )
    }
    function token() {
        let urll = window.location.href;
        if (urll.includes("#access_token")) {
            window.location.href = "app/dashboard.html";
        }
    }
    s
    d
    • 3
    • 17
  • Session Null after login, but page.data.session is filled - sveltekit auth helpers
    b

    brubadger

    03/16/2023, 1:18 AM
    I'm trying to set up login using the svelte kit auth helpers. I'm able to successfully login and $page.data.session.user is filled with the user accurately. My RLS policies work correctly when doing client side retrieval in the .svelte files, but I can't get a hold of the user session in any of the .ts files. For example, I have the following root layout.ts and the session is always null: import type { LayoutLoad } from './$types'; import { getSupabase } from '@supabase/auth-helpers-sveltekit'; export const load: LayoutLoad = async (event) => { const { session } = await getSupabase(event); console.error("session: " + JSON.stringify(session)); return { session }; }; The session is also null in hooks.server.ts: export const handle: Handle = async ({ event, resolve }) => { event.locals.supabase = createClient(PUBLIC_SUPABASE_URL, PUBLIC_SUPABASE_ANON_KEY); event.locals.getSession = async () => { const { data: { session } } = await event.locals.supabase.auth.getSession(); console.error("hook session: " + JSON.stringify(session)); return session; }; return resolve(event, { filterSerializedResponseHeaders(name) { return name === 'content-range'; } }); }; and in layout.sever.ts: export const load: LayoutServerLoad = async ({ locals: { getSession } }) => { const session = getSession(); console.error("server session: " + JSON.stringify(session)); return { session: session }; }; I've been pulling my hair for a while so any help would be greatly appreciated.
    s
    • 2
    • 12
  • trouble using data type
    k

    kingpeppe

    03/16/2023, 2:39 AM
    I have re-read the documentation and the cods looks sound.
    Copy code
    ts
    import { createClient } from 'https://esm.sh/@supabase/supabase-js@2'
    import type { Database } from './types/supabase'
    
    // // SETTINGS
    const SUPABASE_URL = Deno.env.get('SUPABASE_URL')
    const SUPABASE_KEY = Deno.env.get('SUPABASE_KEY')
    
    // CLIENT
    export const supabase = createClient<Database>(SUPABASE_URL, SUPABASE_KEY)
    Copy code
    ts
    export const getStats = async () => {
       const { data: swap-stats, error } = await supabase.from('swap-stats').select('*')
    
      if (data) return data
      if (error) return error
    }
    however, I keep getting errors. What am I doing wrong?
    g
    • 2
    • 5
  • Just lost all connection to Database
    b

    BrianVueReference

    03/16/2023, 2:47 AM
    All of a sudden all my SQL queries no longer work and I cannot login the database on PGadmin with my SSL/PW. I looked at the Supabase status and it says everything is up. Is there something going on or is there a reason to lose all access? I haven't received an email or anything.
    g
    • 2
    • 28
  • trouble reading rows
    k

    kingpeppe

    03/16/2023, 2:47 AM
    I've reread the documentation to refresh my memory and the code looks sound, but I keep getting an empty array.
    supabase.ts
    Copy code
    ts
    import { createClient } from 'https://esm.sh/@supabase/supabase-js@2'
    import type { Database } from './types/supabase'
    
    // // SETTINGS
    const SUPABASE_URL = Deno.env.get('SUPABASE_URL')
    const SUPABASE_KEY = Deno.env.get('SUPABASE_KEY')
    
    // CLIENT
    export const supabase = createClient<Database>(SUPABASE_URL, SUPABASE_KEY)
    
    // HELPERS
    export const getStats = async () => {
      const { data, error } = await supabase.from('swap-stats').select('*')
    
      if (data) return data
      if (error) return error
    }
    main.ts
    Copy code
    ts
    import { getStats } from './supabase.ts'
    
    const stats = await getStats()
    console.log(stats)
    What am I doing wrong?
    s
    • 2
    • 1
  • [solved] Why is this SQL statement failing?
    d

    dmayo2

    03/16/2023, 2:52 AM
    INSERT INTO table (col1,col2,col3) VALUES ("val1","val2","val3")
    g
    • 2
    • 1
1...168169170...230Latest