https://supabase.com/ logo
Join Discord
Powered by
# help-and-questions
  • Getting Error When Trying To Create Serializable Isolation
    c

    COLD1

    04/14/2023, 7:16 PM
    Copy code
    javascript
    
    require('dotenv').config({ path: __dirname + '/../../.env' });
    const { body, validationResult } = require('express-validator');
    const supabaseUrl = process.env.SUPABASE_URL;
    const supabaseKey = process.env.SUPABASE_ANON_KEY;
    const { createClient } = require('@supabase/supabase-js');
    const supabase = createClient(supabaseUrl, supabaseKey);
    // const csrf = require('csrf');
    const { v4: uuidv4 } = require('uuid');
    
    // POST /articles
    exports.createArticle = [
        // Use express-validator middleware for input validation
        body('author_id').isInt(),
        body('article_title').notEmpty(),
        body('summary').notEmpty(),
        body('content').notEmpty(),
      
        async (req, res, next) => {
          const client = await supabase.pool.connect(); // acquire a connection from the pool
          try {
            await client.query('BEGIN ISOLATION LEVEL SERIALIZABLE'); // begin a transaction with serializable isolation level
      
            const errors = validationResult(req);
            if (!errors.isEmpty()) {
              return res.status(400).json({ errors: errors.array() });
            }
      
            const { data: maxArticleId, error: maxArticleIdError } = await supabase
              .from('articles')
              .select('MAX(article_id) as max_article_id');
            if (maxArticleIdError) {
              await client.query('ROLLBACK'); // rollback the transaction if an error occurred
              return next(maxArticleIdError);
            }
      
            const nextArticleId = maxArticleId[0].max_article_id + 1;
      
            const { data: article, error } = await supabase
              .from('articles')
              .insert({
                article_id: nextArticleId,
                author_id: req.body.author_id,
                article_title: req.body.article_title,
                summary: req.body.summary,
                content: req.body.content,
              });
      
            if (error) {
              await client.query('ROLLBACK'); // rollback the transaction if an error occurred
              return next(error);
            }
      
            await client.query('COMMIT'); // commit the transaction if there were no errors
      
            res.json({ message: 'Article created successfully!' });
          } catch (error) {
            await client.query('ROLLBACK'); // rollback the transaction if an error occurred
            next(error);
          } finally {
            client.release(); // release the connection back to the pool
          }
        },
      ];
    g
    • 2
    • 10
  • Reset password event with email OTP
    u

    .Volxen

    04/14/2023, 7:18 PM
    can i in a way get the reset password event trigger when am trying to reset a users password through OTP?
    g
    • 2
    • 14
  • Using Supabase with postgres client and supabase.js: remaining connection slots are reserved
    g

    Gui BL

    04/14/2023, 7:27 PM
    Hello here! I have an application for which I do pretty intensive SQL. I alternate in using a postgres client and the supabase JS client to get my data and authication. I am working in a serverless environment (next.js server components) and after 1-2 hour of development I end up with this error:
    Copy code
    remaining connection slots are reserved for non-replication superuser connections
    I'm not a pro on connection pooling and such but I think this comes from me sending multiple requests and the connection pool becoming busy. If I restart the server in the dashboard all works fine but I would like tips on avoiding this issue in the future. How would I best setup my connection pool?
    g
    • 2
    • 2
  • Specifying id when creating new auth.users
    z

    zxkevinxz

    04/14/2023, 8:27 PM
    Hi, I was wondering if it is possible to give a specific uuid to be used for the id when creating a new user instead instead having it generate one? We are using Prisma and the Remix Auth Helpers. We want to be able to create a user profile in the db without an auth, then later on create an auth if needed with a matching id.
    g
    • 2
    • 3
  • Will the crates be published on crates.io that are used by the Edge runtime?
    j

    Jere

    04/14/2023, 9:00 PM
    I think it would be cool because you could use the runtime in other applications.
  • Create migration file for buckets & folders
    r

    riccardolardi

    04/14/2023, 9:22 PM
    Is it possible to create a supabase migration file to automate buckets & folders creation? I've tried by creating buckets using the dashboard and then diffing the DB / dumping the schema but it doesn't contain anything related to storage...
    g
    • 2
    • 1
  • Alternate Schema not showing up in API
    f

    Fisher

    04/14/2023, 9:57 PM
    Hey guys, I created an alternate schema for my web3 auth. I am trying to follow a very similar method to what NextAuth did, by creating 3 new tables in my schema, one is for users, one is for session token information, and one is wallet information. I create a JS client with my admin key and I have exposed that schema to the public end point. The functionality I am looking for is to be able to insert information to those tables when a user first connects their web3 wallet, which then keeps track of session tokens etc... it then takes that user information and by way of a trigger I have set up copies the user information into an RLS protected public 'users' table that users access with their signed jwt token. The problem I am having is trying to insert anything into this web3_auth schema. I cant seem to find it anywhere. Now it might just be a lack of knowledge on how to access it, but when I do a select function for ('sessions') it cant find anything. Is there a way to access that schema that I don't know about?
    g
    • 2
    • 3
  • Best practice for updating/deleting storage objects (from table and from bucket)
    k

    kylelovesyou

    04/14/2023, 10:19 PM
    I was going through the react native example (user management app) and at the very end there is a section describing how to create a database trigger to automatically remove the old avatar image from a bucket. Is it necessary to create database triggers whenever you are updating or deleting storage objects? This seems like a non-trivial amount of work at first pass. Any comments/insight on this would be much appreciated.
    g
    • 2
    • 41
  • Local instance has migration conflicts in storage schema
    n

    nlarusstone

    04/15/2023, 12:16 AM
    Running
    supabase db remote commit
    creates a migration file with the following commands in it:
    Copy code
    alter table "storage"."buckets" add column "allowed_mime_types" text[];
    
    alter table "storage"."buckets" add column "avif_autodetection" boolean default false;
    
    alter table "storage"."buckets" add column "file_size_limit" bigint;
    
    alter table "storage"."objects" add column "version" text;
    But when I start the server using
    supabase start
    I get the following error:
    Copy code
    Error: Migration failed. Reason: An error occurred running 'add-automatic-avif-detection-flag'. Rolled back this migration. No further migrations were run. Reason: column "avif_autodetection" of relation "buckets" already exists
    This happens even from a fresh start. If I remove those commands from the migration script, the DB can start, but the commands get added back in the next time i try to commit from remote
  • Next.js 13 and createServerComponentSupabaseClient and deploying to Netlify
    d

    dperolio

    04/15/2023, 12:24 AM
    When trying to deploy to Netlify and using Next.js 13
    app
    directory, I'm getting the following errors: > 8:22:11 PM: Error occurred prerendering page "/register". Read more: https://nextjs.org/docs/messages/prerender-error > 8:22:11 PM: Error: either NEXT_PUBLIC_SUPABASE_URL and NEXT_PUBLIC_SUPABASE_ANON_KEY env variables or supabaseUrl and supabaseKey are required! > 8:22:11 PM: at createServerComponentSupabaseClient (/opt/build/repo/.next/server/chunks/128.js:140:15) > 8:22:11 PM: at Home (/opt/build/repo/.next/server/app/register/page.js:478:120) > 8:22:11 PM: at S (/opt/build/repo/.next/server/chunks/722.js:17648:13) > 8:22:11 PM: at Ua (/opt/build/repo/.next/server/chunks/722.js:17745:21) > 8:22:11 PM: at Object.toJSON (/opt/build/repo/.next/server/chunks/722.js:17576:20) > 8:22:11 PM: at stringify () > 8:22:11 PM: at da (/opt/build/repo/.next/server/chunks/722.js:17135:9) > 8:22:11 PM: at bb (/opt/build/repo/.next/server/chunks/722.js:17841:30) > 8:22:11 PM: at Timeout._onTimeout (/opt/build/repo/.next/server/chunks/722.js:17698:16) > 8:22:11 PM: at listOnTimeout (node:internal/timers:559:17) > 8:22:11 PM: info - Generating static pages (3/7) > 8:22:11 PM: Error occurred prerendering page "/login". Read more: https://nextjs.org/docs/messages/prerender-error > 8:22:11 PM: Error: either NEXT_PUBLIC_SUPABASE_URL and NEXT_PUBLIC_SUPABASE_ANON_KEY env variables or supabaseUrl and supabaseKey are required! > 8:22:11 PM: at createServerComponentSupabaseClient (/opt/build/repo/.next/server/chunks/128.js:140:15) > 8:22:11 PM: at Home (/opt/build/repo/.next/server/app/login/page.js:498:120) > 8:22:11 PM: at S (/opt/build/repo/.next/server/chunks/722.js:17648:13) > 8:22:11 PM: at Ua (/opt/build/repo/.next/server/chunks/722.js:17745:21) > 8:22:11 PM: at Object.toJSON (/opt/build/repo/.next/server/chunks/722.js:17576:20) > 8:22:11 PM: at stringify () > 8:22:11 PM: at da (/opt/build/repo/.next/server/chunks/722.js:17135:9) > 8:22:11 PM: at bb (/opt/build/repo/.next/server/chunks/722.js:17841:30) > 8:22:11 PM: at Timeout._onTimeout (/opt/build/repo/.next/server/chunks/722.js:17698:16) > 8:22:11 PM: at listOnTimeout (node:internal/timers:559:17) > 8:22:11 PM: info - Generating static pages (5/7) > 8:22:11 PM: info - Generating static pages (7/7) > 8:22:11 PM: > Export encountered errors on following paths: > 8:22:11 PM: /api/test/route: /api/test > 8:22:11 PM: /login/page: /login > 8:22:11 PM: /page: / > 8:22:11 PM: /register/page: /register > 8:22:12 PM: ​ > 8:22:12 PM: "build.command" failed
  • add raw_user_mets_data for invited users
    n

    naveeng2402

    04/15/2023, 1:29 AM
    Is there any way to add raw user meta data for users invited via supabase studio using postgres triggers
    g
    • 2
    • 2
  • Sveltekit "permission denied for schema public error" on insert
    y

    ykisana

    04/15/2023, 1:57 AM
    I implemented Supabase into my Sveltekit applicaition following this tutorial: https://supabase.com/docs/guides/auth/auth-helpers/sveltekit Auth works as expected. But am running into an issue doing stuff on my server. As per the tutorial I have this defined in my hooks.server.ts:
    Copy code
    event.locals.supabase = createSupabaseServerClient({
            supabaseUrl: PUBLIC_SUPABASE_URL,
            supabaseKey: PUBLIC_SUPABASE_ANON_KEY,
            event
        });
    I have a POST request defined as follow
    POST: RequestHandler = async ({ request, locals: { supabase, getSession } })
    This is in a
    +server.ts
    file in a route. First I wanted to protect the API, so I did this, as per the docs:
    Copy code
    const session = await getSession();
            if (!session) {
                // the user is not signed in
                throw new Error('Unauthorized');
            }
    This seems to work, I don't see the error. But then I try doing this:
    Copy code
    const { error } = await supabase
                .from('messages')
                .insert({ message: message) });
    And get the following error:
    Copy code
    error: {
        code: '42501',
        details: null,
        hint: null,
        message: 'permission denied for schema public'
      }
    I've tried with my Secret Key as-well, so updating it to
    supabaseKey: PUBLIC_SUPABASE_SECRET_KEY
    in
    hooks.server.ts
    . And the same error occurs. I've confirmed that the .env vars are correct. And these should be the same as on the client, and auth works so no issue there.
    g
    • 2
    • 16
  • supabase functions error on serve
    l

    leovigildo

    04/15/2023, 2:27 AM
    supabase functions serve hello-world Error: Error response from daemon: create supabase\functions\import_map.json: "supabase\\functions\\import_map.json" includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed. If you intended to pass a host directory, use absolute path Try rerunning the command with --debug to troubleshoot the error. i am using docker 4.18.0 in windows 11
    g
    • 2
    • 2
  • NEXT_PUBLIC_SUPABASE_URL and NEXT_PUBLIC_SUPABASE_ANON_KEY required
    d

    dperolio

    04/15/2023, 3:13 AM
    I am using Next.js 13 and I am getting this error when using the context provider and middleware from the docs:
    Copy code
    ts
    import { createMiddlewareSupabaseClient } from '@supabase/auth-helpers-nextjs';
    import { NextResponse } from 'next/server';
    
    import type { NextRequest } from 'next/server';
    
    export async function middleware (req: NextRequest) {
      const res = NextResponse.next();
      const supabase = createMiddlewareSupabaseClient({ req, res });
      await supabase.auth.getSession();
      return res;
    }
    In particular, it's saying
    createMiddlewareSupabaseClient
    needs it.
  • What's the threshold for using database functions?
    k

    kylelovesyou

    04/15/2023, 3:39 AM
    When should I start to think... this should be a database function and not be done through the supabase client on the frontend? If I need to see if a user's age is above 21 before creating a record I could (1) make call client-side using supabase client to see if user is above 21 and then create the record- 2 calls with supabase client- or (2) call a database function and have the function handle this logic. How big of a difference would it be- between 1 and 2 in terms of performance?
    n
    • 2
    • 6
  • update only one column with upsert([])
    h

    Hartaithan

    04/15/2023, 3:44 AM
    Here's my table: create table public.games ( id bigint generated by default as identity not null, created_at timestamp with time zone not null default now(), updated_at timestamp with time zone null, ordered_at timestamp with time zone null, title text not null, image_url text not null, platform text not null, status text not null, progress jsonb null, user_id uuid not null, code text not null, order bigint not null default '0'::bigint, constraint games_pkey primary key (id), constraint games_user_id_fkey foreign key (user_id) references auth.users (id) on delete cascade ) tablespace pg_default; And I need to update the order column on several rows in one query. I do it like this: const list = [ { id: 7, order: 1 }, { id: 8, order: 2 }, { id: 6, order: 3 }, { id: 4, order: 4 }, { id: 3, order: 5 } ] supabase.from("games").upsert(list).select("*") But I get an error message: 'null value in column "title" of relation "games" violates not-null constraint' It's like it can't find the row with the id and tries to insert. What am I doing wrong? And is upsert the right way to achieve my goal?
    g
    • 2
    • 13
  • SQL Editor is not loading
    p

    proro485

    04/15/2023, 3:55 AM
    Well I'm trying to open the SQL Editor page and everything is loading except the editor. I have included some images for reference.

    https://cdn.discordapp.com/attachments/1096645062114422895/1096645062399623278/Screenshot_from_2023-04-15_09-24-45.png▾

    https://cdn.discordapp.com/attachments/1096645062114422895/1096645062680657990/Screenshot_from_2023-04-15_09-25-12.png▾

  • Cascade deletes for storage objects?
    w

    Wizzel

    04/15/2023, 8:15 AM
    The latest updates allow us to setup cascade deletes from the UI which is super helpful. However I was wondering if this can be done with storage objects as well. Specifically I want to delete objects when a user gets deleted. I see that objects have an "owner_id" but the storage schema is protected.
    g
    • 2
    • 2
  • Compress data
    m

    MDobs

    04/15/2023, 8:41 AM
    Hello I'm trying to compress data before they get saved on the database, but it seems that pg_compress is not available, is there another extension to use?
    g
    • 2
    • 1
  • Javascript RPC Typescript error: Argument of type 'string' is not assignable to parameter of type 'n
    h

    hichana

    04/15/2023, 9:03 AM
    In the Javascript documentation an example is given for using rpc to call custom functions: https://supabase.com/docs/reference/javascript/using-filters
    const { data, error } = await supabase.rpc('hello_world')
    In typescript, the following error is thrown:
    Argument of type 'string' is not assignable to parameter of type 'never'.ts(2345)
    To mitigate the error I had to add a custom typescript definition for the supabase client:
    Copy code
    // supabaseCustom.d.ts
    
    import { PostgrestBuilder } from '@supabase/postgrest-js';
    import { SupabaseClient } from '@supabase/supabase-js';
    
    declare module '@supabase/supabase-js' {
      interface SupabaseClient {
        rpc<ResponseType, ParamsType>(
          fn: string,
          params?: ParamsType
        ): PostgrestBuilder<ResponseType>;
      }
    }
    I think I'll add an issue to the javascript repo, but placing it here in case it helps anyone else.
  • Not receiving sign in event
    w

    ws

    04/15/2023, 9:35 AM
    Hi, I've set up onAuthStateChange on my Swift App, but it doesn't fire when a sign in happens (via provider Apple): I receive login-callback url and I execute
    Copy code
    let session = try await supabase.auth.session(from: url)
    but no auth event fired. It worked yesterday, maybe supabase outage ?
    • 1
    • 1
  • my cronjob says it's running, but it has stopped doing anything
    a

    AlleyCat

    04/15/2023, 12:31 PM
    I have a cronjob that was running for weeks no problem. I haven't touched that code since. Today i noticed I wasn't getting any data into the app when I sat down to work on it and it has just randomly stopped pulling data but i still see it running when i call
    SELECT * FROM cron.job

    https://cdn.discordapp.com/attachments/1096774848916762737/1096774966814441563/image.png▾

    g
    • 2
    • 45
  • in deno edge functions, can I import _module1 in _module2 ?
    m

    marc

    04/15/2023, 1:14 PM
    Hey 🖐️ I try to import my
    /functions/_core/dbtypes.ts
    file into
    /functions/_api/supabase.ts
    but I don't understand how the files are loaded, I use the import map with
    Copy code
    {
      "imports": {
        "/": "./",
        "./": "./"
      }
    }
    if you can help me to understand how to have code shared globally between all folders _ or how to set up a global runtime to define some code before all execution tanks for your time ❤️

    https://cdn.discordapp.com/attachments/1096785593175908515/1096785593448529990/Capture_decran_2023-04-15_a_15.11.32.png▾

    https://cdn.discordapp.com/attachments/1096785593175908515/1096785593758920796/Capture_decran_2023-04-15_a_15.13.54.png▾

    • 1
    • 1
  • bulk loading example with node /js
    k

    khairulhaaziq

    04/15/2023, 1:27 PM
    hi I am building an app that requires inserting a huge number of rows for each user in close to every few miliseconds. (it is kind of a game and those are the logs). never done something like it. I saw I need to use the copy function and sql but I am not really familiar with it. it inserts to multiple tables and one depends the other. I wonder if anyone can help show some examples and best practices. thanks!
  • Resumable upload giving a 404 error with Uppy
    s

    salzar

    04/15/2023, 1:49 PM
    Im getting this error when using the resumable end point with uppy, how can i fix this? is it just not rolled out full yet?
    Copy code
    unexpected response while creating upload, originated from request (method: POST, url: https://wmsccjgcrykictvgimtt.supabase.co/storage/v1/upload/resumable, response code: 404, response text: {"message":"Route POST:/upload/resumable not found","error":"Not Found","statusCode":404}, request id: n/
    g
    • 2
    • 3
  • Storage API - Doesn't Return UUID
    a

    altechzilla

    04/15/2023, 4:19 PM
    Hi, I'm trying to build an admin dashboard that uses the Supabase REST API to upload and retrieve objects from storage. When I upload an object, it only returns the key (aka bucket and file name), not the object UUID. Therefore, I cannot assign that newly uploaded file with a table row. The table row is using a column called "avatar" which has a relation to storage objects, so it needs the UUID. How can I have it retrieve the UUID on upload OR do a GET request to storage that returns ID? Every attempt so far only returns the file name, format, and data. Thank you!
    g
    • 2
    • 20
  • Rls in Next Api Routes
    a

    Arinji

    04/15/2023, 4:30 PM
    Heya so i have this weird problem where normal queries go through with a next js api route..however whenever i add even a basic rls policy like requirement of authentication.. it fails. I can see the active session as well I am using the supabase create client with the public and anon key btw
    n
    • 2
    • 5
  • Realtime confusing docs
    s

    shnoman

    04/15/2023, 4:49 PM
    Trying to make a chat App with superbase in a flutter. When I use the stream in a flutter, I am getting the data, but the issue is it only fetches the first 1k messages; how to get others as there is no range method for stream. I have 5k messages in the database. Don't know to paginate with the stream. In the docs, there are other stream methods as well that we should use. In docs, it's written to subscribe to the channel; what is a channel? How can I get only the last message rather than a list of messages, which I am getting now with the following method.
    Copy code
    supaClient
          .from('messages')
          .stream(primaryKey: ['id'])
          .order('createdAt')
    g
    a
    • 3
    • 19
  • Getting user with Auth UI returns error
    t

    TimurKramar

    04/15/2023, 5:08 PM
    I am using Auth UI and when I try to retrieve a user with
    getUser()
    I get a weird error: ```"AuthApiError: invalid claim: missing sub claim at eval (webpack-internal:///(app-client)/./node_modules/@supabase/gotrue-js/dist/module/lib/fetch.js:49:20)"```I inspected the logs for the API Edge network, and it receives a GET request at path
    /auth/v1/user
    , and the logs for auth show request at path
    /user
    with the error missing sub claim.
    g
    • 2
    • 7
  • How to select first X characters from JSON property?
    c

    Canman

    04/15/2023, 5:21 PM
    I'm sure this is possible, but I can't figure out the syntax. I want to do something like this: select LEFT(foo ->>'source' , 3) from t; How would I do this using Supabase client syntax?
    g
    • 2
    • 1
1...180181182...230Latest