https://supabase.com/ logo
Join Discord
Powered by
# help-and-questions
  • append CSV to table through code
    d

    dev Joakim Pedersen

    01/18/2023, 3:34 PM
    Alright so, I have an admin panel for my clients. they are a collection of different stores. And it would be great if i could let my users upload a CSV to append to my products_table. My colleague got a collection of 1200 product that he managed to upload in 2 days of work with SQL. not sure how he made this happen but it was not a pleasant ride. So I guess it's up to me to create a simple button to upload. I'm not sure how this will go on. so question is have anyone made this feature? if so how did you do it ? I'm using the JS client. and Next.js as my framework of choice 😊
  • Why do I get an empty array even if the DB is populated with this code?
    d

    dandis

    01/18/2023, 4:18 PM
    Copy code
    export const getQuotas = async (company_id) => {
        let { data: quota, error } = await supabase.from('quota').select('*');
        const quotaData = quota;
        return quotaData;
    };
    When I log what this function returns, it's simply an empty array. I have the said table (quota) populated.
    g
    m
    g
    • 4
    • 8
  • Creating a function and trigger for new users
    e

    Esore

    01/18/2023, 5:11 PM
    I created the following function and trigger
    Copy code
    CREATE OR REPLACE FUNCTION create_user_and_account()
    RETURNS TRIGGER AS $$
    DECLARE new_id UUID;
    BEGIN
        SELECT gen_random_uuid() INTO new_id;
        INSERT INTO public.users(id, email) VALUES (new_id, NEW.email);
        INSERT INTO public.accounts(owner_id) VALUES (new_id);
        RETURN NEW;
    END;
    $$ LANGUAGE plpgsql;
    
    
    CREATE TRIGGER create_user_and_account_trigger
    AFTER INSERT ON auth.users
    FOR EACH ROW
    EXECUTE FUNCTION create_user_and_account();
    I get success, however now when I try to register a new user it is unable to. Why is this the case and how can i remedy it? What I am trying to do is since we cannot edit the auth.users table I want to be able to get the information from it such as the id and email and put into a newly built public.auth table and put that data inthere and also create a public.account row so that it is a user inside an account. The reason that I did this is that I want multiple users to be within 1 account like for an Enterprise System. Any help would be great!
    g
    • 2
    • 50
  • NextJs middleware returns null on await supabase.auth.getSession()
    j

    JeromeK

    01/18/2023, 5:46 PM
    Hey Guys I want to protect routes with middleware in Nextjs13 (not using the app dir) I login the user like this on
    /pages/login.tsx
    Copy code
    ts
    const { error, data } = await supabase.auth.signInWithPassword({email, password});
    /lib/supabaseClient.ts
    Copy code
    ts
    import { createClient } from "@supabase/supabase-js";
    
    const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL;
    const supabaseKey = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY;
    
    export const supabase = createClient(supabaseUrl, supabaseKey);
    and I would like to validate it like this on
    /middleware.ts
    Copy code
    ts
    import type { NextRequest } from "next/server";
    import { NextResponse } from "next/server";
    
    import { createMiddlewareSupabaseClient } from "@supabase/auth-helpers-nextjs";
    
    export async function middleware(req: NextRequest) {
      const res = NextResponse.next();
      // Create authenticated Supabase Client.
      const supabase = createMiddlewareSupabaseClient({ req, res });
      const {data: { session }} = await supabase.auth.getSession(); // this returns always null
    
      if (req.nextUrl.pathname.startsWith("/dashboard")) {
        console.log(session);
      }
    }
    g
    c
    • 3
    • 13
  • I try to connect to SupaBase from Prisma Data Platform, but it fails
    k

    Kottalo Laurant

    01/18/2023, 6:02 PM
    Can somebody help me, please?
    g
    n
    • 3
    • 7
  • auto-create buckets in local development
    l

    logemann

    01/18/2023, 6:06 PM
    Hi, is there any way to auto-create buckets in local development similar to auto-create complete schemas and db data? This is of course crucial for any local development when it comes to using storage. Otherwise i would need to create them after every "supabase start" command which would be a non-starter of course. Thanks.
    g
    • 2
    • 13
  • Can't login to Supabase after converting GitHub account to organization
    y

    yekta

    01/18/2023, 6:24 PM
    After turning our GitHub account to an organization, can't login to Supabase anymore (naturally since that account is now gone). I tried "forgot my password" option but Supabase doesn't seem to be sending a password link to our registered email. What's the way to get around this and convert to email login?
    g
    • 2
    • 2
  • "invalid input syntax for type bigint" when trying to fetch an entry from DB by field id (uuid)
    d

    Dbugger

    01/18/2023, 6:55 PM
    This is the instruction I am using:
    adminclient.from('prompts').select().eq('id', id).single();
    And this the answer
    Copy code
    {
      "code": "22P02",
      "details": null,
      "hint": null,
      "message": "invalid input syntax for type bigint: \"9021b0c0-c1d7-4c45-9772-fdfe05b2f90e\""
    }
    The weirdest part is that it works on my local dev, but when deployed, it gives me the error, even though the base is clearly an "uuid"
    g
    • 2
    • 22
  • Transfer Project to different account
    g

    garyaustin

    01/18/2023, 7:18 PM
    https://supabase.com/docs/guides/platform/migrating-and-upgrading-projects
  • Seeding Auth in the local environment
    d

    Dbugger

    01/18/2023, 7:50 PM
    I am working on learning how to use the local environment and while a little confusing, I think I start getting an idea, but something is still escaping my grasp. How am I supposed to "seed" users, when I reset the DB? I have not found anything in the documentation addressing this issue.
    u
    n
    l
    • 4
    • 17
  • RLS policy that allows anyone to update a specific column?
    s

    Smardrengr

    01/18/2023, 9:11 PM
    I have a trigger function that updates
    games.players_conf
    when someone, anyone, joins a
    game
    . However, while I want only the game organizer to be able to update other details in the game record that he created, unless I allow all to update that column, the function is not allowed to run. Question: Can I write a policy that allows something like:
    Copy code
    create policy "Organizers can update their own games."
      on games for update
      using ( auth.uid() = organizer_id );
    
    CREATE POLICY games_players_update
        ON games
        FOR UPDATE
        TO public
        WITH CHECK (cols = '{players_conf}')
    u
    • 2
    • 5
  • Waiting for auth init before checking user?
    u

    56e5

    01/18/2023, 9:15 PM
    Hi, Is there a way to check whether auth is done initializing before checking falsyness of the user value? E.g.
    Copy code
    const user = useUser();
    
      useEffect(() => {
        if (!user) {
          // Redirect somewhere relevant
        }
      }, [user]);
    will always redirect on page load, because
    user
    seems to start out falsy while it's doing some checks and populating the value, even if the user turns out to be actually logged in in the end. I want to do something like:
    Copy code
    const user = useUser();
    
      useEffect(() => {
        if (user.isReady && !user) {
          // Redirect somewhere relevant
        }
      }, [user]);
    Does this exist? Maybe I can use
    session
    like this somehow? Thanks!
    g
    • 2
    • 6
  • Running tests against remote db instead of local
    c

    cayblood

    01/18/2023, 10:36 PM
    I'm setting up a github deployment for a project that uses supabase. I've noticed that even with caching enabled for docker images, the
    supabase start
    command still takes about 2m30s to run. It would be great to be able to speed up a deployment by using a remote supabase database that gets reset with each new deployment. Is there a way to tell
    supabase db test
    to run against a remote database?
    a
    • 2
    • 10
  • counter-intuitive invite link design
    d

    Deng

    01/18/2023, 11:29 PM
    The current design of invite links for Supabase immediately invalidates the link after first opening, which is counter-intuitive and confusing for users. It would improve the user experience to have a more intuitive design, such as allowing for multiple uses or providing an option to resend the invite link or having a time-limited design, such as expiring after one week.
  • "url argument is missing" - unable to create new users via both the Supabase UI and client library
    n

    nakulthebuilder

    01/18/2023, 11:47 PM
    I am using signup with email and password creds and using both the supabase UI (user invite) and the javascript library
    supabaseClient.auth.signUp({email, password})
    I am getting a 500 error
    url argument is missing
    . I am guessing this is related to the
    SITE_URL
    , which is currently set to a subdomain I am using for development, however I've tried a number of different ways and updated the redirect urls with wildcards and nothing seems to work. I have also tried restarting the Supabase server to no avail. Any guidance would be very much appreciated. Note: It's working fine when using my local supabase db.
    g
    m
    c
    • 4
    • 16
  • supabase db remote commit -> dont sync triggers in "auth" schema
    l

    logemann

    01/19/2023, 12:45 AM
    After syncing my remote DB state to a local migration, i find that the triggers responsible for auth tables were not synced. Is this by design?
    g
    • 2
    • 2
  • having issues with kubernetes helm chart-- getting fatal failure when attempting to clone repo...
    a

    ale.k

    01/19/2023, 1:22 AM
    Error I'm getting is as if credentials are needed/repo doesn't exist? (I know this is a community project... but thinking it might just be a repo/direction change since github.io is used by the documentation....?) Any help would be much appreciated!
    g
    • 2
    • 3
  • is there a way to .update() a JSONB field? i.e. .update(metadata-->share_status, true)?
    b

    Blobby

    01/19/2023, 2:37 AM
    is there a way to .update() a JSONB field? i.e. .update(metadata-->share_status, true)?
    g
    • 2
    • 1
  • RLS Error syntax near ;
    b

    bob_the_robot

    01/19/2023, 3:21 AM
    Not getting a great error message, hoping that someone can help shine some light on what's wrong with my query. When a user starts a game, the game's id gets set to their profile. I want them to be able to view all of the invites they have sent out to their game. I have this RLS policy I am trying to create and the UI says
    Error adding policy: failed to create pg.policies: syntax error at or near ";"
    Copy code
    sql
    CREATE POLICY "game creator can view invites" ON "public"."game_invites"
    AS PERMISSIVE FOR SELECT
    TO authenticated
    USING (( 1 <= ( SELECT COUNT(*) FROM game_invites WHERE game_id = ( SELECT current_game FROM profiles WHERE id = uid() ) ))
    I tried also
    select exists()
    but that gives me error
    Error adding policy: failed to create pg.policies: syntax error at or near "SELECT"
    Copy code
    sql
    SELECT EXISTS (
        SELECT 
          COUNT(*) 
        FROM 
          game_invites 
        WHERE 
          game_id = (
            SELECT 
              current_game 
            FROM 
              profiles 
            WHERE 
              id = uid()
          )
      )
    g
    • 2
    • 1
  • Edge Function invocations
    v

    VuNguyen

    01/19/2023, 3:53 AM
    Is this 500k Edge Function invocations per month or one time?
    g
    s
    • 3
    • 5
  • Possible to translate JS Client query to raw SQL?
    d

    drewbie

    01/19/2023, 4:05 AM
    is it possible to take a query, or a series of queries created via the JS client and see the outputted SQL? I am (and hopefully previously) using Edge Functions to create certain records that have associated records attached to them. Basically a chain of create 1, then create 2 with the id from 1 etc. Realizing that I'd much rather do this via .rpc and invoke a Postgres function instead of making an Edge Function do it. My trouble is basically translating the js queries into a Postgres function. The DX for me writing complex raw SQL is a PITA (for me at least) and wanted to see if there's anything I can leverage to make it easier. Appreciate any input!
    g
    • 2
    • 2
  • User meta data with Twitter OAuth?
    s

    Shelby

    01/19/2023, 4:48 AM
    Why does not this work?
    Copy code
    js
    const { data, error } = await supabaseClient.auth.signInWithOAuth({
          provider: 'twitter',
          options : {
            data : {
              credits: 1,
              used_credits: 0
            }
          }
    })
    g
    • 2
    • 2
  • Trying to get data auth.uid(). Please check my code. Where did I go wrong?
    c

    CherterB

    01/19/2023, 8:48 AM
    Hey guys. I make a screen shot of code that I'm trying to use. So basically it just returned data of user who is logged in. But I always get an empty string. Any insights? As a reminder, I'm still new to sql.
  • performance issue (?) with plv8 and RLS
    f

    flapili (FR, bad EN)

    01/19/2023, 8:56 AM
    Hi, I have an issue with plv8 and RLS
    • 1
    • 11
  • 502 error code while authenticating
    a

    Aissam

    01/19/2023, 9:09 AM
    Hi, Since yesterday I get a 502 error while authenticating. Do you know where this error can come from ? Kind regards,
    g
    • 2
    • 3
  • Edge function: GetStream ?? via npm or JS deliver or without?? How to??
    b

    boeledi

    01/19/2023, 9:10 AM
    I need to write a Supabase Edge Function that interacts with GetStream. But as Supabase Edge Functions are running via Deno, I am importing the package via JS Deliver as follows: import { StreamChat } from "https://cdn.jsdelivr.net/npm/stream-chat"; When I am serving the Edge Function locally, via the supabase functions serve test_chat --debug I get the following error: error: TS2305 [ERROR]: Module '"https://cdn.jsdelivr.net/npm/stream-chat.js"' has no exported member 'StreamChat'. revealing that it does not try to fetch "stream-chat" but "stream-chat .js", which does not exist. When I am importing via: import { StreamChat } from "https://cdn.jsdelivr.net/npm/stream-chat/dist/index.js"; I get the error: error: TS2305 [ERROR]: Module '"https://cdn.jsdelivr.net/npm/stream-chat.js"' has no exported member 'StreamChat'. When I am trying to import via: import { StreamChat} from "npm:stream-chat"; I get the error: error: Following npm specifiers were requested: "stream-chat"; but --no-npm is specified. Would anyone has any solution to this problem? Many thanks
  • How to use onConflict parameter in upsert function?
    l

    lyu

    01/19/2023, 9:13 AM
    How to use
    onConflict
    parameter in
    upsert
    function of supabase js library? This is my code and it doesn't work
    Copy code
    await supabase.from('users')
      .upsert(
        { id: 4, name: "Lorem ipsum" },
        {onConflict: 'id'}
      );
    g
    • 2
    • 1
  • Friend system
    e

    eggnog.

    01/19/2023, 9:17 AM
    hey guys, never built something like this before and never really used a database so I'm wondering what's the best structure for a friends system. I'm asking here because I am of course using supabase. obviously I'd want to be able to send and accept friend requests between users, show pending requests, cancel requests or remove friends and things like that. I've been trying to think and look online (haven't found something good for beginners online) about how to set this up. maybe have an array column in a user table that has outgoing requests and another for incoming requests and then another for actual friends? then I thought how can a user request to be friends with someone and then update that someone's row without actually being able to update it, unless I can only allow users to update specific columns because I also want to make sure it's decently secure as my first app. maybe this has to incorporate real-time I honestly have no clue what would be a decent way to implement this system and I'm hoping one of you may have a resource that explains a really good and popular method of implementing such a system. sorry if I'm not clear at all feel free to ask questions and I will elaborate what I mean. thanks in advance!
    h
    • 2
    • 4
  • Get all children
    k

    kabaday

    01/19/2023, 10:03 AM
    Hey, i have tables folder and note, both of them can have a parent_folderId. Note always has a parent folder, folders don't always have a parent folder. Now i want to get all folders witch are no child folders, and get all of their children (note, folder) in one new array called children. My code looks like this:
    Copy code
    javascript
    const { data: folders, error: err } = await locals.sb
        .from('folder')
        .select('*, children:note(*).folder(*)')
        .eq('owner', owner)
        .is('parent_folderId', null)
        .order('created_at', { ascending: true })
    With this i get all the child notes inside children, but not the folders. How can i also store all child folders inside children? The best case would be to also get all sub notes and folder recursively to get a folder structure like object:
    Copy code
    |- Folder 1
    |  |- note
    |  |- childFolder
    |  |  |- note
    |  |  |- ...
    |- Folder 2
    |...
    g
    k
    • 3
    • 9
  • Change Email Confirmation has no Effect, still old Address.
    c

    ccssmnn

    01/19/2023, 10:38 AM
    I use the method
    supabase.auth.updateUser({ email: data.email })
    to set a new email address for the user (email sign in). After confirming the change by pressing the link received via mail, the user still has the old email address. This problem occurs during development and in production. I must be missing something.
    g
    • 2
    • 12
1...101102103...230Latest