|
const [session, setSession] = useState(null); |
|
|
|
useEffect(() => { |
|
setSession(supabase.auth.session()); |
|
supabase.auth.onAuthStateChange((_event, session) => { |
|
setSession(session); |
|
}); |
|
}, []); |
You've got this identical bit of code for handling Supabase auth sessions in quite a few pages. Since it's likely that every page needs to know if you're logged in or not, you could put this into pages/_app.js. This components sits "above" all other pages, so any code in here will run for every page. You could then pass the session down as a prop to the pages:
// pages/_app.js
function MyApp({ Component, pageProps }) {
const [session, setSession] = useState(null);
useEffect(() => {
setSession(supabase.auth.session());
supabase.auth.onAuthStateChange((_event, session) => {
setSession(session);
});
}, []);
return (
<Layout>
<Component {...pageProps} session={session} />
</Layout>
);
}
FACTube/pages/myvideos.js
Lines 7 to 14 in 78d06ea
You've got this identical bit of code for handling Supabase auth sessions in quite a few pages. Since it's likely that every page needs to know if you're logged in or not, you could put this into
pages/_app.js. This components sits "above" all other pages, so any code in here will run for every page. You could then pass thesessiondown as a prop to the pages: