From 00e432814ab5a2c0f6af6b5da86c0bb9948c7a31 Mon Sep 17 00:00:00 2001 From: PxlLoewe <72106766+PxlLoewe@users.noreply.github.com> Date: Sat, 24 May 2025 14:12:58 -0700 Subject: [PATCH] Fixed type errors in nextJS apps, added Docker files Co-authored-by: Nicolas --- apps/dispatch-server/.dockerignore | 6 + apps/dispatch-server/Dockerfile | 29 +++ apps/dispatch/.dockerignore | 7 + apps/dispatch/Dockerfile | 29 +++ .../navbar/_components/Connection.tsx | 2 +- apps/hub-server/.dockerignore | 6 + apps/hub-server/Dockerfile | 31 +++ apps/hub-server/helper/events.ts | 8 + apps/hub-server/modules/chron.ts | 2 +- apps/hub/.dockerignore | 8 + apps/hub/Dockerfile | 29 +++ apps/hub/app/(app)/admin/event/[id]/page.tsx | 4 +- .../event/_components/AppointmentModal.tsx | 106 ++++------- .../(app)/admin/event/_components/Form.tsx | 179 ++++++++---------- .../hub/app/(app)/admin/keyword/[id]/page.tsx | 4 +- apps/hub/app/(app)/admin/report/[id]/page.tsx | 11 +- .../hub/app/(app)/admin/station/[id]/page.tsx | 24 +-- apps/hub/app/(app)/admin/user/[id]/page.tsx | 20 +- apps/hub/app/(app)/page.tsx | 7 +- apps/hub/app/(app)/settings/page.tsx | 6 +- apps/hub/app/(auth)/oauth/page.tsx | 40 +--- apps/hub/app/api/auth/accessToken/route.ts | 8 +- apps/hub/helper/authServices.ts | 22 +++ turbo.json | 4 +- 24 files changed, 334 insertions(+), 258 deletions(-) create mode 100644 apps/dispatch-server/.dockerignore create mode 100644 apps/dispatch-server/Dockerfile create mode 100644 apps/dispatch/.dockerignore create mode 100644 apps/dispatch/Dockerfile create mode 100644 apps/hub-server/.dockerignore create mode 100644 apps/hub-server/Dockerfile create mode 100644 apps/hub-server/helper/events.ts create mode 100644 apps/hub/.dockerignore create mode 100644 apps/hub/Dockerfile create mode 100644 apps/hub/helper/authServices.ts diff --git a/apps/dispatch-server/.dockerignore b/apps/dispatch-server/.dockerignore new file mode 100644 index 00000000..7a533e48 --- /dev/null +++ b/apps/dispatch-server/.dockerignore @@ -0,0 +1,6 @@ +node_modules +Dockerfile +.dockerignore +nodemon.json +.env +.env.example \ No newline at end of file diff --git a/apps/dispatch-server/Dockerfile b/apps/dispatch-server/Dockerfile new file mode 100644 index 00000000..ae216d30 --- /dev/null +++ b/apps/dispatch-server/Dockerfile @@ -0,0 +1,29 @@ +FROM node:22-alpine + +# Set the working directory +WORKDIR /usr/app + +# Copy package.json and package-lock.json +COPY package*.json ./ + +# Install dependencies +RUN npm install + +# Change ownership to the non-root user +RUN chown -R node:node /usr/app + +# Copy the rest of the application code +COPY . . + +# Build the application +RUN npm run build + +# Expose the application port +EXPOSE 3002 + +# Run container as non-root (unprivileged) user +# The "node" user is provided in the Node.js Alpine base image +USER node + +# Command to run the application +CMD ["node", "index.js"] \ No newline at end of file diff --git a/apps/dispatch/.dockerignore b/apps/dispatch/.dockerignore new file mode 100644 index 00000000..3147d3ff --- /dev/null +++ b/apps/dispatch/.dockerignore @@ -0,0 +1,7 @@ +node_modules +Dockerfile +.dockerignore +.eslint.config.msj +.README.md +.env +.env.example \ No newline at end of file diff --git a/apps/dispatch/Dockerfile b/apps/dispatch/Dockerfile new file mode 100644 index 00000000..210f3e7e --- /dev/null +++ b/apps/dispatch/Dockerfile @@ -0,0 +1,29 @@ +FROM node:22-alpine + +# Set the working directory +WORKDIR /usr/app + +# Copy package.json and package-lock.json +COPY package*.json ./ + +# Install dependencies +RUN npm install + +# Change ownership to the non-root user +RUN chown -R node:node /usr/app + +# Copy the rest of the application code +COPY . . + +# Build the application +RUN npm run build + +# Expose the application port +EXPOSE 3001 + +# Run container as non-root (unprivileged) user +# The "node" user is provided in the Node.js Alpine base image +USER node + +# Command to run the application +CMD ["npm", "start"] \ No newline at end of file diff --git a/apps/dispatch/app/pilot/_components/navbar/_components/Connection.tsx b/apps/dispatch/app/pilot/_components/navbar/_components/Connection.tsx index e97dff55..99bb8001 100644 --- a/apps/dispatch/app/pilot/_components/navbar/_components/Connection.tsx +++ b/apps/dispatch/app/pilot/_components/navbar/_components/Connection.tsx @@ -1,6 +1,6 @@ "use client"; import { useSession } from "next-auth/react"; -import { usePilotConnectionStore } from "../../../_store/pilot/connectionStore"; +import { usePilotConnectionStore } from "_store/pilot/connectionStore"; import { useEffect, useRef, useState } from "react"; import { useQuery } from "@tanstack/react-query"; import { getStationsAPI } from "querys/stations"; diff --git a/apps/hub-server/.dockerignore b/apps/hub-server/.dockerignore new file mode 100644 index 00000000..7a533e48 --- /dev/null +++ b/apps/hub-server/.dockerignore @@ -0,0 +1,6 @@ +node_modules +Dockerfile +.dockerignore +nodemon.json +.env +.env.example \ No newline at end of file diff --git a/apps/hub-server/Dockerfile b/apps/hub-server/Dockerfile new file mode 100644 index 00000000..cfce4bee --- /dev/null +++ b/apps/hub-server/Dockerfile @@ -0,0 +1,31 @@ +FROM node:22-alpine + +ENV NODE_ENV=production + +# Set the working directory +WORKDIR /usr/app + +# Copy package.json and package-lock.json +COPY package*.json ./ + +# Install dependencies +RUN npm install + +# Change ownership to the non-root user +RUN chown -R node:node /usr/app + +# Copy the rest of the application code +COPY . . + +# Build the application +RUN npm run build + +# Expose the application port +EXPOSE 3003 + +# Run container as non-root (unprivileged) user +# The "node" user is provided in the Node.js Alpine base image +USER node + +# Command to run the application +CMD ["node", "index.js"] \ No newline at end of file diff --git a/apps/hub-server/helper/events.ts b/apps/hub-server/helper/events.ts new file mode 100644 index 00000000..ba456620 --- /dev/null +++ b/apps/hub-server/helper/events.ts @@ -0,0 +1,8 @@ +import { Event, Participant } from "@repo/db"; + +export const eventCompleted = (event: Event, participant?: Participant) => { + if (!participant) return false; + if (event.finisherMoodleCourseId && !participant.finisherMoodleCurseCompleted) return false; + if (event.hasPresenceEvents && !participant.attended) return false; + return true; +}; diff --git a/apps/hub-server/modules/chron.ts b/apps/hub-server/modules/chron.ts index ce06df5e..6bce78f8 100644 --- a/apps/hub-server/modules/chron.ts +++ b/apps/hub-server/modules/chron.ts @@ -1,9 +1,9 @@ import { getMoodleCourseCompletionStatus, getMoodleUserById } from "./moodle"; import { CronJob } from "cron"; import { prisma } from "@repo/db"; -import { eventCompleted } from "@repo/ui/helper"; import { sendCourseCompletedEmail } from "modules/mail"; import { handleParticipantFinished } from "modules/event"; +import { eventCompleted } from "helper/events"; const syncMoodleIds = async () => { try { diff --git a/apps/hub/.dockerignore b/apps/hub/.dockerignore new file mode 100644 index 00000000..716c6297 --- /dev/null +++ b/apps/hub/.dockerignore @@ -0,0 +1,8 @@ +node_modules +Dockerfile +.dockerignore +.gitignore +.eslint.config.msj +.README.md +.env +.env.example \ No newline at end of file diff --git a/apps/hub/Dockerfile b/apps/hub/Dockerfile new file mode 100644 index 00000000..3ad34206 --- /dev/null +++ b/apps/hub/Dockerfile @@ -0,0 +1,29 @@ +FROM node:22-alpine + +# Set the working directory +WORKDIR /usr/app + +# Copy package.json and package-lock.json +COPY package*.json ./ + +# Install dependencies +RUN npm install + +# Change ownership to the non-root user +RUN chown -R node:node /usr/app + +# Copy the rest of the application code +COPY . . + +# Build the application +RUN npm run build + +# Expose the application port +EXPOSE 3000 + +# Run container as non-root (unprivileged) user +# The "node" user is provided in the Node.js Alpine base image +USER node + +# Command to run the application +CMD ["npm", "start"] \ No newline at end of file diff --git a/apps/hub/app/(app)/admin/event/[id]/page.tsx b/apps/hub/app/(app)/admin/event/[id]/page.tsx index 9d115efe..75184324 100644 --- a/apps/hub/app/(app)/admin/event/[id]/page.tsx +++ b/apps/hub/app/(app)/admin/event/[id]/page.tsx @@ -1,7 +1,7 @@ import { prisma } from "@repo/db"; import { Form } from "../_components/Form"; -export default async ({ params }: { params: Promise<{ id: string }> }) => { +export default async function Page({ params }: { params: Promise<{ id: string }> }) { const { id } = await params; const event = await prisma.event.findUnique({ where: { @@ -10,4 +10,4 @@ export default async ({ params }: { params: Promise<{ id: string }> }) => { }); if (!event) return
Event not found
; return
; -}; +} diff --git a/apps/hub/app/(app)/admin/event/_components/AppointmentModal.tsx b/apps/hub/app/(app)/admin/event/_components/AppointmentModal.tsx index 3b5a2fee..289cb5e7 100644 --- a/apps/hub/app/(app)/admin/event/_components/AppointmentModal.tsx +++ b/apps/hub/app/(app)/admin/event/_components/AppointmentModal.tsx @@ -1,34 +1,21 @@ -import { DateInput } from "../../../../_components/ui/DateInput"; -import { zodResolver } from "@hookform/resolvers/zod"; -import { Event, Participant, Prisma } from "@repo/db"; -import { - EventAppointmentOptionalDefaults, - EventAppointmentOptionalDefaultsSchema, - ParticipantOptionalDefaultsSchema, -} from "@repo/db/zod"; -import { useSession } from "next-auth/react"; -import { Controller, useForm, UseFormReturn } from "react-hook-form"; -import { deleteAppoinement, upsertAppointment } from "../action"; -import { Button } from "../../../../_components/ui/Button"; -import { - PaginatedTable, - PaginatedTableRef, -} from "../../../../_components/PaginatedTable"; -import { Ref, RefObject, useRef } from "react"; +import { Event, Participant } from "@repo/db"; +import { EventAppointmentOptionalDefaults } from "@repo/db/zod"; import { CellContext } from "@tanstack/react-table"; +import { useSession } from "next-auth/react"; +import { RefObject, useRef } from "react"; +import { UseFormReturn } from "react-hook-form"; +import { PaginatedTable, PaginatedTableRef } from "../../../../_components/PaginatedTable"; +import { Button } from "../../../../_components/ui/Button"; +import { DateInput } from "../../../../_components/ui/DateInput"; import { upsertParticipant } from "../../../events/actions"; -import { Switch } from "../../../../_components/ui/Switch"; +import { deleteAppoinement, upsertAppointment } from "../action"; interface AppointmentModalProps { event?: Event; ref: RefObject; participantModal: RefObject; - appointmentsTableRef: React.RefObject; - appointmentForm: UseFormReturn< - EventAppointmentOptionalDefaults, - any, - undefined - >; + appointmentsTableRef: React.RefObject; + appointmentForm: UseFormReturn; participantForm: UseFormReturn; } @@ -56,9 +43,7 @@ export const AppointmentModal = ({ ✕ -

- Termin {appointmentForm.watch("id")} -

+

Termin {appointmentForm.watch("id")}

{ if (!event) return; @@ -101,13 +86,7 @@ export const AppointmentModal = ({ accessorKey: "enscriptionDate", header: "Einschreibedatum", cell: ({ row }: CellContext) => { - return ( - - {new Date( - row.original.enscriptionDate, - ).toLocaleString()} - - ); + return {new Date(row.original.enscriptionDate).toLocaleString()}; }, }, { @@ -116,11 +95,7 @@ export const AppointmentModal = ({ if (row.original.attended) { return Ja; } else if (row.original.appointmentCancelled) { - return ( - - Nein (Termin abgesagt) - - ); + return Nein (Termin abgesagt); } else { return ?; } @@ -159,33 +134,32 @@ export const AppointmentModal = ({ Anwesend )} - {!row.original.appointmentCancelled && - event?.hasPresenceEvents && ( - - )} + {!row.original.appointmentCancelled && event?.hasPresenceEvents && ( + + )} ); }, diff --git a/apps/hub/app/(app)/admin/event/_components/Form.tsx b/apps/hub/app/(app)/admin/event/_components/Form.tsx index f8ce5d24..89798cce 100644 --- a/apps/hub/app/(app)/admin/event/_components/Form.tsx +++ b/apps/hub/app/(app)/admin/event/_components/Form.tsx @@ -1,51 +1,42 @@ "use client"; import { zodResolver } from "@hookform/resolvers/zod"; +import { BADGES, Event, EVENT_TYPE, Participant, PERMISSION, User } from "@repo/db"; import { EventAppointmentOptionalDefaults, EventAppointmentOptionalDefaultsSchema, EventOptionalDefaults, EventOptionalDefaultsSchema, - ParticipantOptionalDefaultsSchema, + ParticipantSchema, } from "@repo/db/zod"; -import { Controller, set, useForm } from "react-hook-form"; -import { - BADGES, - Event, - EVENT_TYPE, - Participant, - PERMISSION, - prisma, - Prisma, -} from "@repo/db"; -import { Bot, Calendar, FileText, User, UserIcon } from "lucide-react"; -import { Input } from "../../../../_components/ui/Input"; -import { useRef, useState } from "react"; -import { - deleteAppoinement, - deleteEvent, - upsertAppointment, - upsertEvent, -} from "../action"; -import { Button } from "../../../../_components/ui/Button"; -import { redirect, useRouter } from "next/navigation"; -import { Switch } from "../../../../_components/ui/Switch"; -import DatePicker, { registerLocale } from "react-datepicker"; -import "react-datepicker/dist/react-datepicker.css"; -import { - PaginatedTable, - PaginatedTableRef, -} from "../../../../_components/PaginatedTable"; -import { Select } from "../../../../_components/ui/Select"; +import { Bot, Calendar, FileText, UserIcon } from "lucide-react"; import { useSession } from "next-auth/react"; +import { redirect } from "next/navigation"; +import { useRef, useState } from "react"; +import "react-datepicker/dist/react-datepicker.css"; +import { useForm } from "react-hook-form"; +import { PaginatedTable, PaginatedTableRef } from "../../../../_components/PaginatedTable"; +import { Button } from "../../../../_components/ui/Button"; +import { Input } from "../../../../_components/ui/Input"; import { MarkdownEditor } from "../../../../_components/ui/MDEditor"; +import { Select } from "../../../../_components/ui/Select"; +import { Switch } from "../../../../_components/ui/Switch"; +import { deleteEvent, upsertEvent } from "../action"; import { AppointmentModal } from "./AppointmentModal"; import { ParticipantModal } from "./ParticipantModal"; +import { ColumnDef } from "@tanstack/react-table"; export const Form = ({ event }: { event?: Event }) => { const { data: session } = useSession(); - const form = useForm({ + const form = useForm({ resolver: zodResolver(EventOptionalDefaultsSchema), - defaultValues: event, + defaultValues: event + ? { + ...event, + discordRoleId: event.discordRoleId ?? undefined, + maxParticipants: event.maxParticipants ?? undefined, + finisherMoodleCourseId: event.finisherMoodleCourseId ?? undefined, + } + : undefined, }); const appointmentForm = useForm({ resolver: zodResolver(EventAppointmentOptionalDefaultsSchema), @@ -55,7 +46,7 @@ export const Form = ({ event }: { event?: Event }) => { }, }); const participantForm = useForm({ - resolver: zodResolver(ParticipantOptionalDefaultsSchema), + resolver: zodResolver(ParticipantSchema), }); const appointmentsTableRef = useRef(null); const [loading, setLoading] = useState(false); @@ -73,10 +64,7 @@ export const Form = ({ event }: { event?: Event }) => { appointmentsTableRef={appointmentsTableRef} event={event} /> - + { setLoading(true); @@ -155,11 +143,7 @@ export const Form = ({ event }: { event?: Event }) => { value: key, }))} /> - + {form.watch("hasPresenceEvents") ? ( @@ -196,58 +180,61 @@ export const Form = ({ event }: { event?: Event }) => { Presenter: true, Participants: true, }} - columns={[ - { - header: "Datum", - accessorKey: "appointmentDate", - accessorFn: (date) => - new Date(date.appointmentDate).toLocaleString(), - }, - { - header: "Presenter", - accessorKey: "presenter", - cell: ({ row }) => ( -
- - {(row.original as any).Presenter.firstname}{" "} - {(row.original as any).Presenter.lastname} - -
- ), - }, - { - header: "Teilnehmer", - accessorKey: "Participants", - cell: ({ row }) => ( -
- - - {row.original.Participants.length} - -
- ), - }, - { - header: "Aktionen", - cell: ({ row }) => { - return ( -
- -
- ); + columns={ + [ + { + header: "Datum", + accessorKey: "appointmentDate", + accessorFn: (date) => new Date(date.appointmentDate).toLocaleString(), }, - }, - ]} + { + header: "Presenter", + accessorKey: "presenter", + cell: ({ row }) => ( +
+ + {row.original.Presenter.firstname} {row.original.Presenter.lastname} + +
+ ), + }, + { + header: "Teilnehmer", + accessorKey: "Participants", + cell: ({ row }) => ( +
+ + {row.original.Participants.length} +
+ ), + }, + { + header: "Aktionen", + cell: ({ row }) => { + return ( +
+ +
+ ); + }, + }, + ] as ColumnDef< + EventAppointmentOptionalDefaults & { + Presenter: User; + Participants: Participant[]; + } + >[] + } /> @@ -311,11 +298,7 @@ export const Form = ({ event }: { event?: Event }) => {
- {event && ( diff --git a/apps/hub/app/(app)/admin/keyword/[id]/page.tsx b/apps/hub/app/(app)/admin/keyword/[id]/page.tsx index 7cfeaf45..82390973 100644 --- a/apps/hub/app/(app)/admin/keyword/[id]/page.tsx +++ b/apps/hub/app/(app)/admin/keyword/[id]/page.tsx @@ -1,7 +1,7 @@ import { prisma } from "@repo/db"; import { KeywordForm } from "../_components/Form"; -export default async ({ params }: { params: Promise<{ id: string }> }) => { +export default async function Page({ params }: { params: Promise<{ id: string }> }) { const { id } = await params; const keyword = await prisma.keyword.findUnique({ where: { @@ -10,4 +10,4 @@ export default async ({ params }: { params: Promise<{ id: string }> }) => { }); if (!keyword) return
Station not found
; return ; -}; +} diff --git a/apps/hub/app/(app)/admin/report/[id]/page.tsx b/apps/hub/app/(app)/admin/report/[id]/page.tsx index fa85447c..178bd992 100644 --- a/apps/hub/app/(app)/admin/report/[id]/page.tsx +++ b/apps/hub/app/(app)/admin/report/[id]/page.tsx @@ -1,16 +1,9 @@ import { ExclamationTriangleIcon } from "@radix-ui/react-icons"; import { prisma } from "@repo/db"; import { Error } from "_components/Error"; -import { - ReportAdmin, - ReportSenderInfo, -} from "(app)/admin/report/_components/form"; +import { ReportAdmin, ReportSenderInfo } from "(app)/admin/report/_components/form"; -export default async function ReportDetailsPage({ - params, -}: { - params: { id: string }; -}) { +export default async function Page({ params }: { params: Promise<{ id: string }> }) { const { id } = await params; const report = await prisma.report.findUnique({ diff --git a/apps/hub/app/(app)/admin/station/[id]/page.tsx b/apps/hub/app/(app)/admin/station/[id]/page.tsx index 399adf90..f894a84c 100644 --- a/apps/hub/app/(app)/admin/station/[id]/page.tsx +++ b/apps/hub/app/(app)/admin/station/[id]/page.tsx @@ -1,13 +1,13 @@ -import { prisma } from '@repo/db'; -import { StationForm } from '../_components/Form'; +import { prisma } from "@repo/db"; +import { StationForm } from "../_components/Form"; -export default async ({ params }: { params: Promise<{ id: string }> }) => { - const { id } = await params; - const station = await prisma.station.findUnique({ - where: { - id: parseInt(id), - }, - }); - if (!station) return
Station not found
; - return ; -}; +export default async function Page({ params }: { params: Promise<{ id: string }> }) { + const { id } = await params; + const station = await prisma.station.findUnique({ + where: { + id: parseInt(id), + }, + }); + if (!station) return
Station not found
; + return ; +} diff --git a/apps/hub/app/(app)/admin/user/[id]/page.tsx b/apps/hub/app/(app)/admin/user/[id]/page.tsx index 7d09774f..2009e314 100644 --- a/apps/hub/app/(app)/admin/user/[id]/page.tsx +++ b/apps/hub/app/(app)/admin/user/[id]/page.tsx @@ -1,14 +1,9 @@ import { PersonIcon } from "@radix-ui/react-icons"; import { prisma, User } from "@repo/db"; -import { - AdminForm, - ConnectionHistory, - ProfileForm, - UserReports, -} from "./_components/forms"; +import { AdminForm, ConnectionHistory, ProfileForm, UserReports } from "./_components/forms"; import { Error } from "../../../../_components/Error"; -const Page = async ({ params }: { params: { id: string } }) => { +export default async function Page({ params }: { params: Promise<{ id: string }> }) { const { id } = await params; const user: User | null = await prisma.user.findUnique({ @@ -107,12 +102,7 @@ const Page = async ({ params }: { params: { id: string } }) => {
- +
@@ -122,6 +112,4 @@ const Page = async ({ params }: { params: { id: string } }) => {
); -}; - -export default Page; +} diff --git a/apps/hub/app/(app)/page.tsx b/apps/hub/app/(app)/page.tsx index c13328de..4e7f3dd9 100644 --- a/apps/hub/app/(app)/page.tsx +++ b/apps/hub/app/(app)/page.tsx @@ -18,7 +18,7 @@ Aktive Events / Mandatory Events export default async function Home({ searchParams, }: { - searchParams: { stats?: "pilot" | "dispo" }; + searchParams: Promise<{ stats?: "pilot" | "dispo" }>; }) { const { stats } = await searchParams; const view = stats || "pilot"; @@ -33,10 +33,7 @@ export default async function Home({ Logbook - + Zum vollständigen Logbook diff --git a/apps/hub/app/(app)/settings/page.tsx b/apps/hub/app/(app)/settings/page.tsx index 8c593f4f..5d655a36 100644 --- a/apps/hub/app/(app)/settings/page.tsx +++ b/apps/hub/app/(app)/settings/page.tsx @@ -3,7 +3,7 @@ import { getServerSession } from "../../api/auth/[...nextauth]/auth"; import { ProfileForm, SocialForm, PasswordForm, PilotForm } from "./_components/forms"; import { GearIcon } from "@radix-ui/react-icons"; -export const page = async () => { +export default async function Page() { const session = await getServerSession(); if (!session) return null; const user = await prisma.user.findFirst({ @@ -37,6 +37,4 @@ export const page = async () => {
); -}; - -export default page; +} diff --git a/apps/hub/app/(auth)/oauth/page.tsx b/apps/hub/app/(auth)/oauth/page.tsx index d50134a4..0c8881e5 100644 --- a/apps/hub/app/(auth)/oauth/page.tsx +++ b/apps/hub/app/(auth)/oauth/page.tsx @@ -1,48 +1,20 @@ +import { services } from "../../../helper/authServices"; import { Authorize } from "./_components/Authorize"; -export const services = [ - { - id: "1", - service: "dispatch", - name: "Leitstellendisposition", - approvedUrls: ["http://localhost:3001"], - }, - { - id: "2", - secret: "jp2k430fnv", - service: "desktop", - name: "Desktop client", - approvedUrls: ["var://oAuth"], - }, - { - id: "3", - secret: "d0f3e4e4", - service: "moodle", - name: "Moodle", - approvedUrls: [ - "http://localhost:8081", - "https://moodle.virtualairrescue.com", - ], - }, -]; export type Service = (typeof services)[number]; -const Page = async ({ +export default async function Page({ searchParams, }: { - searchParams: Promise<{ [key: string]: string | string[] | undefined }>; -}) => { + searchParams: Promise<{ client_id: string; service: string }>; +}) { const { service: serviceId, client_id: clientId } = await searchParams; - const service = services.find( - (service) => service.id === serviceId || service.id === clientId, - ); + const service = services.find((service) => service.id === serviceId || service.id === clientId); if (!service) { return
Service not found
; } return ; -}; - -export default Page; +} diff --git a/apps/hub/app/api/auth/accessToken/route.ts b/apps/hub/app/api/auth/accessToken/route.ts index 8872adf6..225cb696 100644 --- a/apps/hub/app/api/auth/accessToken/route.ts +++ b/apps/hub/app/api/auth/accessToken/route.ts @@ -1,15 +1,11 @@ import { NextRequest } from "next/server"; import { sign } from "jsonwebtoken"; -import { services } from "(auth)/oauth/page"; import { prisma } from "@repo/db"; +import { services } from "../../../../helper/authServices"; export const POST = async (req: NextRequest) => { try { - if ( - !req.headers - .get("content-type") - ?.includes("application/x-www-form-urlencoded") - ) { + if (!req.headers.get("content-type")?.includes("application/x-www-form-urlencoded")) { return new Response("Unsupported Content-Type", { status: 415 }); } diff --git a/apps/hub/helper/authServices.ts b/apps/hub/helper/authServices.ts new file mode 100644 index 00000000..71f4803b --- /dev/null +++ b/apps/hub/helper/authServices.ts @@ -0,0 +1,22 @@ +export const services = [ + { + id: "1", + service: "dispatch", + name: "Leitstellendisposition", + approvedUrls: ["http://localhost:3001"], + }, + { + id: "2", + secret: "jp2k430fnv", + service: "desktop", + name: "Desktop client", + approvedUrls: ["var://oAuth"], + }, + { + id: "3", + secret: "d0f3e4e4", + service: "moodle", + name: "Moodle", + approvedUrls: ["http://localhost:8081", "https://moodle.virtualairrescue.com"], + }, +]; diff --git a/turbo.json b/turbo.json index a326738c..2b11aabb 100644 --- a/turbo.json +++ b/turbo.json @@ -1,7 +1,7 @@ { "$schema": "https://turbo.build/schema.json", "globalDependencies": ["**/.env.*local"], - "globalEnv": ["EMAIL_SERVER", "EMAIL_FROM", "SECRET"], + "globalEnv": ["EMAIL_SERVER", "EMAIL_FROM", "SECRET", "DATABASE_URL", "NEXTAUTH_SECRET"], "ui": "tui", "tasks": { "generate": { @@ -15,7 +15,7 @@ "build": { "dependsOn": ["^build", "generate", "migrate"], "inputs": ["$TURBO_DEFAULT$", ".env*"], - "outputs": [".next/**", "!.next/cache/**"] + "outputs": [".next/**", "!.next/cache/**", "dist/**"] }, "lint": { "dependsOn": ["^lint"]