From 4db7f0b9a57b87b0b4ee2fae4fc04952663eb9ef Mon Sep 17 00:00:00 2001 From: Euan Caskie <56805259+Ortovoxx@users.noreply.github.com> Date: Mon, 27 Nov 2023 16:38:47 +0000 Subject: [PATCH 1/4] Remove console.log --- pages/scanner.tsx | 1 - pages/signin.tsx | 2 -- 2 files changed, 3 deletions(-) diff --git a/pages/scanner.tsx b/pages/scanner.tsx index bafdc07..c280d46 100644 --- a/pages/scanner.tsx +++ b/pages/scanner.tsx @@ -28,7 +28,6 @@ export default function Qr() { }) const res2 = await res.json() - console.log(res2) if (res2.success) { setData(res2); } else { diff --git a/pages/signin.tsx b/pages/signin.tsx index e1c67c0..5fbac9d 100644 --- a/pages/signin.tsx +++ b/pages/signin.tsx @@ -15,8 +15,6 @@ export default function SignIn() { const {data: session} = useSession(); - console.log(session) - const { colorScheme, toggleColorScheme } = useMantineColorScheme(); const dark = colorScheme === 'dark'; From d2b73ef6c958a7a464e4c6eb54130c16ce3c1326 Mon Sep 17 00:00:00 2001 From: Euan Caskie <56805259+Ortovoxx@users.noreply.github.com> Date: Mon, 27 Nov 2023 16:44:49 +0000 Subject: [PATCH 2/4] Fix error for non ticket holders --- pages/api/auth/[...nextauth].ts | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/pages/api/auth/[...nextauth].ts b/pages/api/auth/[...nextauth].ts index 2b218fa..28df2e6 100644 --- a/pages/api/auth/[...nextauth].ts +++ b/pages/api/auth/[...nextauth].ts @@ -34,20 +34,27 @@ export const authOptions: NextAuthOptions = { }; session.id = user.id; return session + }, + async signIn({ user, account, profile, email, credentials }) { + const holder = await prisma.ticketHolders.findFirst({ + where: { + sotonId: user.sotonId || undefined, + } + }) + + return !!holder; } } }; -async function getPlusOnes(sotonId: string): Promise<{ error?: string, plusOnes: string[] }> { +async function getPlusOnes(sotonId: string): Promise<{ plusOnes: string[] }> { const holder = await prisma.ticketHolders.findFirst({ where: { sotonId: sotonId } }) - if (!holder) return {error: 'Could not find ticket holder, have you bought a ticket?', plusOnes: []}; - - return { plusOnes: holder.plusOnes } + return { plusOnes: holder?.plusOnes || [] } } export default async function auth(req: NextApiRequest, res: NextApiResponse) { @@ -74,8 +81,6 @@ export default async function auth(req: NextApiRequest, res: NextApiResponse) { const plusOne = await getPlusOnes(data.sotonId) - if (plusOne.error) return res.status(403).json({error: plusOne.error}) - return { id: data.sotonId, firstName: data.firstName, @@ -98,8 +103,6 @@ export default async function auth(req: NextApiRequest, res: NextApiResponse) { const plusOne = await getPlusOnes(sotonData.mail.split('@')[0]) - if (plusOne.error) return res.status(403).json({error: plusOne.error}) - return { id: sotonData.mail.split('@')[0], firstName: sotonData.givenName, @@ -109,10 +112,6 @@ export default async function auth(req: NextApiRequest, res: NextApiResponse) { plusOnes: plusOne.plusOnes, } - - - // res.redirect(`https://sotonverify.link?callback=${process.env.NEXTAUTH_URL}`); - } } From 0fb76f91dc9557550b46a5f9d4ee95f56f8ba4e9 Mon Sep 17 00:00:00 2001 From: Euan Caskie <56805259+Ortovoxx@users.noreply.github.com> Date: Mon, 27 Nov 2023 16:48:49 +0000 Subject: [PATCH 3/4] Create signout.tsx --- pages/signout.tsx | 72 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 pages/signout.tsx diff --git a/pages/signout.tsx b/pages/signout.tsx new file mode 100644 index 0000000..7f1ec1d --- /dev/null +++ b/pages/signout.tsx @@ -0,0 +1,72 @@ +import {unstable_getServerSession} from "next-auth"; +import {LoginButton} from "@/components/LoginButton"; +import {IncomingMessage, ServerResponse} from "http"; +import {NextApiRequestCookies} from "next/dist/server/api-utils"; +import {NextApiRequest, NextApiResponse} from "next"; +import {authOptions} from "./api/auth/[...nextauth]"; +import {Text, useMantineColorScheme} from "@mantine/core"; +import {signIn, signOut, useSession} from "next-auth/react"; +import {useRouter} from "next/router"; +import Tables from "./seat-selection"; +import {FontAwesomeIcon} from "@fortawesome/react-fontawesome"; +import {faMicrosoft} from "@fortawesome/free-brands-svg-icons"; +import React from "react"; + +// @ts-ignore +export default function SignOut() { + + const router = useRouter(); + + const {data: session} = useSession(); + + const { colorScheme, toggleColorScheme } = useMantineColorScheme(); + const dark = colorScheme === 'dark'; + + return ( +