https://supabase.com/ logo
#help
Title
# help
m

mudkip

06/15/2022, 6:18 PM
it never says "received new message" even when there's been an update to the messages
n

Needle

06/15/2022, 6:18 PM
Hello @mudkip! This thread has been automatically created from your message in #843999948717555735 a few seconds ago. We have already mentioned the @User so that they can see your message and help you as soon as possible! Want to unsubscribe from this thread? Right-click the thread in Discord (or use the ``...`` menu) and select "Leave Thread" to unsubscribe from future updates. Want to change the title? Use the ``/title`` command! We have solved your problem? Click the button below to archive it.
g

garyaustin

06/15/2022, 6:26 PM
Have you setup up database replication for the table by turning on operation switches and clicking on table then selecting the table? Do you have RLS on the table?
m

mudkip

06/15/2022, 6:27 PM
i dont have rls and no how do i turn on replication?
oh they are all turned on
but is it normal that it shows 0 tables when i have one?
wait i turned it on for the table
@garyaustin is it the strict mode that's causing it to write into my database twice?
how do i prevent it
g

garyaustin

06/15/2022, 6:31 PM
I don't know what you are referring to
m

mudkip

06/15/2022, 6:32 PM
you know how strict mode causes it to run it twice
like in the index.js file
and also if i want to turn on RLS how will it affect the realtime? @garyaustin
g

garyaustin

06/15/2022, 6:36 PM
Is strict mode something to do with React? If you are getting two console.log for each insert/update then for some reason you have two subscriptions. With RLS on, you have to have a user signed in by the point you subscribe and that user has to meat select RLS policy on that table.
m

mudkip

06/15/2022, 6:36 PM
i dont have any sign in though
these policies will work with the code i have now?
i dont need to adjust anything?
g

garyaustin

06/15/2022, 6:37 PM
Anon should work.
m

mudkip

06/15/2022, 6:37 PM
ok good
for some reason whenever i send a message the amount of messages it sends duplicates each time
example:
wait
it sends like 12 messages
g

garyaustin

06/15/2022, 6:43 PM
Put some console.logs in and see what code might be running multiple times. Look at your network tab and see if you have more than websocket and look in that to see if you get just one event message from the server.
m

mudkip

06/15/2022, 8:52 PM
@garyaustin why is my supabase object null?
or at least why could it be null?
@garyaustin sorry i meant undefined
do you know?
g

garyaustin

06/15/2022, 9:06 PM
You don't show any code setting it up with clientClient, so I could not guess.
m

mudkip

06/15/2022, 9:11 PM
app.js
Copy code
js
import { AppContextProvider, useAppContext } from "./context/appContext";
import Chat from './components/Chat.js'
import Login from './components/Login.js'
import './App.css';

function App() {
    const { supabase, user } = useAppContext()

    return (
        <AppContextProvider>
            <div className="grid h-screen place-items-center">
                {supabase ? <Chat/> : <Login/>}
            </div>
        </AppContextProvider>
    );
}

export default App;
appContext.js
Copy code
js
import { createContext, useContext, useState, useEffect } from "react";
import { createClient } from "@supabase/supabase-js";

const AppContext = createContext({});

const AppContextProvider = ({ children }) => {
    const supabaseUrl = process.env.REACT_APP_SUPABASE_URL
    const supabaseAnonKey = process.env.REACT_APP_SUPABASE_ANON_KEY
    const supabase = createClient(supabaseUrl, supabaseAnonKey)
there @garyaustin
wait i think i might know
ok nvm
i dont know
g

garyaustin

06/15/2022, 9:14 PM
console.log supabase right after you set it up and see what you get, if you can. I've not used react in awhile.
m

mudkip

06/15/2022, 9:14 PM
in the appcontextprovider?
whoaaaaa
it's like spamming it infinitely
in the console
1000 messages
ig that's bc it renders it often
and does it instantiate every time you render the app?
g

garyaustin

06/15/2022, 9:17 PM
Why init the code over and over? If that is the case move it I guess. You should look at some react examples or ask a new question just on that, as I really don't know enough about react particulars anymore.
m

mudkip

06/15/2022, 9:18 PM
but that does not explain why it would be null?
g

garyaustin

06/15/2022, 9:18 PM
It is not null there is it?
m

mudkip

06/15/2022, 9:18 PM
no
g

garyaustin

06/15/2022, 9:19 PM
Some react thing and contextprovider code issue you likely have.
https://supabase.com/docs/guides/with-react this is the way I normally see it done as an export/import