https://supabase.com/ logo
Join Discord
Powered by
# javascript
  • s

    Scott P

    07/30/2021, 3:12 PM
    Firstly, are you receiving any of the logs? Is there a specific reason you're using the realtime-js lib over the supabase-js lib? For example, this
    update
    example I use in a prod environment without a problem:
    Copy code
    js
    SupabaseClient.from(`my_table:my_column=eq.some_value`)
      .on("UPDATE", (payload) => {
        console.log("🔥 Received update via subscription from Supabase");
      })
      .subscribe(result => {
        if (result !== "SUBSCRIBED") {
          console.log(`❌ Error subscribing: ${result}.`);
        } else {
          console.log(`🔥 Opened subscription`);
        }
      });
    h
    • 2
    • 2
  • s

    Scott P

    07/30/2021, 3:06 PM
    Realtime subscriptions
  • s

    stibbs

    07/31/2021, 1:29 AM
    Just curious, is anyone in production with supabase + sveltekit?
  • o

    Olyno

    07/31/2021, 2:12 AM
    Honestly, I'm not going to use sveltekit for now because it's still in beta
  • s

    stibbs

    07/31/2021, 2:34 AM
    It's so much less code than react which is very appealing lol
  • k

    Khan W

    07/31/2021, 4:37 AM
    Is it possible to just return the row count from a query, without fetching all the records?
  • k

    Khan W

    07/31/2021, 4:37 AM
    EG I need to count all messages whose content contains a string, and is between two dates. Do I need to use an RPC for that?
  • k

    Khan W

    07/31/2021, 4:38 AM
    Nevermind found it in the docs
  • h

    hieu

    07/31/2021, 7:49 AM
    https://supabase.io/docs/postgrest/client/select. Use head option on select
  • k

    Khan W

    07/31/2021, 8:24 AM
    Thanks 🙏
  • k

    Khan W

    07/31/2021, 3:06 PM
    I'm trying to call an RPC from JS like this:
    Copy code
    javascript
    supabase
      .rpc("getEmptyStats", {
        guild: guild,
        startDates: startDates,
        endDates: endDates,
        dateCount: startDates.length,
      })
      .then((data, error) => {
        console.log(data);
        console.log(error);
      });
    The RPC returns an array of ints for some stats queries, however I'm having troubles calling the function and getting this error:
    Copy code
    bash
    {
      error: {
        hint: 'No function matches the given name and argument types. You might need to add explicit type casts.',
        details: null,
        code: '42883',
        message: 'function public.getEmptyStats(dateCount => text, endDates => text, guild => text, startDates => text) does not exist'
      },
      data: null,
      count: null,
      status: 404,
      statusText: 'Not Found',
      body: null
    }
    Is there a way to typecast this in JS? Or do I need to do it in SQL.
    s
    k
    b
    • 4
    • 19
  • k

    Khan W

    07/31/2021, 3:07 PM
    Also the
    startDates
    and
    endDates
    variables are arrays, but look like they're being interpreted as strings when passed to the RPC function, can I pass arrays to the function? Or do I need to send a CSV string and parse it in SQL or something like that
  • k

    Khan W

    07/31/2021, 3:07 PM
    The RPC is defined like this:
    Copy code
    sql
    FUNCTION public.getEmptyStats(guild int8, startDates timestamp[], endDates timestamp[], dateCount int)
  • a

    amserra

    07/31/2021, 8:58 PM
    Hey guys! If you could check out and provide your input would be great! https://www.reddit.com/r/sveltejs/comments/ov4yc3/questions_on_sveltekit_and_supabase/
  • u

    user

    08/01/2021, 9:17 AM
    Hello, I was looking for learning supabase lately, and downloaded the react todo list and I have a question about a line in the code App.js
    Copy code
    js
        useEffect(() => {
            const session = supabase.auth.session();
            setUser(session?.user ?? null);
    
            const { data: authListener } = supabase.auth.onAuthStateChange(
                async (event, session) => {
                    const currentUser = session?.user;
                    setUser(currentUser ?? null);
                }
            );
    
            return () => {
                authListener?.unsubscribe();
            };
        }, [user]);
    so what does
    ??
    mean in
    setUser(session?.user ?? null)
  • u

    unrealg

    08/01/2021, 9:21 AM
    its called nullish coallessing
  • a

    Azura

    08/01/2021, 9:21 AM
    I will replace
    session?.user
    with
    user
    to make it simple for you.
    user ?? null
    , is equivalent to:
    Copy code
    js
    if (user == null){
    return null;
    // Which is redundant because user is already null
    // Recommended: return 'user' instead
    } else {
    return user;
    }
    The code above doesn't make much sense because it was used wrongly. It should generally be used like this in an example:
    total_likes ?? 0
    , which can be translated to:
    Copy code
    js
    if (total_likes == null){
    return 0;
    } else {
    return total_likes;
    }
  • u

    unrealg

    08/01/2021, 9:21 AM
    ^^
  • u

    user

    08/01/2021, 9:23 AM
    aha so
    user ??
    =
    if (user == null)
    and
    null
    after
    ??
    is to return null if user is equal to null ?
  • a

    Azura

    08/01/2021, 9:23 AM
    Sorry, I updated my answer to clarify the issue.
  • u

    user

    08/01/2021, 9:24 AM
    yeah I saw it, thanks! thanks for letting me know cause I think I'll be using
    ??
    a lot
  • a

    Azura

    08/01/2021, 9:25 AM
    It's short-hand for a common use case, so it's perfectly fine to use it instead of the traditional way 😁
  • t

    Trey

    08/02/2021, 9:14 PM
    Hey everyone. I'm stumbling my way through learning vuex with supabase, and struggling to figure out how to log a user out. I was told I would need some type of clear_state for my store, but I'm not sure how that works. So far I've tried
    Copy code
    javascript
      logUserOut() {
          supabase.auth.signOut();
          this.$router.push("/");
        },
  • t

    Trey

    08/02/2021, 9:14 PM
    This is my current store:
    Copy code
    javascript
     state: {
        userInformation: null,
        loggingIn: false,
      },
      mutations: {
        login(state, payload) {
          state.userInformation = payload;
        },
        attemptLogin(state) {
          state.loggingIn = true;
        },
        finishAttemptLogin(state) {
          state.loggingIn = false;
        },
        session(state) {
          state.session = true;
        },
      },
    So I'm guessing something like
    Copy code
    javascript
     CLEAR_STATE(state) {
          state.session = false;
        },
    ?
  • t

    Trey

    08/02/2021, 9:15 PM
    Any help would be appreciated. Thanks!
  • s

    Sucipto

    08/03/2021, 12:04 AM
    Have you try with store action:
    Copy code
    js
    state:{...},
    mutations:{...},
    actions: {
      async logout({ commit }) {
        const { error } = await supabase.auth.signOut();
        if (!error) {
          commit('clear_user') // clear user/session information
    
          // import from router
          router.replace('/')
        }
      }
    }
  • s

    Skolder

    08/03/2021, 4:04 AM
    as a general rule, in vuex, everything that is a simple state change and is sync you use a mutation, for more complex things, like updating several parts of your store or doing any async work, you use actions
  • u

    user

    08/03/2021, 11:17 AM
    Does the js libs work with deno and typescript?
  • u

    user

    08/03/2021, 11:19 AM
    Haha found it sorry 😄
  • u

    user

    08/03/2021, 11:27 AM
    Wait no this is not what i was searching for
1...567...81Latest