https://supabase.com/ logo
Join Discord
Powered by
# help-and-questions
  • Issues with Magic Links
    d

    death_wears_bunny_slippers

    10/02/2022, 11:16 PM
    Hi, I'm new to Supabase. I'm having the following issues with magic links: 1. Sometimes clicking on the link does not seem to authorize me. It opens my app and the
    pages/index.js
    getServerSideProps()
    redirects to my signin page. This is intermittent although it seems to be happening more frequently in the last few hours. When this happens, if I wait a minute or two it sometimes just magically redirects to the home page. So perhaps this is a latency issue as far as setting the session on Supabase? 2. After authenticating, calling
    req.cookies["sb-access-token"]
    in an API route sometimes returns
    undefined
    . This too is intermittent. Other times I can see the cookie and it matched what I see in the developer tools. Has anyone else had a similar issue? Is there anything specific I should try?
  • Getting profile data from another table
    b

    Brams

    10/03/2022, 12:21 AM
    Hi all, very new to supabase and started building a basic direct messaging chat app in React Native. So far I've managed to load the conversations and their corresponding messages including new messages being rendered in realtime, but unfortunately not quite sure on what the best approach would be to get the user name showing as the conversations title in the overview I figured I'd make a conversations table and conversation_participants table in Supabase *In the conversation table I have a column for ID, created_at and Name (which is being displayed as the title in the video) In the conversation_participants I have an ID (primary key relation to conversations table id), profile_id (foreign key relation to profiles table) and created_at columns* My question would be what approach you would recommend to get the profile data (first_name and last_name) into my ConversationsScreen component in React Native (where the user should be able to select which conversation to open) Any suggestions would be greatly appreciated 🙌!
    simulator-screen-recording-iphone-13-2022-10-02-at-20-16-11
    j
    m
    • 3
    • 3
  • Get results of created function in SQL editor with select.
    g

    garyaustin

    10/03/2022, 1:01 AM
    I think I know the answer, but just checking. Basically I want to run explain analyze but also do several sql commands before that. This does not work because the SQL editor (and 3rd party Datagrip editor) don't return results if there are more than one sql command. So an alternative would be to somehow create a function with the explain code in it and then display the result after running in the SQL editor.
    Copy code
    CREATE OR REPLACE FUNCTION run_explain()
      RETURNS SETOF text AS
    $$
    BEGIN
       // more stuff here
       RETURN QUERY
       EXPLAIN ANALYZE SELECT * FROM messages;
    END
    $$ LANGUAGE plpgsql;
    select * from run_explain();
    This does not work for same reason above. Supabase SQL editor just returns successful and Datagrip asks which command to run. Is there anyway to create/replace a function and get the result in the SQL editor I'm missing? Otherwise doing two separate windows with the create and select I assume is as good as it gets.
    j
    • 2
    • 1
  • Return Error from Edge Function
    b

    BoogersLLC

    10/03/2022, 1:05 AM
    Hello, I'm trying to return a custom error from an edge function. You can see in the screenshot attached I can return the response as a 500. However, I don't understand how to throw an error so that the supabase
    invoke
    function catches the error (and then populates
    error
    instead of
    data
    ) I'm also pretty confused because if I try to just
    throw new Error('some error')
    instead of returning a response, I get a CORS Policy block. So it seems like I must return a response with my CORS headers, but then I'm not sure how to return an error at that point? I'm also a total Deno noob, so I may be missing something really obvious here.
    • 1
    • 2
  • Can't seem to cross intermediary table
    e

    Elector

    10/03/2022, 2:39 AM
    I apologize for my ignorance, but SQL is not my strong point. My tables:
    Copy code
    event {
        id: UUID
    }
    
    category: {
        id: int,
        name: text
    }
    
    criterion: {
        question: text
        category_id: FK -> category
    }
    
    event_category {
        event_id: FK -> event
        category_id: FK -> category
    }
    So, each category has various criteria. And an event can have various categories. What I can't seem to do is answer the question: "For this event, what are all the criteria that apply?" This is what I have so far. I can get to the category, but I can't get across the intermediary table:
    Copy code
    javascript
    let { data, error, status } = await supabase
      .from('criterion')
      .select('category_id, question, category_id!inner(name)')
      .eq('category_id.name', 'Event');
    I know my from table needs to be criterion, and I know I need go to up from criterion to category (with an inner join, and I've made this happen). I know I also need to go across event_category, but I can't seem to work out the supabase query for that. If anyone could provide advice, it would be greatly appreciated.
    j
    • 2
    • 5
  • Constraints in Supabase UI?
    u

    user8923

    10/03/2022, 3:00 AM
    Is it me or there is no way anywhere in the Supabase UI to view the table and column constraints? SQL query required? Not even the slightest indication that there is a constrain on a table? Bummer...
    j
    g
    • 3
    • 7
  • Realtime doesn't work locally.
    c

    corasan

    10/03/2022, 4:14 AM
    I am using
    v2.0.0-rc.10
    , and it works fine when I point my application to the remote db, but when I point it to my local environment it doesn't get any updates. I checked the state of each channel and they all say "joined". I checked the logs as well and I can see that it
    JOINED realtime:xxxx
    .
    g
    • 2
    • 2
  • DROP Table timeout
    b

    Bruce Wang

    10/03/2022, 4:40 AM
    I am using sqlalchmey orm to interact with supabase, which so far has been seemless. However a key part of our process is dropping tables daily. Testing this, the first subsequent call to drop a table is timing out. Keep in mind this same process works fine on a locally deployed postgres instances aswell as one hosted online (not supabase) Function I am calling to drop tables: Base.metadata.drop_all(bind=engine)
    s
    • 2
    • 1
  • Error 404 while using React UserProvider
    m

    Monky

    10/03/2022, 9:38 AM
    Hi. Just like in the title I am having a problem with setting up Auth in NextJS. I am using this guide: https://supabase.com/docs/guides/auth/auth-helpers/nextjs, but seems that I can't get it to work properly. The API routes (for example: user) return a 404 error right away on every page. However the operations like SignUp seem to work great. I'm not really sure what the problem is since my code did exactly the same after copying the code from the guide. My current code looks like this: ``_app.ts``
    Copy code
    ts
     // Components
    import { ThemeProvider } from 'next-themes';
    import { UserProvider } from '@supabase/auth-helpers-react';
    
    // Variables
    import { supabaseClient } from '@supabase/auth-helpers-nextjs';
    
    // Styles
    import '../styles/globals.css';
    
    // Types
    import type { ReactElement, ReactNode } from 'react';
    import type { NextPage } from 'next';
    import type { AppProps } from 'next/app';
    
    export type NextPageWithLayout<P = {}, IP = P> = NextPage<P, IP> & {
      getLayout?: (page: ReactElement) => ReactNode;
    };
    
    interface AppPropsWithLayout extends AppProps {
      Component: NextPageWithLayout;
    }
    
    function MyApp({ Component, pageProps }: AppPropsWithLayout) {
      const getLayout = Component.getLayout ?? ((page) => page);
    
      return getLayout(
        <UserProvider supabaseClient={supabaseClient}>
          <ThemeProvider attribute="class">
            <Component {...pageProps} />
          </ThemeProvider>
        </UserProvider>
      );
    }
    
    export default MyApp;
    ``api/auth/[...supabase].ts``
    Copy code
    ts
    import { handleAuth } from '@supabase/auth-helpers-nextjs';
    
    export default handleAuth({ logout: { returnTo: '/' } });
    This is the error generated by the ``useUser`` hook: ``The request to /api/auth/user failed!`` And here the ``UserProvider`` console error: ``GET http://localhost:3000/api/auth/user 404 (Not Found)``
    • 1
    • 1
  • Is it possible to send a file to an edge function and save the file in Supabase storage?
    c

    cdedreuille

    10/03/2022, 11:02 AM
    I'm having a hard time sending a file to an edge function for it to be saved. Perhaps this is not the right thing to do but I was wondering if this was possible.
    Copy code
    const file = e.target.files[0];
    
    let formData = new FormData();
    formData.append("file", file);
    
    const { data, error } = await supabaseClient.functions.invoke(
      "media-upload",
      {
        body: JSON.stringify({
          file: formData,
        }),
      }
    );
    This is how I send my file to the edge function but inside the function I can't do
    file.getAll("file")
    . Anyone knows what I'm doing wrong?
    j
    • 2
    • 2
  • Disable RLS
    d

    daveteu

    10/03/2022, 11:48 AM
    I am new to postgres, so I have a simple security question about RLS which I cannot find a straight forward answer. I understand if I apply RLS, I can add policy (e.g. user authenticated with supabase), I can have authenticated users have read/write access to the specific row.. Does that also means if RLS is disabled, that table can only be accessed by backend (with the proper token), and inaccessible from frontend ? Im asking because I am seeing some admin_ tables have RLS enabled.., while some are disabled.
    m
    • 2
    • 1
  • Supabase auth with Cloudflare workers
    r

    rishav

    10/03/2022, 12:27 PM
    Are there any good tutorials on using Supabase auth with a Cloudflare workers app? Something which shows the entire flow - from users seeing the social login page to the cookie parsing - to fetching the user details
    a
    • 2
    • 1
  • Cannot use 'supabase.auth.api.setAuthCookie'
    s

    Sherlock7

    10/03/2022, 12:53 PM
    I'm new to supabase and I've been following tutorials (supabase's and some others on the internet) but so far couldn't manage to make this work (see image). I'm trying to set up Authentication with Nextjs. I'm using next(with ts) v12.3.1, node v18.1.0 and the last packages from supabase Thanks in advance
    g
    s
    j
    • 4
    • 7
  • Env variable in nodejs to init client
    m

    Mokamars

    10/03/2022, 2:14 PM
    Hi everyone, do you know how to use env variables to initate the client ? Get an error while starting the app. It seems answers for Next and VITE does not work. Thanks
    g
    • 2
    • 12
  • Referencing columns from one table to another (not id)
    g

    garyaustin

    10/03/2022, 3:20 PM
    Why are you not able to do a foreign key? Is the content title declared unique?
    h
    • 2
    • 33
  • Trying to pause a project takes too long
    d

    dubo

    10/03/2022, 5:03 PM
    basically the title
    g
    • 2
    • 3
  • What's the best way to debug any RLS policy?
    c

    chaos

    10/03/2022, 6:21 PM
    I have written a complex RLS insert check, and it's failing where it should pass. How can I debug it efficiently?
  • Help understanding trigger function for inserting into users profile
    v

    Vik

    10/03/2022, 8:39 PM
    Hey, I'm working on creating a function that will trigger whenever a new user signs up. I need some help understanding this approach and if it works how I think it does. To start, this is what my profiles table looks like:
    Copy code
    create table profiles (
      id uuid references auth.users not null,
      join_date timestamp with time zone,
      username citext unique,
      avatar_url text,
      first_name text,
      last_name text,
      birthday text,
      about text,
      private boolean,
    
      primary key (id),
      constraint username_length check (char_length(username) >= 3 and char_length(username) <= 30),
      constraint first_name_length check (char_length(first_name) <= 30),
      constraint last_name_length check (char_length(last_name) <= 30),
      constraint birthday_length check (char_length(birthday) <= 50),
      constraint about_length check (char_length(about) <= 100)
    );
    As for the username, I left it just as unique because I want to handle that flow on the frontend. If the username is not set the user has not completed onboarding so they will be presented with a username creation screen first. But for my function, I do want it to set the id, join_date, and private to false. This is what I have written out but would love some eyes on it.
    Copy code
    begin
      insert into profiles(id, join_date, private)
      values(new.id, new.now(), new.false)
    end;
    Does the
    new.now()
    work as I expect it to? A date time stamp and in general does that function structure look correct? Thank you in advance!
    g
    • 2
    • 9
  • Help me figure out supabase-js v2 realtime with Typescript
    u

    user8923

    10/04/2022, 2:42 AM
    I'm trying to follow the examples in the docs on how to set up realtime with V2. My eslint config disallows the use of the
    any
    type. What is the type of the
    payload
    arg in the example below?
    Copy code
    supabase
      .channel("*")
      .on("postgres_changes", { event: "*", schema: "*" }, payload =>
      {
        console.log("Change received!", payload);
      })
      .subscribe();
    j
    • 2
    • 3
  • SELECT based on auth.uid()
    h

    Homemadesteam58

    10/04/2022, 6:02 AM
    Check out this on the documentation. It helped me to get RLS working and I think the video has the solution you are looking for
    c
    g
    • 3
    • 4
  • Multiple row subscription return
    a

    AntonOfTheWoods

    10/04/2022, 6:19 AM
    It appears that rows that are updated get pushed individually to subscribers, even if they are inserted as part of a single insert instruction. Is there any way to get supabase to batch these to a single push?
    g
    • 2
    • 6
  • Is there a way to restrict selecting of only certain rows based on a table column through RLS?
    r

    rinorzk

    10/04/2022, 8:45 AM
    I have a table for rooms let's say, and I have two types or rooms, public and private, so I want to list all the public rooms to the user, however I don't want to include the private ones unless the user is a member of that room (added from the admin). Now ofc in my application I can use the
    eq("type", "public")
    , but I wanted to ask is this the safest way, is there a better way to secure this?
    n
    g
    • 3
    • 11
  • Need guidance on how to make my chat functionality, please help!
    l

    lewisd

    10/04/2022, 8:54 AM
    Hi guys, I'm trying to create a chat app and i've ran into some trouble. When inside a chat, getting new messages into the UI is fine and works great. It's really simple, just listen to the
    conversationMessages
    table and filter by the
    conversationId
    that we are currently on - Great stuff ✅ The problem I have is the Inbox component. It needs to show: - All current conversations you're involved in - The latest message sent to each chat - Whether it has been read or not by the user (I compare
    conversationMembers.lastRead
    with the latest
    conversationMessages.createdAt
    - Needs to update in realtime - if im on my inbox screen and get a new message, I expect that chat to move up to 1st place and show the new message. I have created a
    view
    called
    conversationsView
    that gets all the above data ready for me and it works great. However, I failed to realise you cannot use
    realtime
    on
    views
    😔 so my plan has failed on the last hurdle. When a new message is sent, the inbox is not updated in realtime. Does anyone see a way of achieving this? Im quite new to SQL. I've attached an image of my db design and chat component. I've spent 3 days trying to figure out a way of doing this 😆 If anyone has a good method of achieving this please put me out of my misery haha.
    g
    j
    +2
    • 5
    • 17
  • Database Webhooks (Function hooks) clarification
    c

    caracalla

    10/04/2022, 9:46 AM
    Posted this question on Reddit already, and now posting it here as well. A am not really sure which communication channel is preferred. I've checked the documentation for this feature on the Supabase page https://supabase.com/blog/supabase-functions-updates#database-webhooks-alpha and on the docs page https://supabase.github.io/pg_net/api/#nethttp_post. I understand the concept of Database Webhooks and how to use them, but as always, the devil is in the details. What happens if HTTP/Webhook endpoint (URL) is (temporarily) not accessible for whatever reason? Will Supabase retry the GET/POST request after a while? If so, how many times? Are there any logs to see if there are issues?
    s
    • 2
    • 1
  • RLS Policy giving ERROR413 on request
    m

    Midas

    10/04/2022, 11:07 AM
    I have this RLS Policy that calls a database function, but for some reason it is giving a 413 request error
    g
    • 2
    • 6
  • API too slow all of a sudden
    d

    danishyasin33

    10/04/2022, 1:37 PM
    Our API has slowed down all of a sudden, this is causing our lambdas to time out. Please assist. I have contacted support but no response yet. We're a paying customer on Pro tier. Please assist. It is taking 6 mins for the API to respond.
    o
    • 2
    • 2
  • Get user.id server-side in Next.js
    u

    매튜

    10/04/2022, 5:22 PM
    I'm trying to select user-specific rows using the UUID in getServerSideProps in Next.js but haven't found a solution yet (using auth-helpers). The below works client side but not server side. export const getServerSideProps = withPageAuth({ redirectTo: '/', async getServerSideProps() { // Find out how many words user is currently studying at novice level - maximum allowed is 200 const { data } = await supabaseServerClient() .from('_users_vocabulary') .select('*') .eq('B', user.id); return { props: { data } }; } });
    g
    n
    • 3
    • 21
  • row level security and react query
    c

    Corentin_dev

    10/04/2022, 7:51 PM
    Hi, I am using react query on a side project. When I login and land on the dashboard, I have a table with item coming from a Supabase table. This table a RLS to display only row from the auth user (auth.uid() = user_id) But, when the query run for the first time, I get the empty array (RLS block). Nevertheless, when i leave the window and come back (so that react query refetch the data) I do get the data. I tried to add a a enable option to pause if there is no user but the user is present at the first query.. I am understand why I don't get the data for the first time Thanks in advance for your help !
    g
    h
    n
    • 4
    • 13
  • SOLVED Build docker images locally (willing to contribute, am experienced with ansible)
    m

    Milou

    10/05/2022, 12:05 AM
    Hi! I'm trying to get a supabse/postgres image working with the
    pg_jsonschema
    extension installed. Since the
    pg_jsonschema
    extension is not yet available in the default supabase/postrges images, I wan't to build a custom one locally. According to this wiki page: https://github.com/supabase/postgres/wiki/Docker I am supposed to run this ansible playbook in order to generate a container: https://github.com/supabase/postgres/blob/develop/ansible/playbook-docker.yml This playbook imports, among other tasks, this task file: https://github.com/supabase/postgres/blob/develop/ansible/tasks/docker/setup.yml Which to me looks like tasks that should be run inside the container, correct? The docs don't mention that this playbook should be run against a running container, it sounds more like the container is generated when running the playbook. Could someone clarify how this works?
    s
    • 2
    • 6
  • Realtime and CRUD in React, best practices?
    u

    user8923

    10/05/2022, 2:53 AM
    Let us say we create a React Todo app with simple CRUD operations. We want this app to be realtime so that changes are instantly seen by other connected clients. When I add a new todo via a form, I make a call into supabase to insert a new todo row and immediately select the result in order to obtain an todo object that includes the auto-generated id column. I then add this todo object to my state. The problem is that I'm also receiving that same todo via the realtime subscription, as if it had been created by someone else. To avoid duplication I compare the id of the newly insert todo with the one just received from the sub, and if they match I do not update the UI. Is this the right approach? Is there a way to avoid pushing changes to the client that initiated it?
    g
    • 2
    • 4
1...373839...230Latest