https://supabase.com/ logo
Join Discord
Powered by
# help-and-questions
  • Array Contains Any?
    a

    A-PRYME

    01/26/2023, 12:05 AM
    Coming from firestore, what is the equivalent of an
    arrayContainsAny
    query? Also, is it possible to match a column against multiple values? i.e I have a list of ages 42, 46 and 48. I want to fetch users who's ages match any one of the three, how can I achieve this?
    g
    • 2
    • 4
  • Discord Embed Supabase Webhook
    j

    jakeAnon

    01/26/2023, 12:18 AM
    Hello I am looking to send a discord webhook embed with supabase webhook. Docs mention that the json payload is auto generated but is there anyway for me to format my embed object?
    g
    • 2
    • 1
  • signOut() not signing a user out?
    u

    1voy

    01/26/2023, 12:22 AM
    I'm using Twitter as my OAuth provider and I have a button using the signOut() function to log a user out. It does not work when I click it, a user still exists. I also have another problem, it seems that my app is making double requests - when the site is refreshed I have 2 console logs about the user My code:
    Copy code
    const logout = async () => {
        await supabase.auth.signOut();
        router.push('/');
      };
    
      return (
        <div className='flex-col flex-wrap items-center justify-center w-full max-w-3xl px-2 mx-auto my-16 text-center'>
          {lessons &&
            lessons.map((lesson) => (
              <Link
                key={lesson.id}
                href={lesson.id.toString()}
                className='flex h-40 p-8 mb-4 text-xl rounded shadow'
              >
                {lesson.title}
              </Link>
            ))}
          {user ? (
            <div>
              <h1>User is logged in with: {user.email}</h1>
    
              <Image
                alt='avatar'
                src={`${user.user_metadata.avatar_url}`}
                width={30}
                height={30}
              />
    
              <h2>Allow access to post on your behalf:</h2>
              <button
                className='p-2 font-black tracking-tighter text-white bg-black rounded-xl'
                onClick={() => logout()}
              >
                Signout
              </button>
            </div>
          ) : (
      
          )}
        </div>
      );
    }
    
    export const getServerSideProps = async (ctx: GetServerSidePropsContext) => {
      // Create authenticated Supabase Client
      const supabase = createServerSupabaseClient(ctx);
      // Check if we have a session
      const {
        data: { session },
      } = await supabase.auth.getSession();
    
      const { data: lessons }: PostgrestResponse<any> = await supabase
        .from('lesson')
        .select('*');
    
      if (!session)
        return {
          props: {
            user: false,
          },
        };
    
      return {
        props: {
          initialSession: session,
          user: session.user,
          lessons,
        },
      };
    };
    g
    v
    l
    • 4
    • 27
  • Loading state in Supabase Auth?
    f

    fast

    01/26/2023, 12:36 AM
    Hey there, I was wondering if there is a loading state which i can use to wait until the user is loaded. For example on my admin page I am checking if the user is logged in by checking the user object coming from the useUser Hook (I am using React + NextJS). The problem is that there is some sort of delay until the user etc. is loaded. Code:
    Copy code
    const router = useRouter();
    const supabaseUser = useUser();
    
    React.useEffect(() => {
      if(supabaseUser) {
        //Allow the user enter the admin dashboard
      } else {
        //Redirect user to login page
        router.push("/login");
      }
    }, [supabaseUser]);
    ^ The problem with that is that the user object need some amount of time to load but the useEffect Hook is called before the user is loaded so the user gets redirected. I am coming from firebase where I've used such hooks for such cases.
    g
    • 2
    • 1
  • How do I create a security policy based on a users column for another table?
    v

    Vik

    01/26/2023, 12:41 AM
    I'm currently designing the
    followers
    table for my project. My goal is to allow reading of a users followers if their account is not set to private. profiles table: id: uuid ... private: boolean followers table: id: int8 user_id: FK profiles ID followee_id: FK profiles ID So anytime a user follows someone a record is created in the followers table. The
    user_id
    column is the user being followed and the
    followee_id
    is the person that followed them. I want to setup a policy so if the users account is private you will only be able to see their list if you are already following them, aka a record exists. If their account is private and you don't already follow them, nothing should be returned. I've never created a policy based on a FK's table column, so this will be a learning experience for me.
    g
    • 2
    • 9
  • How to update JSON using JS client?
    p

    pickwickian

    01/26/2023, 12:43 AM
    I have a column that is JSON. I just need to use the
    update
    method to insert the JSON into the column. The example given for this in the documentation is confusing. It looks like if you want to treat your whole row like JSON. But only one of my columns is JSONB. I have it as a JS Object. I'm not sure what I am doing wrong and there's no error spitting out. I tried to update it like their docs where I named the column and used template literal to pass the value in. That didn't work (screenshot attached) and I tried a more conventional route. I feel like if it's not updating, it should be displaying something for the error.
    g
    • 2
    • 24
  • Supabase Auth UI component - redirectTo prop not working (?)
    h

    herropaul

    01/26/2023, 12:43 AM
    I am trying to use the Supabase
    Auth
    component to redirect users to a specific path after they log in, but it's not working. I've provided the path in the URL configuration tab in my Supabase dashboard and defined it in my NextJS
    pages
    directory as well (
    pages/users/index.tsx
    ), but it's still not redirecting. Has anyone else had this issue or have any suggestions? Here are some github issues I found as well but haven't been working for me. https://github.com/supabase/supabase/discussions/6088 https://github.com/supabase/auth-elements/issues/12
    t
    l
    • 3
    • 7
  • Large files fail to upload
    c

    Cool Bean

    01/26/2023, 2:13 AM
    Building a React app where users upload video files. Short videos (1-10mins) upload quickly without issue. Longer videos (> 30 mins) with a file size of >0.5 gig fail to upload. Large videos also fail to upload manually on the supabase website. Anyone else running into this / have a fix?
    g
    • 2
    • 3
  • How do I delete a user from all tables cleanly using RPCs?
    i

    InASunshineState

    01/26/2023, 2:24 AM
    I just saw that there's a function in the docs to delete them but it appears to be a stand-in for killing them from the auth table, but it's everything that happens after I don't get. I saw in GitHub there's this question that would work from the standpoint of a single delete: https://github.com/supabase/supabase/discussions/11207 And a many like this dealing with foreign key constraints:https://github.com/supabase/supabase/discussions/6524 but my concern with those is two-fold. One, that others ops would be impeded that are currently working on those rows on other tables (insert, update, etc.) and also that I can find a half dozen threads saying people said they tried setting that sort of thing up and it still didn't work. And this one https://github.com/supabase/supabase/discussions/6979 which people actually got humorous about asking for the functionality. I tried drafting my own only to find out that CTEs are only able to do one operation afterwards (if I read the docs right, but it also seems to be true in practice) so I thought I'd be clever and make its one operation another function on for deletes in Google.
    g
    • 2
    • 6
  • How do I retrieve from foreign table that contains the joining key?
    e

    elliott

    01/26/2023, 2:54 AM
    Say I have a table "profiles", and a table "images". "profiles" has no reference to "images", but "images" has a reference to "profiles", "images.profile_id". I know how to go from "images" -> "profiles" supabase .from("images") .select("\*, profile:profile_id(\*)") Straightforward right. But how do I go the other way? supabase .from("profiles") .select("\*, images(\*)") I can't figure out any configuration to get this to work where I join the tables from the other table's foreign key. Any help would be appreciated!
    g
    • 2
    • 8
  • Allowed Projects.
    k

    Kamael愛

    01/26/2023, 7:00 AM
    Hi, I know that we are only allowed to create 2 projects under free tier (not sure if this is still the case). I currently have 2 projects, 1 is free tier and I have decided to make 1 pro tier. Does this mean I get to create another free tier project?
    n
    • 2
    • 1
  • How to run a test version of Supabase locally?
    c

    Cody

    01/26/2023, 7:04 AM
    I'm wanting to use Playwright to run some e2e tests. I don't want it connecting to my development database because I want to wipe/re-seed the database after each test. I've searched around and I can't find any examples of doing this.
    g
    n
    • 3
    • 9
  • Session not saving to local storage
    u

    ${fence}

    01/26/2023, 7:35 AM
    Hi guys, as the title states. I've followed the Next.js Supabase tutorial and whenever I login via email/pass or discord provider the session won't save to local storage therefore session is returning null. Any help would be appreciated. I followed the guide 1 for 1 as far as I can tell..
    k
    g
    • 3
    • 11
  • Provider token becomes null
    l

    Lukas

    01/26/2023, 8:00 AM
    After logging in, when calling the hook
    useSession()
    , provider_token is filled with a provider token. After a bit, it becomes null. I was wondering what the best way to proceed is. Should I just store the provider token in localstorage? If I do, how long will that take to get invalidated (as it still seems to work if I copy and paste it out).
    j
    • 2
    • 3
  • What is the easiest way to delete all data from all public tables and drop them?
    l

    lake_mattiato

    01/26/2023, 9:48 AM
    I tried removing the foreign keys in the sql editor but it does not work.
    v
    • 2
    • 1
  • Code Review for Realtime
    h

    harshcut

    01/26/2023, 9:58 AM
    I was testing realtime functionalities in supabase, and was wondering if the functions are used correctly as intended. Is there any optimizations that can be made the below file? https://github.com/harshcut/realtime/blob/main/src/App.tsx
  • Avoid duplicate rows where cannot match value of two columns
    p

    petoma

    01/26/2023, 10:06 AM
    I am almost sure my title is a little bit confusing. I know that I can avoid to create a row in Supabase if I specify that one of the values must be unique. But my issue is that I want to avoid the creation of a new row if there is already one where the value of two columns match. In a school database, one student can only have one score for a subject, so if a teacher tries to insert a row and there is already one with the same student_id and subject_id I want that not to be possible. Is there an option to do that?
  • Service Role Key Not Working Properly
    a

    Abdul ♥

    01/26/2023, 12:06 PM
    i used service role key to access a public table with rls enabled. but when i request to access it returns empty array. why tho
    g
    • 2
    • 1
  • Cannot install supabase CLI
    s

    SimonPotvin

    01/26/2023, 12:10 PM
    __To reproduce__: npm install supabase --save-dev __Error message__: ENOENT  ENOENT: no such file or directory, chmod '${project_folder}/node_modules/supabase/bin/supabase' Is there an issue with the latest CLI version?
    c
    o
    • 3
    • 3
  • Database Connection Refused?
    k

    Ken

    01/26/2023, 12:19 PM
    Hi There, I am trying to connect to my PgSQL instance with dBeaver. Previously I had been able to do this just fine, no issues. However, today I can't even get a previously working connection string to connect to the db, it just says "connection refused." My db is responsive in the Supabase UI and through the Python and JS clients. Any ideas?
    a
    s
    • 3
    • 10
  • Why AuthResponse.user can be null?
    f

    Flayy

    01/26/2023, 12:44 PM
    I am using
    signInWithPassword()
    which returns
    Promise<AuthResponse>
    . Now when there won't be any auth error what needs to happen for user to be null?
    Copy code
    ts
    export type AuthResponse =
      | {
          data: {
            user: User | null // <-----------I mean this null
            session: Session | null
          }
          error: null
        }
      | {
          data: {
            user: null
            session: null
          }
          error: AuthError
        }
    Is there some edge case I need to handle? Or I can just assume that
    user
    will be always set and it is just a general type used in many places?
    • 1
    • 1
  • API access to table rows working differently than expected?
    n

    Nafets

    01/26/2023, 1:05 PM
    Please excuse my rather simple question. I have created a table 'orders', that I now want to access via API (using Postman). When I make the 'list' call (https://.supabase.co/rest/v1/orders) I get the expected results. But when I try to access a specific row (https://.supabase.co/rest/v1/orders/1000002) I only get an empty JSON. Images are attached. Can someone please point me to what I am missing? Thank you! Stefan
    g
    • 2
    • 2
  • Auth, Profiles and usernames
    d

    Dbugger

    01/26/2023, 1:50 PM
    I have run the following queries
    Copy code
    -- Create a table for public profiles
    create table profiles (
      id uuid references auth.users on delete cascade not null primary key,
      updated_at timestamp with time zone,
      username text unique,
      full_name text,
      avatar_url text,
      website text,
    
      constraint username_length check (char_length(username) >= 3)
    );
    
    -- This trigger automatically creates a profile entry when a new user signs up via Supabase Auth.
    create function public.handle_new_user()
    returns trigger as $$
    begin
      insert into public.profiles (id, full_name, avatar_url)
      values (new.id, new.raw_user_meta_data->>'full_name', new.raw_user_meta_data->>'avatar_url');
      return new;
    end;
    $$ language plpgsql security definer;
    create trigger on_auth_user_created
      after insert on auth.users
      for each row execute procedure public.handle_new_user();
    But the problem now is that, I want the user to decide his username on Signup. I am using the helpers from
    @supabase/auth-ui-react
    , but I do not see any way to alter it, so that it fits my needs. What do you recommend me? Do I need to build my own Auth forms?
    s
    u
    • 3
    • 4
  • The type 'varchar' is missing from the list of data types
    g

    garyaustin

    01/26/2023, 3:12 PM
    https://github.com/supabase/supabase/issues/11910 By design it seems.
    g
    • 2
    • 1
  • How to use RLS with Realtime PG changes
    p

    pigeatgarlic

    01/26/2023, 2:56 PM
    I have read through the article https://supabase.com/blog/realtime-row-level-security-in-postgresql and very excited about it However, the article is not clear on how to use WALRUS on my application for example, I want my Realtime client to listen to INSERT change on table where they have SELECT privillege, how should I write the RLS rule accordingly?
    g
    • 2
    • 14
  • Property does not exist on type SupabaseClient
    a

    Arthesius

    01/26/2023, 3:09 PM
    From the docs here: https://supabase.com/docs/guides/realtime/quickstart I try this code and I get this type error:
    Copy code
    ts
    Property 'channel' does not exist on type 'SupabaseClient'.
    
    any
  • Logging in with GitHub provider doesn't work
    k

    Kuba

    01/26/2023, 4:02 PM
    Hello! I have a problem with integrating Supabase's auth. I use Next.js along with the packages listed in docs.
    Copy code
    json
        "@supabase/auth-helpers-nextjs": "^0.5.4",
        "@supabase/auth-helpers-react": "^0.3.1",
        "@supabase/auth-ui-react": "^0.2.6",
        "@supabase/supabase-js": "^2.4.1"
    I'm currently testing Supabase with the example provided in
    auth-helpers
    repo for Next.js (https://github.com/supabase/auth-helpers/tree/main/examples/nextjs). However, trying to sign-in with a GitHub does nothing. The request happens in the background (app goes to GH, authenticates, and redirects back to
    /
    ). Is is the intended behavior or rather a bug?
    g
    • 2
    • 5
  • Edge functions with database triggers for managing long running API calls?
    m

    Mathew

    01/26/2023, 4:07 PM
    Hi there, I have a use case where I am calling a 3rd party API that can take up to 30 seconds or so before receiving a response, that response then needs to get saved into my DB in Supabase. Would this be best handled by creating an Edge function to call the 3rd party API, and build my own polling interval or something to check if it's ready, and then when the response is received then save that to DB and have a DB trigger to notify the frontend? What's the simplest way to handle this?
    • 1
    • 1
  • sign up with password throws 500 error
    f

    felixthehat

    01/26/2023, 4:09 PM
    hi I've followed the nuxt 3 quick start, run the auth user management starter and signup with magic link works fine. I would also like to allow signing up with password also, so I added a
    supabase.auth.signInWithPassword
    method, but that throws the following error. Do I have to enable something to allow sign in with password? thanks!
    Copy code
    ode    500
    msg    "Database error saving new user"
    error_id    "78fa69da17f20755-MAN"
    g
    • 2
    • 1
  • Allow read/write access to signed users.
    a

    A-PRYME

    01/26/2023, 4:19 PM
    Coming from firestore, this code below allow read and write access to signed in users.
    Copy code
    service cloud.firestore {
      match /databases/{database}/documents {
        match /{document=**} {
          allow read, write: if request.auth != null;
        }
      }
    }
    What is the equivalent of this with Supabase?
    g
    • 2
    • 1
1...109110111...230Latest