mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-03 06:27:11 +01:00
@@ -2,6 +2,7 @@ import { useState } from 'react'
|
||||
import Head from 'next/head'
|
||||
import Link from 'next/link'
|
||||
import { useRouter } from 'next/router'
|
||||
import User from './user'
|
||||
|
||||
const NAV_ENTRIES = [
|
||||
{
|
||||
@@ -59,6 +60,7 @@ export default function Header() {
|
||||
</a>
|
||||
)
|
||||
})}
|
||||
<User />
|
||||
</nav>
|
||||
<nav
|
||||
onClick={() => setHamburgerOpen(!hamburgerOpen)}
|
||||
@@ -96,6 +98,7 @@ export default function Header() {
|
||||
</a>
|
||||
)
|
||||
})}
|
||||
<User />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { withAxiom } from 'next-axiom'
|
||||
import createMDX from '@next/mdx'
|
||||
|
||||
|
||||
/** @type {import('next').NextConfig} */
|
||||
const nextConfig = {
|
||||
swcMinify: true,
|
||||
@@ -9,15 +9,15 @@ const nextConfig = {
|
||||
// Optionally, add any other Next.js config below
|
||||
async redirects() {
|
||||
return [
|
||||
// {
|
||||
// source: '/admin',
|
||||
// destination: '/nope',
|
||||
// permanent: true,
|
||||
// },
|
||||
// {
|
||||
// source: '/admin',
|
||||
// destination: '/nope',
|
||||
// permanent: true,
|
||||
// },
|
||||
]
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
const withMDX = createMDX({
|
||||
// Add markdown plugins here, as desired
|
||||
options: {
|
||||
@@ -25,6 +25,6 @@ const withMDX = createMDX({
|
||||
rehypePlugins: [],
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
// Merge MDX config with Next.js config
|
||||
export default withMDX(nextConfig)
|
||||
export default withMDX(nextConfig)
|
||||
|
||||
@@ -4,24 +4,48 @@ import { useEffect } from 'react'
|
||||
|
||||
import type { AppProps } from 'next/app'
|
||||
|
||||
import { useSession, signIn, SessionProvider } from 'next-auth/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,
|
||||
pageProps: { session, ...pageProps },
|
||||
}) {
|
||||
// Use the layout defined at the page level, if available
|
||||
const getLayout = Component.getLayout ?? ((page) => page)
|
||||
|
||||
return (
|
||||
<div className="flex flex-col min-h-screen">
|
||||
<Layout>
|
||||
{ getLayout(<Component {...pageProps}/>) }
|
||||
<Analytics />
|
||||
</Layout>
|
||||
<SessionProvider session={session}>
|
||||
<Layout>
|
||||
{Component.authenticationRequired ? (
|
||||
<Auth>
|
||||
<Component {...pageProps} />
|
||||
</Auth>
|
||||
) : (
|
||||
<Component {...pageProps} />
|
||||
)}
|
||||
<Analytics />
|
||||
</Layout>
|
||||
</SessionProvider>
|
||||
<AxiomWebVitals />
|
||||
</div>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user