-
-
-
- Last updated {new Date(booking.updatedAt).toLocaleString()}
-
-
-
-
-
-
-
- Buchungszeitraum
-
- -
- {daysFormatFrontend(booking.days)}
-
-
-
-
- Bucher
- -
- {booking.name}
-
-
-
-
- Email
- -
- {booking.email}
-
-
-
-
- Status
- -
- {booking.status}
-
-
-
-
+
+ {bookings.map((booking: any) => (
+
+
+
+
+ Last updated {new Date(booking.updatedAt).toLocaleString()}
+
- ))}
-
-
- >
+
+
+
+
-
+ Buchungszeitraum
+
+ -
+ {daysFormatFrontend(booking.days)}
+
+
+
+
- Bucher
+ -
+ {booking.name}
+
+
+
+
- Email
+ -
+ {booking.email}
+
+
+
+
- Status
+ -
+ {booking.status}
+
+
+
+
+
+ ))}
+
)
}
+
+AdminRecentBookings.auth = true
diff --git a/pages/api/auth/[...nextauth].ts b/pages/api/auth/[...nextauth].ts
new file mode 100644
index 0000000..11620be
--- /dev/null
+++ b/pages/api/auth/[...nextauth].ts
@@ -0,0 +1,23 @@
+import NextAuth from "next-auth"
+import GithubProvider from "next-auth/providers/github"
+import EmailProvider from "next-auth/providers/email"
+
+export default NextAuth({
+ providers: [
+ EmailProvider({
+ server: {
+ host: "smtp.sendgrid.net",
+ port: 587,
+ auth: {
+ user: "apikey",
+ pass: process.env.SENDGRID_API_KEY,
+ },
+ },
+ from: process.env.FROM_EMAIL
+ }),
+ GithubProvider({
+ clientId: process.env.GITHUB_ID,
+ clientSecret: process.env.GITHUB_SECRET,
+ }),
+ ],
+})
diff --git a/pages/api/login.ts b/pages/api/login.ts
deleted file mode 100644
index f04c59e..0000000
--- a/pages/api/login.ts
+++ /dev/null
@@ -1,27 +0,0 @@
-import { authenticateAdmin } from '../../lib/authenticate'
-import withSession from '../../lib/session'
-
-async function loginHandler(req: any, res: any): Promise
{
- const { method } = req
-
- switch (method) {
- case 'POST':
- const { username, password } = req.body
-
- if (!authenticateAdmin({ username, password })) {
- res.status(401).end()
- return
- }
-
- const userData = { username, role: 'admin' }
- req.session.set('user', userData)
- await req.session.save()
-
- res.json({ message: 'Authenticated', user: userData })
- break
- default:
- res.setHeader('Allow', ['POST'])
- res.status(405).end(`Method ${method} Not Allowed`)
- }
-}
-export default withSession(loginHandler)
diff --git a/pages/api/logout.ts b/pages/api/logout.ts
deleted file mode 100644
index 4102b2f..0000000
--- a/pages/api/logout.ts
+++ /dev/null
@@ -1,16 +0,0 @@
-import withSession from '../../lib/session'
-
-async function loginHandler(req: any, res: any): Promise {
- const { method } = req
-
- switch (method) {
- case 'POST':
- req.session.destroy()
- res.json({ message: 'Logged out' })
- break
- default:
- res.setHeader('Allow', ['POST'])
- res.status(405).end(`Method ${method} Not Allowed`)
- }
-}
-export default withSession(loginHandler)
diff --git a/pages/login.tsx b/pages/login.tsx
deleted file mode 100644
index d9da524..0000000
--- a/pages/login.tsx
+++ /dev/null
@@ -1,76 +0,0 @@
-import React, { useState } from 'react'
-import { useRouter } from 'next/router'
-import Footer from '../components/footer'
-import Header from '../components/header'
-import Input from '../components/input'
-import { getBaseURL } from '../helpers/url'
-
-export default function Login() {
- const router = useRouter()
- const [username, setUsername] = useState('')
- const [password, setPassword] = useState('')
-
- const isValid = !!username.length && !!password.length
-
- async function onSubmit(event: React.FormEvent) {
- event.preventDefault()
-
- try {
- await fetch('/api/login', {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: JSON.stringify({
- username,
- password,
- }),
- }).then((response) => {
- if (!response.ok) {
- console.error('Unable to login', response.status, response.statusText)
- return
- }
- const redirect = Array.isArray(router.query?.redirect)
- ? router.query.redirect[0]
- : router.query?.redirect
-
- router.push(redirect || getBaseURL())
- })
- } catch (error) {
- console.error('Unable to login', error)
- }
- }
-
- return (
- <>
-
-
-
-
-
- >
- )
-}