diff --git a/client/src/App.tsx b/client/src/App.tsx index 4f12c92..49fa303 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -1,15 +1,20 @@ import { BrowserRouter, Route, Routes } from 'react-router-dom' import Home from './components/Home/Home' import Register from './components/User/Register' +import { SupabaseProvider, useSupabase } from './supabase/SupabaseContext' +import { getSupabaseClient } from './supabase/getSupabaseClient' import './App.css' -import { useEffect, useState } from 'react' -import { createClient, SupabaseClient } from '@supabase/supabase-js' -import { SupabaseProvider } from './supabase/SupabaseContext' -import { useSupabase } from './supabase/useSupabase' +import { useEffect } from 'react' function App() { + const supabase = useSupabase(); + + useEffect(() => { + console.log(supabase); + }, [supabase]) + return ( - +
diff --git a/client/src/components/User/Register.tsx b/client/src/components/User/Register.tsx index 816e6e9..0e0f94c 100644 --- a/client/src/components/User/Register.tsx +++ b/client/src/components/User/Register.tsx @@ -1,4 +1,5 @@ import { useState } from "react"; +import { useSupabase } from "../../supabase/SupabaseContext"; interface FormInput { email: string @@ -6,6 +7,7 @@ interface FormInput { } export default function Register() { + const supabase = useSupabase(); const [input, setInput] = useState({email: "", password: ""}); // const { handleRegister, authData } = useSupabase(); @@ -15,6 +17,10 @@ export default function Register() { // if (email && password) handleRegister!(email, password, authData); } + const handleSupabase = () => { + if (supabase) console.log(supabase); + } + return (

Register

@@ -31,6 +37,7 @@ export default function Register() { +
) } \ No newline at end of file diff --git a/client/src/supabase/SupabaseContext.tsx b/client/src/supabase/SupabaseContext.tsx index b4373e2..6053de0 100644 --- a/client/src/supabase/SupabaseContext.tsx +++ b/client/src/supabase/SupabaseContext.tsx @@ -1,13 +1,18 @@ -import { createContext, FC, ReactNode } from "react"; +import { createContext, FC, ReactNode, useContext } from "react"; import { SupabaseClient } from "@supabase/supabase-js"; -import { useSupabase } from "./useSupabase"; +import { getSupabaseClient } from "./getSupabaseClient"; -const SupabaseContext = createContext(undefined!); +const SupabaseContext = createContext(getSupabaseClient()); export const SupabaseProvider: FC<{children: ReactNode, value: SupabaseClient}> = ({ children }) => { return ( - + {children} ) +} + +export const useSupabase = () => { + const context = useContext(SupabaseContext); + return context || "Context currently undefined"; } \ No newline at end of file diff --git a/client/src/supabase/useSupabase.tsx b/client/src/supabase/getSupabaseClient.tsx similarity index 78% rename from client/src/supabase/useSupabase.tsx rename to client/src/supabase/getSupabaseClient.tsx index f2b8809..ab4d54f 100644 --- a/client/src/supabase/useSupabase.tsx +++ b/client/src/supabase/getSupabaseClient.tsx @@ -1,5 +1,5 @@ import { createClient } from "@supabase/supabase-js"; -export const useSupabase = () => { +export const getSupabaseClient = () => { return createClient(import.meta.env.VITE_SUPABASE_URL, import.meta.env.VITE_SUPABASE_KEY); } \ No newline at end of file