https://supabase.com/ logo
Join Discord
Powered by
# help-and-questions
  • supabase.auth logging out server-side
    s

    stukennedy

    11/11/2022, 4:47 PM
    So ... I'm using Supabase on my own site that uses SSR. I'm managing to do the login using magic links, by getting the URL hash and storing as a cookie. Then I've created my own
    getSupabase
    method for the backend that retrieves the JWT from the cookie and sets the session using
    supabase.auth.setSesssion(...)
    That all works nicely and I can call the api etc. Problem is when I try to logout. I've tried a bunch of things. I delete the cookies and try to call
    setSession
    and
    refreshSession
    (which shouldn't work as it has no tokens to work on anymore from the cookies) but it still returns a user until I manually refresh the page again. What am I doing wrong?
    g
    n
    • 3
    • 10
  • Sign up, Sign in, storing and retrieving data in Vue 3
    r

    Revaycolizer

    11/12/2022, 9:36 AM
    Does anyone know how to enable sign up, sign in, storing and retrieving data from supabase in Vue 3?
    g
    h
    • 3
    • 18
  • Unsubscribe from a realtime channel
    h

    Hermes

    11/12/2022, 2:26 PM
    How exactly does a client unsub from a realtime channel (Postgres CDC)? From the docs, there is
    removeChannel()
    which unsubs and 'removes' the channel from client. What does the remove part mean, if multiple clients are connected to the channel, and one client does a
    removeChannel()
    with that channels' name, does it also end the channel for the other clients? And there is also a
    supabase.channel().unsubscribe()
    which 'unsubscribes from server events and instructs server to terminate'...
    Copy code
    JavaScript
    // snippet from CommentItem component
    // LISTEN FOR WHEN THE COMMENT IS UPDATED OR DELETED
        useEffect(() => {
            const { id: commentID } = commentData;
            const channelName = `public:comments:id=eq.${commentID}`;
            supabase
                .channel(channelName)
                .on(
                    "postgres_changes",
                    {
                        event: "UPDATE",
                        schema: "public",
                        table: "comments",
                        filter: `id=eq.${commentID}`,
                    },
                    onCommentUpdated
                )
                .on(
                    "postgres_changes",
                    {
                        event: "DELETE",
                        schema: "public",
                        table: "comments",
                        filter: `id=eq.${commentID}`,
                    },
                    onCommentDeleted
                )
                .subscribe();
            return () => supabase.removeChannel(channelName);
        }, [commentData, onCommentDeleted, onCommentUpdated]);
    I just want that when the commentItem component unmounts, it should stop listening for those postgres changes on the comments table.
    g
    • 2
    • 5
  • Unable to get useSupabaseClient() function from auth helpers working with Nextjs
    s

    Spoonz

    11/12/2022, 7:23 PM
    This is the error code from dev console
    Copy code
    Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
    1. You might have mismatching versions of React and the renderer (such as React DOM)
    2. You might be breaking the Rules of Hooks
    3. You might have more than one copy of React in the same app
  • Management api usage
    a

    Abhinav_MV

    11/12/2022, 7:32 PM
    Hey how can i create a function using management api. To be more specific i need to add the definition of the function using management api... is it possible ?
    s
    g
    • 3
    • 9
  • How to use getStaticPaths and getStaticProps with new Supabase auth helpers
    s

    Spoonz

    11/12/2022, 8:25 PM
    Can anyone provide an example of how to use NextJS getStaticPaths and getStaticProps with the new
    @supabase/auth-helpers-react
    and
    @supabase/auth-helpers-nextjs
    packages. Every time I try and get it to work myself I end up with useContext errors as the useSupabaseClient() hook is being called outside of the main function.
    n
    l
    l
    • 4
    • 13
  • configure local supabase to use a different port
    j

    jkohlin

    11/12/2022, 11:46 PM
    Is there a way to configure supabase to run at port 3001 since it collides with remix running on port 3000. Can it be done after supabase init? I can't find the docker files
    s
    • 2
    • 4
  • Creating local project from remote -- ERROR relation graphql.schema_version does not exist
    d

    donnybystrom

    11/13/2022, 9:40 AM
    Hi guys! I'm trying to create a local development environment from an existing remote project. Following the guide at https://supabase.com/docs/guides/cli/local-development, npx supabase init npx supabase start npx supabase db remote commit npx supabase db reset I get the following error running the reset command:
    Copy code
    Error: ERROR: relation "graphql.schema_version" does not exist (SQLSTATE 42P01)
    At statement 125:                                                                                   
                                                                                      
                                                                                      
    --                                                                                
    -- Name: TABLE "schema_version"; Type: ACL; Schema: graphql; Owner: supabase_admin
    --                                                                                
                                                                                      
    GRANT ALL ON TABLE "graphql"."schema_version" TO "postgres";
    Looking at the generated migration file, it doesn't seem to create the table graphql.schema_version. I'm guessing the CLI creates a different type of base database locally than what is hosted remotely? The remote project is 4-5 months old and been done entirely in production. Do you guys know what I can do? Is there a better way to migrate the db, a way to ensure local is the same version as remote, or a safe way to upgrade the remote db? My supabase CLI version is 1.12.2 Best regards Donny
    s
    • 2
    • 1
  • DATA IS NOT UPDATING
    s

    sebx

    11/13/2022, 10:14 AM
    Just tried using prisma to see if the supabase-js client is the issue -- same result
  • data is NOT updating
    s

    sebx

    11/13/2022, 11:11 AM
    I'm loosing my mind trying to debug this -- I'm not convinced it's not an issue with my code but I've been at testing every piece for hours and hours now.... It seems like my boolean data is not updating --- UNLESS it is only one field at a time that I'm updating...... Whaaaat. Also, to make it worse: the result i get back from a supabase client query AFTER updating a row is correct -- but it doesn't actually save in the database. The code looks regular:
    Copy code
    ts
      const {data} = await supabaseClient.from("subscriptions")
        .update({...subscriptionData}) // includes {"isSubscribed": true}
        .match({subscriberId: sub.userId})
        .select('subscriberId,isSubscribed')
    
      console.log(data) 
    // {"subscriberId": 4926568, "isSubscribed": true}
    BUT sql editor on dashboard returns
    isSubscribed: false
    I also tried using prisma, same problem. Doesn't save the updates....
    n
    g
    s
    • 4
    • 164
  • Why does this simple foreign key one-to-many relationship give Typescript errors ?
    c

    chrismasters

    11/13/2022, 12:38 PM
    If I have simple relationship where each playlist includes a list of tracks...
    Copy code
    sql
    CREATE TABLE public.playlists (
        id bigint generated by default as identity primary key,
        track_id bigint references public.tracks NOT NULL
    );
    CREATE TABLE public.tracks (
        id bigint generated by default as identity primary key,
        title text NOT NULL,
        artist_name text
    );
    And then access this with a query like this...
    Copy code
    ts
    const { data } = await supabase
      .from('playlists')
      .select(`
        id,
        tracks (
          title,
          artist_name
        )
      `)
    I'd imagined that
    tracks.title
    could only be either a
    string
    or
    null
    type so I could use
    tracks?.title
    to make Typescript happy. But my typescript is giving errors if I use either
    tracks.title
    or
    tracks?.title
    Copy code
    ts
    Property 'title' does not exist on type '({ title: string; } & { artist_name: string | null; }) | ({ title: string; } & { artist_name: string | null; })[]'.
    Property 'title' does not exist on type '({ title: string; } & { artist_name: string | null; })[]'.
    What am I missing? Also, semantically, shouldn't this relationship name be better changed to
    track
    from
    tracks
    as it is singular? Thanks!
    e
    d
    • 3
    • 3
  • Failed to create pg.functions syntax error...
    m

    MrSandyWilly

    11/13/2022, 3:56 PM
    Simple question... what's wrong with this postgres function?
    SELECT * FROM textures ORDER BY id DESC LIMIT 1;
    Trying to select the most recent row.
    g
    • 2
    • 2
  • Collaborate on the same DB
    m

    Mx

    11/13/2022, 7:34 PM
    This is probably a silly question, but how do I invite other people to work on a project with me? I need to give access to the table editor to someone else
    s
    • 2
    • 4
  • What tools are you guys using for migrating between environments?
    d

    donnybystrom

    11/14/2022, 8:40 AM
    I'm looking for a tool chain that supports up() and down() migrations and plays well with the supabase echosystem from local > staging > production. For you guys running multiple environments, what are you using?
    n
    s
    • 3
    • 6
  • Realtime payload property new is returning incomplete data
    m

    MDobs

    11/14/2022, 2:33 PM
    I am listening to
    UPDATE
    for changes in a DB row using realtime, however the response I get on the
    new
    property of the payload doesn't include all the data from that row. Specifically querying the db row does bring back the complete dataset as expected. Is this correct behavior?
    j
    g
    g
    • 4
    • 7
  • FATAL Failed to load configuration required key GOTRUE_DB_DRIVER missing value
    h

    hyodo

    11/14/2022, 4:06 PM
    I have many following auth errors in web console. "FATAL Failed to load configuration required key GOTRUE_DB_DRIVER missing value" How can I fix it?
    g
    z
    • 3
    • 6
  • How do I paginate Supabase requests?
    k

    konga

    11/15/2022, 12:06 AM
    I have a table that has a few thousand rows that I need to process. I want to process the data in chunks. How do I paginate the requests?
    n
    g
    s
    • 4
    • 7
  • Realtime CDC return Error 401 Unautorized
    j

    jor

    11/15/2022, 4:41 AM
    Not sure why this happen, been looking online but found no solution, I did not enable RLS and did turn on replication for the table. Any idea?
    j
    g
    • 3
    • 28
  • supabase.auth.setSession() not working in serverless function
    k

    Kellen Mace

    11/15/2022, 5:40 AM
    In my SvelteKit app, I need to pass the user's access token & refresh token to an API endpoint, set up an auth session for the user, then fire off some authenticated requests to Supabase. It's not working, though. Details: First, I fire off a request to an API endpoint like this, passing along the user's access token and refresh token:
    Copy code
    ts
    const userSession = (await supabase.auth.getSession()).data.session;
    const response = await fetch('/api/stripe-checkout-session', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        accessToken: userSession?.access_token ?? '',
        refreshToken: userSession?.refresh_token ?? '',
      })
    });
    The request handler function for that API endpoint looks like this:
    Copy code
    ts
    export async function POST(event: RequestEvent): Promise<Response> {
        const { accessToken, refreshToken } = await event.request.json();
    
        const { data: setSessionData, error: setSessionError } = await supabase.auth.setSession({
            access_token: accessToken,
            refresh_token: refreshToken,
        });
    
            // 👇 Results in `{ session: null }`
        const { data: getSessionData, error: getSessionError } = await supabase.auth.getSession();
    }
    When I run
    console.log(setSessionData)
    , I get this:
    Copy code
    ts
    {
      session: {
        access_token: 'access-token-goes-here',
        refresh_token: 'refresh-token-goes-here',
        user: { ... },
        token_type: 'bearer',
        expires_in: 2402.638000011444,
        expires_at: 1668490476
      },
      user: {
        id: 'user-id-goes-here',
        aud: 'authenticated',
        role: 'authenticated',
        // ...
      }
    }
    n
    j
    +2
    • 5
    • 8
  • Auth UI not working
    z

    Zeph

    11/15/2022, 8:53 AM
    Hi! I followed the documentation to create a login page using Supabase's Auth UI. My code looks like this:
    Copy code
    ts
    import { Auth, ThemeSupa } from '@supabase/auth-ui-react'
    import { useSupabaseClient } from '@supabase/auth-helpers-react'
    
    export default function Login() {
      const supabaseClient = useSupabaseClient()
      return (
        <Auth
          supabaseClient={supabaseClient}
          appeararance={{ theme: ThemeSupa }}
          theme="dark"
          socialLayout='horizontal'
          redirectTo="http://localhost:3000/"
        />
      )
    }
    But my UI ends up looking like the image attached. Also, the redirect does not work. I am still able to login and logout but its just the styling and redirect that is the issue. Thank you!
    s
    • 2
    • 4
  • resetPasswordForEmail not adhering to 'redirectTo' value
    u

    49Ryann

    11/15/2022, 10:38 AM
    Any reasons why this code called from the front end wouldn't embed my redirectTo string, instead still uses localhost? This is the string it emails the user:
    Copy code
    https://.....supabase.co/auth/v1/verify?token=cbf72dec7017df95f6e91762124ef76943a367eb441af09c9e8f4f1e&type=recovery&redirect_to=http://localhost:4200/
    i
    • 2
    • 5
  • Auth Tokens from Auth provider
    d

    Diogovski

    11/15/2022, 5:59 PM
    Is it possible to get the auth tokens from an account loggin via auth? In my case i need the users auth and secret token, with nextauth i can get them, i want to know if supabase provides them on response
    j
    s
    g
    • 4
    • 16
  • Unexpected token 'I', Invalid request body is not valid JSON
    s

    Smardrengr

    11/15/2022, 7:01 PM
    Continued working on up my SvelteKit + Supabase Auth Helpers project from yesterday... tried signing in, and... suddenly I'm getting a
    500
    error when Supabase tries to apply auth actions.
    Copy code
    Unexpected token 'I', "Invalid request body" is not valid JSON
    SyntaxError: Unexpected token 'I', "Invalid request body" is not valid JSON
    ?! Only a few minor changes to the project from what I pushed to production yesterday (and which works). Cannot for the life of me see what suddenly changed. This error happens in
    npm run dev
    and
    npm run build
    . Here's the DevTools window: Any ideas? Where should I look?
    s
    • 2
    • 4
  • Query based on user ID and other Table
    i

    iStun4Fun

    11/15/2022, 8:34 PM
    As i cant refer text to text on relations, I need to do a query to fetch like following: Sum all Total Revenue where store_royalties.Label = music_label_name => ref Owner.uuid = Auth.uuid Or maybe I Should premodel the data to add a INT at Store Royalties and refer where Label Name = Label_ID to link them for faster sums later? I'm so stuck on this and Would LOVE to have a hand on how to solve it...
    u
    s
    • 3
    • 5
  • Supabase postgres function is not found on supabase js
    c

    Cardoso

    11/16/2022, 1:55 AM
    Hi. I have this function that when i use the rpc function of supabase returns me the following.
    Copy code
    CREATE OR REPLACE FUNCTION close_advertisements (lat float, lng float)
        RETURNS SETOF public.advertisements
        LANGUAGE plpgsql
        AS $$
    BEGIN
        RETURN query (
            SELECT
                *
            FROM
                advertisements
            WHERE
                ST_DWithin (geom, ST_SetSRID (ST_MakePoint (lng, lat), 4326), 10000));
    END;
    $$
    SECURITY DEFINER SET search_path = extensions, public, pg_temp;
    Error message: "Could not find the public.close_advertisements() function or the public.close_advertisements function with a single unnamed json or jsonb parameter in the schema cache" I added the security definer to try an make it visible but without success
    g
    s
    • 3
    • 12
  • webhook listener
    d

    dave johnson

    11/16/2022, 2:04 AM
    I want to capture,parse & store json from an external webhook. It looks like edge functions can serve that purpose... are there any examples or boiler plate example functions, that capture json elements and store to the DB? (saw the stripe tutorial, but it did not included storing data to db)
    n
    • 2
    • 1
  • AuthApiError using supabase-js from node
    d

    Davepar

    11/16/2022, 2:12 AM
    I'm trying to write some simple test scripts that sign in a test user and access the database, but I keep getting an auth error. It's like the client library isn't storing the auth token or something. The error happens in my Jest test script, but also just from a simple node script like:
    Copy code
    import { createClient } from '@supabase/supabase-js'
    
    const PUBLIC_SUPABASE_URL="https://xxxxxxxxx.supabase.co";
    const PUBLIC_SUPABASE_ANON_KEY="xxxxxxxxxxxxx";
    
    const supabase = createClient(PUBLIC_SUPABASE_URL, PUBLIC_SUPABASE_ANON_KEY);
    
    const result = await supabase.auth.signInWithPassword({
      email: 'bob@example.com',
      password: 'mypassword',
    });
    console.log('result', result);
    console.log('user', await supabase.auth.getUser());
    The signInWithPassword() call returns the correct session and user, but the getUser() call returns the error:
    AuthApiError: invalid claim: missing sub claim
    And any other call seems to be unauthenticated.
    j
    • 2
    • 2
  • [Solved] Can't access API Settings on local dashboard, blocking local edge functions dev for schema
    d

    darren

    11/16/2022, 2:19 AM
    Hey y'all! I want to expose a schema so that I can interact with it using supabase-js in my local development setup for edge functions but I'm running into issues. I'm using
    createClient(URL, KEY, {db: {schema: 'stats'}} )
    as seen in the reference guide for supabase-js [1]. The error I get when I run this locally is:
    error: TS2322 [ERROR]: Type '"stats"' is not assignable to type '"public"'
    . I have verified that this schema does exist in the local database when I run psql directly. According to the docs, you have to expose new schemas to the API via the supabase dashboard by going to
    Settings > API Settings > Exposed Schemas
    and adding it manually there. Unfortunately, while this works for the production dashboard I can't get to that setting on my local dashboard. What can I do to expose a schema I made on local? [1]: https://supabase.com/docs/reference/javascript/initializing#api-schemas
    g
    w
    • 3
    • 4
  • index row size 2952 exceeds btree version 4 maximum 2704 for index tablename_columname_key
    a

    arch

    11/16/2022, 8:35 AM
    I trying to insert a data uri string to a text datatype column . i get this error when i do so
    g
    • 2
    • 2
  • how to use timestamptz
    s

    Siddharth

    11/16/2022, 9:28 AM
    Whenever I am entering a new row in my database it is showing in UTC but I want in Indian standard time IST +5:30 So I tried to use timestamptz but stuck at its default value (now() AT TIME ZONE 'utc'::text) I tried to replace the UTC with IST but no use I am still getting UTC time in my row
    n
    j
    m
    • 4
    • 6
1...646566...230Latest