From 5ec8abdb591d513b7fca830bfe1db0aeaa7dc2e3 Mon Sep 17 00:00:00 2001 From: Baitinq Date: Tue, 4 Jun 2024 22:29:43 +0200 Subject: Misc: Move auth state to the app --- src/App.tsx | 9 ++++++++- src/pages/Login.tsx | 32 +++++++++++++------------------- 2 files changed, 21 insertions(+), 20 deletions(-) (limited to 'src') 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 ( <> - + ) } 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) }) -- cgit 1.4.1