mirror of
https://github.com/supabase/supabase.git
synced 2026-12-06 08:29:01 +00:00
## I have read the [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) file. YES
39 lines
905 B
TypeScript
39 lines
905 B
TypeScript
import { SupabaseProvider, useSupabaseClient } from '@/lib/supabase-context'
|
|
import type { AppProps } from 'next/app'
|
|
import { useRouter } from 'next/router'
|
|
import { useEffect } from 'react'
|
|
import '../styles/globals.css'
|
|
|
|
function MyAppInner({ Component, pageProps }: AppProps) {
|
|
const router = useRouter()
|
|
const supabase = useSupabaseClient()
|
|
|
|
useEffect(() => {
|
|
const {
|
|
data: { subscription },
|
|
} = supabase.auth.onAuthStateChange((event) => {
|
|
switch (event) {
|
|
case 'SIGNED_IN':
|
|
router.push('/')
|
|
return
|
|
case 'SIGNED_OUT':
|
|
router.push('/login')
|
|
return
|
|
}
|
|
})
|
|
return subscription.unsubscribe
|
|
}, [supabase, router])
|
|
|
|
return <Component {...pageProps} />
|
|
}
|
|
|
|
function MyApp(props: AppProps) {
|
|
return (
|
|
<SupabaseProvider>
|
|
<MyAppInner {...props} />
|
|
</SupabaseProvider>
|
|
)
|
|
}
|
|
|
|
export default MyApp
|