diff --git a/components/auth.tsx b/components/auth.tsx
new file mode 100644
index 0000000..7c8355b
--- /dev/null
+++ b/components/auth.tsx
@@ -0,0 +1,21 @@
+import { useEffect } from 'react'
+
+import { useSession, signIn } from 'next-auth/react'
+
+export default 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
Loading...
+}
diff --git a/components/header.tsx b/components/header.tsx
index 99990fa..8fe97f1 100644
--- a/components/header.tsx
+++ b/components/header.tsx
@@ -1,4 +1,5 @@
import { useState } from 'react'
+import { createPortal } from 'react-dom'
import Head from 'next/head'
import Link from 'next/link'
import { useRouter } from 'next/router'
@@ -43,7 +44,10 @@ export default function Header() {
-
+
Pfadi-Bussle
@@ -60,7 +64,6 @@ export default function Header() {
)
})}
-
setHamburgerOpen(!hamburgerOpen)}
@@ -81,8 +84,9 @@ export default function Header() {
/>
@@ -98,7 +102,6 @@ export default function Header() {
)
})}
-
@@ -108,4 +111,4 @@ export default function Header() {
>
)
-}
\ No newline at end of file
+}
diff --git a/components/user.tsx b/components/user.tsx
index 16aa416..4630532 100644
--- a/components/user.tsx
+++ b/components/user.tsx
@@ -24,4 +24,4 @@ export default function User() {
>
)
-}
\ No newline at end of file
+}
diff --git a/helpers/withAuth.tsx b/helpers/withAuth.tsx
new file mode 100644
index 0000000..4a79e5e
--- /dev/null
+++ b/helpers/withAuth.tsx
@@ -0,0 +1,25 @@
+import { SessionProvider } from 'next-auth/react'
+import Auth from '../components/auth'
+import User from '../components/user'
+
+// This is the HOC
+function withAuth(WrappedComponent) {
+ // Return a new component
+ function withAuth({ session, ...pageProps }) {
+ // Render the WrappedComponent with additional props
+ return (
+
+
+
+
+
+
+ )
+ }
+
+ withAuth.displayName = `withAuth(${WrappedComponent.displayName}`
+
+ return withAuth
+}
+
+export default withAuth
diff --git a/pages/_app.tsx b/pages/_app.tsx
index fa0491a..360dadc 100644
--- a/pages/_app.tsx
+++ b/pages/_app.tsx
@@ -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
Loading...
-}
-
-export default function MyApp({
- Component,
- pageProps: { session, ...pageProps },
-}) {
+export default function MyApp({ Component, pageProps }) {
return (
-
-
- {Component.authenticationRequired ? (
-
-
-
- ) : (
-
- )}
-
-
-
-
+
+
+
+
)
-}
\ No newline at end of file
+}
diff --git a/pages/admin/bookings/[uuid]/bill.tsx b/pages/admin/bookings/[uuid]/bill.tsx
index 669f545..0b917cb 100644
--- a/pages/admin/bookings/[uuid]/bill.tsx
+++ b/pages/admin/bookings/[uuid]/bill.tsx
@@ -9,6 +9,7 @@ import { log } from '../../../../helpers/log'
import { getBillTotal, createBill, patchBill } from '../../../../helpers/bill'
import { getBookingStatus } from '../../../../helpers/booking'
import { getServerSideBooking } from '../../../../lib/getServerSideProps'
+import withAuth from '../../../../helpers/withAuth'
export const getServerSideProps = async (context) => {
const milageMax = await getMilageMax()
@@ -114,14 +115,14 @@ function BookingBillPage({
setStoringInProgress(false)
}
- const onAddAdditionalCost = function(
+ const onAddAdditionalCost = function (
event: React.MouseEvent
) {
event.preventDefault()
setAdditionalCosts([...additionalCosts, { name: '', value: 0 }])
}
- const onRemoveAdditionalCost = function(
+ const onRemoveAdditionalCost = function (
event: React.MouseEvent,
index: number
) {
@@ -197,8 +198,9 @@ function BookingBillPage({
>
-
- {`Kostenpunkt ${index + 1
- }`}
+ {`Kostenpunkt ${
+ index + 1
+ }`}