cookie's now only used under /admin

This commit is contained in:
Thomas Ruoff
2024-09-11 23:44:31 +02:00
parent c671b622d5
commit af3262e55e
8 changed files with 77 additions and 61 deletions

View File

@@ -1,52 +1,16 @@
import { AxiomWebVitals } from 'next-axiom'
import { Analytics } from '@vercel/analytics/react';
import { useEffect } from 'react'
import type { AppProps } from 'next/app'
import { useSession, signIn, SessionProvider } from 'next-auth/react'
import Layout from '../components/layout';
import { Analytics } from '@vercel/analytics/react'
import Layout from '../components/layout'
import '../styles/index.css'
import '../styles/gfm.css'
function Auth({ children }) {
const { data: session, status } = useSession()
const isUser = !!session?.user
useEffect(() => {
if (status === 'loading') return // Do nothing while loading
if (!isUser) signIn() // If not authenticated, force log in
}, [isUser, status])
if (isUser) {
return children
}
// Session is being fetched, or no user.
// If no user, useEffect() will redirect.
return <div>Loading...</div>
}
export default function MyApp({
Component,
pageProps: { session, ...pageProps },
}) {
export default function MyApp({ Component, pageProps }) {
return (
<div className="flex flex-col min-h-screen">
<SessionProvider session={session}>
<Layout>
{Component.authenticationRequired ? (
<Auth>
<Component {...pageProps} />
</Auth>
) : (
<Component {...pageProps} />
)}
<Analytics />
</Layout>
</SessionProvider>
<AxiomWebVitals />
<Layout>
<Component {...pageProps} />
<Analytics />
</Layout>
</div>
)
}
}