it never says "received new message" even when the...
# help
m
it never says "received new message" even when there's been an update to the messages
n
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
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
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
I don't know what you are referring to
m
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
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
i dont have any sign in though
these policies will work with the code i have now?
i dont need to adjust anything?
g
Anon should work.
m
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
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
@garyaustin why is my supabase object null?
or at least why could it be null?
@garyaustin sorry i meant undefined
do you know?
g
You don't show any code setting it up with clientClient, so I could not guess.
m
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
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
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
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
but that does not explain why it would be null?
g
It is not null there is it?
m
no
g
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