about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorBaitinq <manuelpalenzuelamerino@gmail.com>2024-06-04 22:29:43 +0200
committerBaitinq <manuelpalenzuelamerino@gmail.com>2024-06-04 22:29:43 +0200
commit5ec8abdb591d513b7fca830bfe1db0aeaa7dc2e3 (patch)
tree6e7ceb6e9a9e79048857c66bd2ad2d385e2b9b33 /src
parentLogin: Setup basic auth (diff)
downloadfs-tracer-frontend-5ec8abdb591d513b7fca830bfe1db0aeaa7dc2e3.tar.gz
fs-tracer-frontend-5ec8abdb591d513b7fca830bfe1db0aeaa7dc2e3.tar.bz2
fs-tracer-frontend-5ec8abdb591d513b7fca830bfe1db0aeaa7dc2e3.zip
Misc: Move auth state to the app
Diffstat (limited to 'src')
-rw-r--r--src/App.tsx9
-rw-r--r--src/pages/Login.tsx32
2 files changed, 21 insertions, 20 deletions
diff --git a/src/App.tsx b/src/App.tsx
index a65251d..47d2c6b 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -1,10 +1,17 @@
+import { useState } from 'react'
+
+import { createClient } from '@supabase/supabase-js'
+
 import './App.css'
 import Login from './pages/Login'
 
+const supabase = createClient('https://slpoocycjgqsuoedhkbn.supabase.co', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InNscG9vY3ljamdxc3VvZWRoa2JuIiwicm9sZSI6ImFub24iLCJpYXQiOjE3MTUyMDU0MjUsImV4cCI6MjAzMDc4MTQyNX0.xZYRTRN65rlms1Hb96IBAQvw3EGtMzUxlGPP5TVey34')
+
 function App() {
+  const [session, setSession] = useState(null)
   return (
     <>
-      <Login />
+      <Login supabase={supabase} session={session} setSession={setSession} />
     </>
   )
 }
diff --git a/src/pages/Login.tsx b/src/pages/Login.tsx
index b152b19..d3555cc 100644
--- a/src/pages/Login.tsx
+++ b/src/pages/Login.tsx
@@ -1,30 +1,24 @@
-import { createClient } from '@supabase/supabase-js'
-import { useState, useEffect } from 'react'
-
-const supabase = createClient('https://slpoocycjgqsuoedhkbn.supabase.co', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InNscG9vY3ljamdxc3VvZWRoa2JuIiwicm9sZSI6ImFub24iLCJpYXQiOjE3MTUyMDU0MjUsImV4cCI6MjAzMDc4MTQyNX0.xZYRTRN65rlms1Hb96IBAQvw3EGtMzUxlGPP5TVey34')
-
-window.HandleSignInWithGoogle = async (response: any) => {
-  console.log(response)
-  const { data, error } = await supabase.auth.signInWithIdToken({
-    provider: 'google',
-    token: response.credential,
-  })
-  console.log(data, error)
-}
+import { useEffect } from 'react'
 
-export default function Login() {
-  const [_, setSession] = useState(null)
+export default function Login(props: any) {
 
   useEffect(() => {
-    supabase.auth.getSession().then(({ data: { session } }) => {
-      setSession(session)
+    window.HandleSignInWithGoogle = async (response: any) => {
+      await props.supabase.auth.signInWithIdToken({
+        provider: 'google',
+        token: response.credential,
+      })
+    }
+
+    props.supabase.auth.getSession().then(({ data: { session } }) => {
+      props.setSession(session)
       console.log("LOGIN SESSION", session)
     })
 
     const {
       data: { subscription },
-    } = supabase.auth.onAuthStateChange((_event, session) => {
-      setSession(session)
+    } = props.supabase.auth.onAuthStateChange((_event, session) => {
+      props.setSession(session)
       console.log("SESSION CHANGE", session)
     })