disable admin login

This commit is contained in:
Thomas Ruoff
2024-03-13 23:48:05 +01:00
parent 0486b99b3e
commit eb15f4b29c
3 changed files with 17 additions and 35 deletions

View File

@@ -2,7 +2,6 @@ import { useState } from 'react'
import Head from 'next/head' import Head from 'next/head'
import Link from 'next/link' import Link from 'next/link'
import { useRouter } from 'next/router' import { useRouter } from 'next/router'
import User from './user'
const NAV_ENTRIES = [ const NAV_ENTRIES = [
{ {
@@ -60,7 +59,6 @@ export default function Header() {
</a> </a>
) )
})} })}
<User />
</nav> </nav>
<nav <nav
onClick={() => setHamburgerOpen(!hamburgerOpen)} onClick={() => setHamburgerOpen(!hamburgerOpen)}
@@ -98,7 +96,6 @@ export default function Header() {
</a> </a>
) )
})} })}
<User />
</div> </div>
</div> </div>
</div> </div>

View File

@@ -7,6 +7,15 @@ const nextConfig = {
// Configure `pageExtensions`` to include MDX files // Configure `pageExtensions`` to include MDX files
pageExtensions: ['js', 'jsx', 'mdx', 'ts', 'tsx'], pageExtensions: ['js', 'jsx', 'mdx', 'ts', 'tsx'],
// Optionally, add any other Next.js config below // Optionally, add any other Next.js config below
async redirects() {
return [
{
source: '/admin',
destination: '/nope',
permanent: true,
},
]
},
} }
const withMDX = createMDX({ const withMDX = createMDX({

View File

@@ -4,48 +4,24 @@ import { useEffect } from 'react'
import type { AppProps } from 'next/app' import type { AppProps } from 'next/app'
import { useSession, signIn, SessionProvider } from 'next-auth/react'
import Layout from '../components/layout'; import Layout from '../components/layout';
import '../styles/index.css' import '../styles/index.css'
import '../styles/gfm.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({ export default function MyApp({
Component, Component,
pageProps: { session, ...pageProps }, pageProps,
}) { }) {
// Use the layout defined at the page level, if available
const getLayout = Component.getLayout ?? ((page) => page)
return ( return (
<div className="flex flex-col min-h-screen"> <div className="flex flex-col min-h-screen">
<SessionProvider session={session}>
<Layout> <Layout>
{Component.authenticationRequired ? ( { getLayout(<Component {...pageProps}/>) }
<Auth>
<Component {...pageProps} />
</Auth>
) : (
<Component {...pageProps} />
)}
<Analytics /> <Analytics />
</Layout> </Layout>
</SessionProvider>
<AxiomWebVitals /> <AxiomWebVitals />
</div> </div>
) )