https://supabase.com/ logo
Join Discord
Powered by
# help-and-questions
  • Getting user's details
    m

    MaGnezij

    03/24/2023, 1:23 PM
    Is there an endpoint that allows me to get user's data only with the access token?
    j
    • 2
    • 1
  • Expose Admin Panel to users inside app?
    r

    Ruben

    03/24/2023, 2:47 PM
    Hey I'm sure all of you have run into this moment where your building an internal app and just need to build a tone of CRUD pages. Would love for these to be near zero effort auto generated from a GraphQL schema. Functionally similar to AdminJS or Django-Admin. Oh wait we have one already in Supabase but it uses the superuser to make data changes. Has anyone tried to take the Supabase admin panel and integrate it into the end user app ?
  • Server side auth with remix
    r

    raoxnei

    03/24/2023, 2:52 PM
    Hi, I have been a bit confused. watching the video about Supabase authentication with Remix helpers (

    https://www.youtube.com/watch?v=Viaed7XWCY8&t=1s▾

    ) was clear. but technically, after writing my code, it didn't make too much sense. If I want to signup, login, update user,.. all of these operations are mentioned need to be client side by the video, since supabase need to create the browser cookie, however, in real life, you can't just update/create a user, or change a user, without server side validation, therefor, you would want to signup/.update a user on the server, through an action, and then call the supbase server client after the data is valid, but then, the client side .onauthstatechanged() method will not be aware of any changes, and the client does not know about it. In other words, If I want to signin/signup/update, etc.. on the server, because I need to add server side validation, how do I proceed from there? after the opearation is successful, the client side is not up to date with the server.
  • Collaborating with other users in my organisation
    a

    Alexander24

    03/24/2023, 3:00 PM
    Hi I can't see the setting to be able to invite my developers to collaborate with me on supabase, we cannot see the option in the project settings Thanks
    g
    • 2
    • 1
  • supabase grafana not working
    j

    JoshTheNerd

    03/24/2023, 3:02 PM
    https://github.com/supabase/grafana-agent-fly-example is this still working>
    e
    • 2
    • 7
  • Partition Table
    m

    Morpheus

    03/24/2023, 3:10 PM
    Hi! I am planning to migrate my app from Firebase to Supabse. And I have a big concern: I have one BIG table and would like to use RANGE PARTITIONING. https://www.postgresql.org/docs/current/ddl-partitioning.html What is your advice? I looked for the extension pg_partman but did not find it in Supabase. I already know that to use pg_partman it is necessary: pg_jobmon https://github.com/omniti-labs/pg_jobmon dblink https://www.postgresql.org/docs/current/dblink.html How can I install the pg_partman extension in my project? If it is not possible, what are the alternatives to automate the partition table creation? Just for reference Amazon RDS implemented pg_partman. https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/PostgreSQL_Partitions.html Thanks in advance for the feedback!
  • key-array pairs with relation
    n

    Netail

    03/24/2023, 3:26 PM
    Hi, I was wondering what the best solution to would be to save a key-array with foreign keys. Projects are currently saved like this, with team being a jsonb
    Copy code
    json
    [
      {
        "id": 1,
        "name": "Awesome project",
        "team": {
          "lead": [1],
          "frontend": [2, 3],
          "backend": [4]
        }
      }
    ]
    This is because it is a key-array type, with the key being dynamic.
    Copy code
    json
    {
      "<role>: <user id>[]
    }
    Members are currently saved in a different table as such:
    Copy code
    json
    [
      {
        "id": 1,
        "email": "user1@gmail.com",
      },
      {
        "id": 2,
        "email": "user2@gmail.com",
      },
      {
        "id": 3,
        "email": "user3@gmail.com",
      },
      {
        "id": 4,
        "email": "user4@gmail.com",
      }
    ]
    The next would be to fetch each user object with the id given in the role array, resulting in:
    Copy code
    json
    [
      {
        "id": 1,
        "name": "Awesome project",
        "team": {
          "lead": [
            {
              "id": 1,
              "email": "user1@gmail.com",
            },
          ],
          "frontend": [
            {
              "id": 2,
              "email": "user2@gmail.com",
            },
            {
              "id": 3,
              "email": "user3@gmail.com",
            },
          ],
          "backend": [
            {
              "id": 4,
              "email": "user4@gmail.com",
            }
          ]
        }
      }
    ]
    For now I thought of fetching the project object first and the looping through each array and fetching the corresponding user object. But I feel like there would be an easier way, e.g. through a query
  • Postgres changes filter with more than one condition?
    i

    imagio

    03/24/2023, 3:30 PM
    It's unclear from the docs and reading the realtime-js source if it's possible to specify more than one condition for a postgres changes realtime filter. It's easy to specify a single condition such
    my_column=eq.foo
    but the docs and code lack any example of how you might have a realtime filter condition such as
    my_column=eq.foo AND other_column=lte.30
    . Relevant code is here https://github.com/supabase/realtime-js/blob/master/src/RealtimeChannel.ts and here https://github.com/supabase/realtime/blob/a4f740004508164745470063f62453a5610bd677/lib/extensions/postgres_cdc_rls/repo/migrations/20211116213934_create_realtime_is_visible_through_filters_function.ex#L8 The postgresql functions seem to suggest that multiple conditions are possible but the JS code is pretty unclear. Can anybody point me toward how to assign multiple conditions to a postgres changes listener filter?
    g
    • 2
    • 11
  • Presigned Upload URLs in supabase-js
    c

    ccssmnn

    03/24/2023, 3:58 PM
    Storage-API v0.30 introduced the ability to request signed upload URLs. There is no issue with this feature in storage-js and also no issue yet. Is this work in progress, or should I file an issue?
  • Single device login per user
    e

    eloahsam

    03/24/2023, 4:08 PM
    Is it possible to limit the number of logged in devices for a single account at the same time ?
    g
    • 2
    • 1
  • Swift: Type of expression is ambiguous without more context
    w

    Wil | The🐐.eth

    03/24/2023, 4:13 PM
    I have spent more time than I would like to admit on this bug. Any help would be appreciated. I am trying to fetchUserdata from my database and display the username on a page. The error is in the fetchUserData function on the HomeViewModel.swift file Specifically the error is on this line
    Copy code
    guard let userId = supabase.auth.user()?.id as? String else {
    Copy code
    import Foundation
    import SwiftUI
    import Combine
    import Supabase
    
    class HomeViewModel: ObservableObject {
        @Published var username: String = ""
        private var cancellables = Set<AnyCancellable>()
        private let userDataAccess: UserDataAccess
        private let supabase = SupabaseClient(supabaseURL: URL(string: Config.supabaseURL)!, supabaseKey: Config.supabaseKey)
    
        init() {
            userDataAccess = UserDataAccess(supabase: supabase)
            fetchUserData()
        }
    
        private func fetchUserData() {
            guard let userId = supabase.auth.user()?.id as? String else {
                return
            }
    
            userDataAccess.retrieveUserData(user_id: userId) { [weak self] result in
                DispatchQueue.main.async {
                    switch result {
                    case .success(let userData):
                        self?.username = userData.display_name
                    case .failure(let error):
                        print("Failed to fetch user data: \(error)")
                    }
                }
            }
        }
    }
    Here is the UserDataAccess file the HomeViewModel is referencing.
    Copy code
    import Supabase
    import Foundation
    
    class UserDataAccess {
        private let supabase: SupabaseClient
    
        init(supabase: SupabaseClient) {
            self.supabase = supabase
        }
        
        func retrieveUserData(user_id: String, completion: @escaping (Result<UserData, Error>) -> Void) {
            let query = supabase.database
                .from("user_data")
                .select(columns: "*")
                .filter(column: "user_id", operator: .eq, value: user_id)
                .single()
    
            Task {
                do {
                    let response: UserData = try await query.execute().value
                    completion(.success(response))
                } catch {
                    completion(.failure(error))
                }
            }
        }
    
    
    
        func insertUserData(userData: UserData, completion: @escaping (Result<UserData, Error>) -> Void) {
            do {
                let encoder = JSONEncoder()
                let jsonData = try encoder.encode(userData)
                if let jsonObject = try JSONSerialization.jsonObject(with: jsonData) as? [String: Any] {
                    let encodableObject = jsonObject.mapValues { AnyEncodable($0) }
                    let query = supabase.database
                        .from("user_data")
                        .insert(values: encodableObject, returning: .representation)
                        .single()
    
                    Task {
                        do {
                            let response: UserData = try await query.execute().value
                            completion(.success(response))
                        } catch {
                            completion(.failure(error))
                        }
                    }
                } else {
                    completion(.failure(NSError(domain: "InsertUserDataError", code: -1, userInfo: [NSLocalizedDescriptionKey: "Failed to convert userData to JSON"])))
                }
            } catch {
                completion(.failure(error))
            }
        }
    }
    And the UserData.swift file
    Copy code
    import Foundation
    
    struct UserData: Codable {
        let user_id: String
        let display_name: String
        let age: Int
        let gender: String
        let height: Double?
        let weight: Double?
        let fitness_goal: String
    
        enum CodingKeys: String, CodingKey {
            case user_id = "user_id"
            case display_name = "display_name"
            case age = "age"
            case gender = "gender"
            case height = "height"
            case weight = "weight"
            case fitness_goal = "fitness_goal"
        }
    }
    Any help would greatly appreciated. Thank you very much.
  • Discord Auth
    k

    Kenbak

    04/13/2023, 3:03 PM
    Hello guys, I'm using the Discord auth and it's working pretty well. I would like to know if it's possible to change the redirect/callback URL that supabase provides. And how to proceed? Currently I collect emails in the database, but would like to have only usernames and guilds. Thanks so much
  • Is it possible to connect with postgresql?
    l

    LoSantos_YT👑

    04/13/2023, 3:13 PM
    Is there any way to connect supaBase to a postgres database??? In this case from an Odoo ERP.
    g
    n
    • 3
    • 26
  • Safari login issue
    g

    gurps

    04/13/2023, 3:48 PM
    Hey, I'v added Auth to my NextJS using Supabase. Works fine on all browsers expect Safari, the
    useSessionContext
    doesn't seem to refresh when the user logs in. I tried it on other browsers and saw the session hydrating, but it doesn't on Safari. I am using MacBook Pro M1 2021 14 Inch and Safari version 16.3, this also happens on mobile Safari as well.
    n
    • 2
    • 19
  • Failed to toggle RLS: failed to update pg.tables with the given ID: must be owner of event trigger p
    d

    DonQ

    04/13/2023, 4:03 PM
    i get this error. also i cant ALTER tables from the SQL Editor which gives me : Failed to run sql query: schema "pgtle" does not exist. Any idea? i am on the free tier #pgtle
    g
    g
    • 3
    • 13
  • best practice for rate limit logging
    j

    jar

    04/13/2023, 4:04 PM
    Id like to track db actions such as adding a row to an action_log table each time a user updates a table and give a weight and then i can query the logs by user and time created to see if user has performed more actions than I allow. but that may be computationally expensive to call prior to each request. I am performing most actions in rpc functions so planned to just make necessary checks and updates in those. Also if say i get many users is it possible these tables arent performant for mass logs because I know supabase announced something about some new service for logs which im not sure if indicates standard tables arent good for this. I could also maintain a weight_used column for the user that i update each call and just store the sum_total. Im not sure what best practice is or best way to approach rate limits. Thanks!
    n
    • 2
    • 8
  • Dev/Prod Environment?
    k

    kevlust

    04/13/2023, 4:07 PM
    While I'm developing my app, it's ok for me to mess around with my database tables, functions, etc because nobody is using it yet. But when I start getting users, things will be more delicate: I won't be able to change the structure of my tables without it affecting all users and potentially causing bad bugs in production. How should I go about this? How can I test changes to my Supabase project without having them affect all users immediately? Is there such thing as a dev environment on Supabase that I can use to experiment, and only "deploy" my changes on prod when I've verified that it's safe to do so for all users? If not, what are some good practices, or what does Supabase recommend we do?
    s
    • 2
    • 1
  • Update not updating D:
    s

    supafloh

    04/13/2023, 5:33 PM
    I am doing an update on a row, but the row doesn't change at all.
    Copy code
    js
                const { data: updateData, error: updateError } = await supabase
                  .from("profiles")
                  .update({
                    provider_token: refreshData.access_token,
                    provider_refresh_token: refreshData.refreshToken,
                    provider_token_expires_at: new Date(refreshData.newAccess.expires_in + now).toISOString(),
                  })
                  .eq("id", user.id)
                  .select("*");
                if (updateError) {
                  console.log(updateError);
                  return;
                }
                console.log(updateData);
    I'm sure the values being passed in are different as I am printing them right before running the query There are no errors in logs from what I can see What are some steps I can take to debug this?
    g
    • 2
    • 10
  • how to get rid of TS warnings
    c

    christer

    04/13/2023, 6:04 PM
    I've solved this twice before, but I cant seem to remember how I can get rid of these?

    https://cdn.discordapp.com/attachments/1096133946187710545/1096133946414207147/Screenshot_2023-04-13_at_20.03.04.png▾

    u
    n
    • 3
    • 9
  • Trying to update a row in profiles table.
    h

    H1GHG2M3R

    04/13/2023, 7:18 PM
    I have a nextjs app that uses the discord provider as the main method of logging in. after a successful login the user is sent to a linking page where they can link their account with steam. Apparently there is no steam auth provider in supabase so i chose to use passport steam for that. I have imported a supabase client in to my passport-steam login strat:
    import { supabase } from "./supabaseClient";
    retrieving the session:
    const { data: sessionData, error: sessionErr } = await supabase.auth.getSession();
    and then updating the users row like this:
    Copy code
    const { data, error } = await supabase
            .from("profiles")
            .update({ steam_id: profile.id })
            .eq('id', sessionData.session?.user.id)
    I am getting a error: invalid input syntax for type uuid: "undefined". which makes me think that maybe the "getSession" method is not working? but even if i just use my own uuid as a string instead of sessionData.session?.user.id for testing i still get a error" duplicate key value violates unique constraint "profiles_pkey" " as it already exists. Cant figure out what am i doing wrong
  • 502 Bad Gateway - Newbie
    g

    GlennMarcus

    04/13/2023, 10:00 PM
    Hello. Total supabase newbie here. Got stuck on my first edge function. I followed the
    hello-world
    example from https://supabase.com/docs/guides/functions/quickstart After substituting my project-ref and ANON_KEY the curl command is showing a
    502 Bad Gateway
    . I can see the errors on the supabase dashboard, so I can confirm calls are making it out to the network.
    • 1
    • 1
  • Will my plan automatically switch to Pro if limits are hit?
    u

    1voy

    04/13/2023, 10:00 PM
    Is there a project that can allow my project to pay for the $25 plan if it exceeds free plan limits? Is there at least an alarm I can set?
    g
    • 2
    • 2
  • Need help supabase-auth-ui doesnt seem to be loading the css
    m

    Midas

    04/13/2023, 10:59 PM
    Like the title says i tried using the supabase auth ui but the css doesnt seem to load. I followed this guide https://supabase.com/docs/guides/auth/auth-helpers/auth-ui Am I missing any inport or cdn link.
    Copy code
    jsx
    import { supabaseClient } from "../utils/supabaseClient";
    import { Navigate } from "react-router-dom";
    import React, { useState, useEffect } from "react";
    import { Auth } from "@supabase/auth-ui-react";
    import { ThemeSupa } from "@supabase/auth-ui-shared";
    
    function Login() {
      const [logged, setLogged] = useState(false);
      const [loading, setLoading] = useState(true);
    
      useEffect(() => {
        async function fetchData() {
          const result = await supabaseClient.auth.getSession();
          if (result.data.session !== null) setLogged(true);
          console.log(result);
          setLoading(false);
        }
    
        fetchData();
      }, []);
    
      return <>{loading ? <div>Loading...</div> : logged ? <Navigate to="/logged" /> : <Auth supabaseClient={supabaseClient} theme={{ ThemeSupa }} providers={["google"]} />}</>;
    }
    export default Login;

    https://cdn.discordapp.com/attachments/1096208151310770247/1096208151591796848/image.png▾

    o
    • 2
    • 4
  • ERROR: relation "public.profile" doesn't exist
    l

    Lorenium

    04/13/2023, 11:35 PM
    I'm trying to use triggers to keep my public.profile table in sync with my auth.users table but I can't sign a new user up cause of this error. I enabled pgAudit and the log says:
    PL/pgSQL function public.handle_update_user() line 3 at SQL statement
    here are my triggers/functions:
    Copy code
    postgres
    CREATE OR REPLACE FUNCTION public.handle_new_user()
    RETURNS TRIGGER AS $$
    BEGIN
      INSERT INTO public.profile (id, email, username)
      VALUES (NEW.id, NEW.email, NEW.raw_user_meta_data->>'username');
      RETURN NEW;
    END;
    $$ LANGUAGE plpgsql SECURITY DEFINER;
    
    DROP TRIGGER IF EXISTS on_auth_user_created ON auth.users;
    CREATE TRIGGER on_auth_user_created
    AFTER INSERT ON auth.users
    FOR EACH ROW EXECUTE PROCEDURE public.handle_new_user();
    
    
    -- Function and trigger to update user
    CREATE OR REPLACE FUNCTION public.handle_update_user() RETURNS TRIGGER AS $$
    BEGIN
      UPDATE public.profie
      SET email = NEW.email, username = NEW.username, updated_at = NEW.updated_at
      WHERE id = NEW.id;
      RETURN NEW;
    END;
    $$ LANGUAGE plpgsql SECURITY definer;
    
    DROP TRIGGER IF EXISTS on_auth_user_updated ON auth.users;
    CREATE TRIGGER on_auth_user_updated AFTER UPDATE ON auth.users
    FOR EACH ROW EXECUTE FUNCTION public.handle_update_user();
    
    -- Function and trigger to delete user
    CREATE OR REPLACE FUNCTION public.handle_delete_user() RETURNS TRIGGER AS $$
    BEGIN
      DELETE FROM public.profile
      WHERE id = OLD.id;
      RETURN OLD;
    END;
    $$ LANGUAGE plpgsql SECURITY definer;
    
    DROP TRIGGER IF EXISTS on_auth_user_deleted ON auth.users;
    CREATE TRIGGER on_auth_user_deleted AFTER DELETE ON auth.users
    FOR EACH ROW EXECUTE FUNCTION public.handle_delete_user();
    What am I doing wrong? Also why was
    handle_update_user
    triggered even though I'm inserting into the table?

    https://cdn.discordapp.com/attachments/1096217125904994424/1096217126055972904/image.png▾

  • getting an error while uploading to supabase bucket
    l

    landfight

    04/13/2023, 11:50 PM
    ERROR  Error uploading image to bucket: {"error": "", "message": "new row violates row-level security policy for table \"objects\"", "statusCode": "403"}
    here is the code with expo image picker and im trying to use this with an authenticated user
    Copy code
    const pickImage = async () => {
        // Pick an image
        const result = await ImagePicker.launchImageLibraryAsync({
          mediaTypes: ImagePicker.MediaTypeOptions.Images,
          allowsEditing: true,
          aspect: [4, 3],
          quality: 1,
        });
    
        // Get user ID and file extension
        const { data, error } = await supabase.auth.getSession();
        const user = data?.session?.user;
        const userId = user?.id;
        const fileExtension = result.assets[0].uri.split(".").pop();
    
        // Create unique file name and get image blob
        const fileName = `profile_picture_${userId}.${fileExtension}`;
        const response = await fetch(result.assets[0].uri);
        const fileBlob = await response.blob();
    
        // Upload image to bucket
        if (!result.canceled) {
          setProfileImage(result.assets[0].uri);
          const { data, error } = await supabase.storage
            .from("profile_pictures")
            .upload(fileName, fileBlob, {
              cacheControl: "3600",
              upsert: true,
            });
          if (error) {
            console.error("Error uploading image to bucket:", error);
          }
        }
      };
    i used the default templates for the bucket policies

    https://cdn.discordapp.com/attachments/1096220910589067395/1096220911281131550/CleanShot_2023-04-13_at_19.49.57.png▾

    g
    m
    • 3
    • 20
  • How can I create own database name ?
    p

    pusha007

    04/13/2023, 11:54 PM
    How can I create own database name ? in settings stays always postgre. Its for multi tenant.
    Copy code
    const pool = new Pool({
        host: 'xxxo',
        user: 'xxx',
        database: db_name ?? 'postgres',
        password: 'xxx',
        ssl: { rejectUnauthorized: false },
        port: 22163,
        max: 20,
        idleTimeoutMillis: 30000,
        connectionTimeoutMillis: 10000,
      });
    
      return pool;
    }
    
    export var connectors = {
      'defaultdb': construct_pool('defaultdb'),
      'tenant_db1': construct_pool('tenant_db1'),
      'tenant_db2': construct_pool('tenant_db2')
    }
    • 1
    • 1
  • The new apple sign in launch documentation? Does it support Expo?
    v

    Vik

    04/14/2023, 12:19 AM
    Supabase announced native Sign in with Apple support for mobile applications but didn’t share how to implement it. Does anyone know if this is supported in Expo/React Native? They only mentioned Flutter.
    g
    u
    +4
    • 7
    • 13
  • How to get all posts of friends
    d

    DwarfNinja

    04/14/2023, 12:36 AM
    If I have a database like this, how can I get all the posts of my friends? Eg. You have 5 users. I'm user 1 and befriended with user 2 and 4 but not with user 3 and 5. I want all the posts made by user 2 and 4. How can I achieve this?
    Copy code
    Auth.Users Table {
      id PK        
      email
      //etc. etc. Supabase Auth 
    }
    
    Public.Friends table {
      id PK
      created_at
      user FK Auth.Users.Id
      friend FK Auth.Users.Id
    }
    
    Public.Timeline table {
      id PK
      created_at
      user FK Auth.Users.Id
      message 
    }
  • Auth in local development
    j

    Josiah

    04/14/2023, 12:56 AM
    I'm completely new to supabase and was hoping to use it for my next project. For my project I want to auth using phone numbers. I see that there's this doc https://supabase.com/docs/guides/auth/phone-login/twilio for integrating twillio. When I try to do this using the supabase instance created using supabase start I don't see settings option under Authentication. From what I can see in the docs, local development has some limitations when compared to the deployed instance. I was wondering if this is one of those limitations. Would it make sense to self-host supabase? Ideally I would like to develop my project locally before deploying to the remote instance.
  • can i use supabase cloud with an existing postgresql database
    d

    donga

    04/14/2023, 1:52 AM
    hi guys, im new to supabase and trying to understand if i do this
    g
    • 2
    • 1
1...178179180...230Latest