diff --git a/apps/hub-server/index.ts b/apps/hub-server/index.ts index f33fe1aa..75efaea0 100644 --- a/apps/hub-server/index.ts +++ b/apps/hub-server/index.ts @@ -1,2 +1,2 @@ import "modules/chron"; -console.log("VAR hub Server started"); \ No newline at end of file +console.log("VAR hub Server started"); diff --git a/apps/hub/app/(app)/admin/station/_components/Form.tsx b/apps/hub/app/(app)/admin/station/_components/Form.tsx index c8bfe068..c604dfa9 100644 --- a/apps/hub/app/(app)/admin/station/_components/Form.tsx +++ b/apps/hub/app/(app)/admin/station/_components/Form.tsx @@ -1,246 +1,245 @@ -'use client'; -import { zodResolver } from '@hookform/resolvers/zod'; -import { StationOptionalDefaultsSchema } from '@repo/db/zod'; -import { set, useForm } from 'react-hook-form'; -import { z } from 'zod'; -import { BosUse, Country, Station } from '@repo/db'; -import { FileText, LocateIcon, PlaneIcon } from 'lucide-react'; -import { Input } from '../../../../_components/ui/Input'; -import { useState } from 'react'; -import { deleteStation, upsertStation } from '../action'; -import { Button } from '../../../../_components/ui/Button'; -import { redirect } from 'next/navigation'; +"use client"; +import { zodResolver } from "@hookform/resolvers/zod"; +import { StationOptionalDefaultsSchema } from "@repo/db/zod"; +import { set, useForm } from "react-hook-form"; +import { z } from "zod"; +import { BosUse, Country, Station } from "@repo/db"; +import { FileText, LocateIcon, PlaneIcon } from "lucide-react"; +import { Input } from "../../../../_components/ui/Input"; +import { useState } from "react"; +import { deleteStation, upsertStation } from "../action"; +import { Button } from "../../../../_components/ui/Button"; +import { redirect } from "next/navigation"; export const StationForm = ({ station }: { station?: Station }) => { - const form = useForm>({ - resolver: zodResolver(StationOptionalDefaultsSchema), - defaultValues: station, - }); - const [loading, setLoading] = useState(false); - const [deleteLoading, setDeleteLoading] = useState(false); - console.log(form.formState.errors); - return ( - <> -
{ - setLoading(true); - const createdStation = await upsertStation(values, station?.id); - setLoading(false); - if (!station) redirect(`/admin/station`); - })} - className="grid grid-cols-6 gap-3" - > -
-
-

- Allgemeines -

- - - - - - + const form = useForm>({ + resolver: zodResolver(StationOptionalDefaultsSchema), + defaultValues: station, + }); + const [loading, setLoading] = useState(false); + const [deleteLoading, setDeleteLoading] = useState(false); + return ( + <> + { + setLoading(true); + const createdStation = await upsertStation(values, station?.id); + setLoading(false); + if (!station) redirect(`/admin/station`); + })} + className="grid grid-cols-6 gap-3" + > +
+
+

+ Allgemeines +

+ + + + + + - -
-
-
-
-

- Standort + Ausrüstung -

- - - - - Ausgerüstet mit: - -
- - - - -
+ +
+
+
+
+

+ Standort + Ausrüstung +

+ + + + + Ausgerüstet mit: + +
+ + + + +
- - - -
-
-
-
-

- Hubschrauber -

- - - -
-
-
-
-
- - {station && ( - - )} -
-
-
- - - ); + + + +
+
+
+
+

+ Hubschrauber +

+ + + +
+
+
+
+
+ + {station && ( + + )} +
+
+
+ + + ); }; diff --git a/apps/hub/app/(app)/admin/user/[id]/page.tsx b/apps/hub/app/(app)/admin/user/[id]/page.tsx index 19f0a092..5e4d92e5 100644 --- a/apps/hub/app/(app)/admin/user/[id]/page.tsx +++ b/apps/hub/app/(app)/admin/user/[id]/page.tsx @@ -1,22 +1,22 @@ -import { PrismaClient } from '@repo/db'; +import { PrismaClient } from "@repo/db"; export default async ({ params }: { params: Promise<{ id: string }> }) => { - const prisma = new PrismaClient(); - const { id } = await params; + const prisma = new PrismaClient(); + const { id } = await params; - const user = await prisma.user.findUnique({ - where: { - id: id, - }, - }); - console.log(user); - return ( -
-

- {user?.firstname} {user?.lastname} -

-

{user?.email}

- {/* TODO: Hier Nutzerdaten bearbeiten */} -
- ); + const user = await prisma.user.findUnique({ + where: { + id: id, + }, + }); + console.log(user); + return ( +
+

+ {user?.firstname} {user?.lastname} +

+

{user?.email}

+ {/* TODO: Hier Nutzerdaten bearbeiten */} +
+ ); }; diff --git a/apps/hub/app/(app)/settings/_components/forms.tsx b/apps/hub/app/(app)/settings/_components/forms.tsx index b11b1ad1..8873634a 100644 --- a/apps/hub/app/(app)/settings/_components/forms.tsx +++ b/apps/hub/app/(app)/settings/_components/forms.tsx @@ -10,345 +10,344 @@ import { useSession } from "next-auth/react"; import { useRouter } from "next/navigation"; import { Button } from "../../../_components/ui/Button"; import { - PersonIcon, - EnvelopeClosedIcon, - BookmarkIcon, - DiscordLogoIcon, - PaperPlaneIcon, - Link2Icon, - MixerHorizontalIcon, - LockClosedIcon, - LockOpen2Icon, - LockOpen1Icon, + PersonIcon, + EnvelopeClosedIcon, + BookmarkIcon, + DiscordLogoIcon, + PaperPlaneIcon, + Link2Icon, + MixerHorizontalIcon, + LockClosedIcon, + LockOpen2Icon, + LockOpen1Icon, } from "@radix-ui/react-icons"; export const ProfileForm = ({ user }: { user: User }) => { - const schema = z.object({ - firstname: z.string().min(2).max(30), - lastname: z.string().min(2).max(30), - email: z.string().email({ - message: "Bitte gebe eine gültige E-Mail Adresse ein", - }), - }); - const [isLoading, setIsLoading] = useState(false); - type IFormInput = z.infer; + const schema = z.object({ + firstname: z.string().min(2).max(30), + lastname: z.string().min(2).max(30), + email: z.string().email({ + message: "Bitte gebe eine gültige E-Mail Adresse ein", + }), + }); + const [isLoading, setIsLoading] = useState(false); + type IFormInput = z.infer; - const form = useForm({ - defaultValues: { - firstname: user.firstname, - lastname: user.lastname, - email: user.email, - }, - resolver: zodResolver(schema), - }); - return ( -
{ - setIsLoading(true); - await updateUser(values); - form.reset(values); - setIsLoading(false); - toast.success("Deine Änderungen wurden gespeichert!", { - style: { - background: "var(--color-base-100)", - color: "var(--color-base-content)", - }, - }); - })} - > -

- Persönliche Informationen -

-
- - {form.formState.errors.firstname && ( -

- {form.formState.errors.firstname.message} -

- )} - - {form.formState.errors.lastname && ( -

- {form.formState.errors.lastname?.message} -

- )} - - {form.formState.errors.email && ( -

{form.formState.errors.email?.message}

- )} -
- -
-
-
- ); + const form = useForm({ + defaultValues: { + firstname: user.firstname, + lastname: user.lastname, + email: user.email, + }, + resolver: zodResolver(schema), + }); + return ( +
{ + setIsLoading(true); + await updateUser(values); + form.reset(values); + setIsLoading(false); + toast.success("Deine Änderungen wurden gespeichert!", { + style: { + background: "var(--color-base-100)", + color: "var(--color-base-content)", + }, + }); + })} + > +

+ Persönliche Informationen +

+
+ + {form.formState.errors.firstname && ( +

+ {form.formState.errors.firstname.message} +

+ )} + + {form.formState.errors.lastname && ( +

+ {form.formState.errors.lastname?.message} +

+ )} + + {form.formState.errors.email && ( +

{form.formState.errors.email?.message}

+ )} +
+ +
+
+
+ ); }; export const SocialForm = ({ - discordAccount, - user, + discordAccount, + user, }: { - discordAccount?: DiscordAccount; - user: User; + discordAccount?: DiscordAccount; + user: User; }) => { - const [isLoading, setIsLoading] = useState(false); - const [vatsimLoading, setVatsimLoading] = useState(false); - const router = useRouter(); + const [isLoading, setIsLoading] = useState(false); + const [vatsimLoading, setVatsimLoading] = useState(false); + const router = useRouter(); - const schema = z.object({ - vatsimCid: z.number().min(1000).max(9999999), - }); + const schema = z.object({ + vatsimCid: z.number().min(1000).max(9999999), + }); - type IFormInput = z.infer; + type IFormInput = z.infer; - const form = useForm({ - defaultValues: { - vatsimCid: user?.vatsimCid || undefined, - }, - resolver: zodResolver(schema), - }); + const form = useForm({ + defaultValues: { + vatsimCid: user?.vatsimCid || undefined, + }, + resolver: zodResolver(schema), + }); - if (!user) return null; - console.log("Dirty", form.formState.isDirty); - return ( -
{ - form.handleSubmit(async () => { - setVatsimLoading(true); - }); - await updateUser({ - vatsimCid: values.vatsimCid, - }); - setVatsimLoading(false); - form.reset(values); - toast.success("Deine Änderungen wurden gespeichert!", { - style: { - background: "var(--color-base-100)", - color: "var(--color-base-content)", - }, - }); - })} - > -

- Verbindungen & Benachrichtigungen -

-
-
-
- - Discord - -
+ if (!user) return null; + return ( + { + form.handleSubmit(async () => { + setVatsimLoading(true); + }); + await updateUser({ + vatsimCid: values.vatsimCid, + }); + setVatsimLoading(false); + form.reset(values); + toast.success("Deine Änderungen wurden gespeichert!", { + style: { + background: "var(--color-base-100)", + color: "var(--color-base-content)", + }, + }); + })} + > +

+ Verbindungen & Benachrichtigungen +

+
+
+
+ + Discord + +
- {discordAccount ? ( - - ) : ( - - - - )} -
-
-
- - {form.formState.errors.vatsimCid && ( -

- {form.formState.errors.vatsimCid.message} -

- )} -
-
- -
- - ); + {discordAccount ? ( + + ) : ( + + + + )} +
+
+
+ + {form.formState.errors.vatsimCid && ( +

+ {form.formState.errors.vatsimCid.message} +

+ )} +
+
+ +
+ + ); }; export const PasswordForm = ({ user }: { user: User }) => { - const schema = z.object({ - password: z.string().min(2).max(30), - newPassword: z.string().min(2).max(30), - newPasswordConfirm: z.string().min(2).max(30), - }); - const [isLoading, setIsLoading] = useState(false); - type IFormInput = z.infer; + const schema = z.object({ + password: z.string().min(2).max(30), + newPassword: z.string().min(2).max(30), + newPasswordConfirm: z.string().min(2).max(30), + }); + const [isLoading, setIsLoading] = useState(false); + type IFormInput = z.infer; - const form = useForm({ - defaultValues: {}, - resolver: zodResolver(schema), - }); - return ( -
{ - setIsLoading(true); - const result = await changePassword( - values.password, - values.newPassword - ); - form.reset(values); - setIsLoading(false); - if (result.error) { - form.setError("password", { - type: "manual", - message: result.error, - }); - } else if (result.success) { - toast.success("Dein Passwort wurde geändert!", { - style: { - background: "var(--color-base-100)", - color: "var(--color-base-content)", - }, - }); - } - })} - > -

- Password Ändern -

-
- - {form.formState.errors.password && ( -

{form.formState.errors.password.message}

- )} - - {form.formState.errors.newPassword && ( -

- {form.formState.errors.newPassword?.message} -

- )} - - {form.formState.errors.newPasswordConfirm && ( -

- {form.formState.errors.newPasswordConfirm?.message} -

- )} -
- -
-
-
- ); + const form = useForm({ + defaultValues: {}, + resolver: zodResolver(schema), + }); + return ( +
{ + setIsLoading(true); + const result = await changePassword( + values.password, + values.newPassword, + ); + form.reset(values); + setIsLoading(false); + if (result.error) { + form.setError("password", { + type: "manual", + message: result.error, + }); + } else if (result.success) { + toast.success("Dein Passwort wurde geändert!", { + style: { + background: "var(--color-base-100)", + color: "var(--color-base-content)", + }, + }); + } + })} + > +

+ Password Ändern +

+
+ + {form.formState.errors.password && ( +

{form.formState.errors.password.message}

+ )} + + {form.formState.errors.newPassword && ( +

+ {form.formState.errors.newPassword?.message} +

+ )} + + {form.formState.errors.newPasswordConfirm && ( +

+ {form.formState.errors.newPasswordConfirm?.message} +

+ )} +
+ +
+
+
+ ); }; diff --git a/apps/hub/app/_components/PaginatedTable.tsx b/apps/hub/app/_components/PaginatedTable.tsx index c83b2dd4..995184d0 100644 --- a/apps/hub/app/_components/PaginatedTable.tsx +++ b/apps/hub/app/_components/PaginatedTable.tsx @@ -64,7 +64,6 @@ export function PaginatedTable({ useImperativeHandle(ref, () => ({ refresh: () => { - console.log("refresh"); RefreshTableData(); }, })); diff --git a/apps/hub/app/api/auth/[...nextauth]/auth.ts b/apps/hub/app/api/auth/[...nextauth]/auth.ts index 8f9cc5b0..1558d356 100644 --- a/apps/hub/app/api/auth/[...nextauth]/auth.ts +++ b/apps/hub/app/api/auth/[...nextauth]/auth.ts @@ -1,67 +1,66 @@ import { - AuthOptions, - getServerSession as getNextAuthServerSession, -} from 'next-auth'; -import { PrismaAdapter } from '@next-auth/prisma-adapter'; -import Credentials from 'next-auth/providers/credentials'; -import { PrismaClient } from '@repo/db'; -import bcrypt from 'bcryptjs'; + AuthOptions, + getServerSession as getNextAuthServerSession, +} from "next-auth"; +import { PrismaAdapter } from "@next-auth/prisma-adapter"; +import Credentials from "next-auth/providers/credentials"; +import { PrismaClient } from "@repo/db"; +import bcrypt from "bcryptjs"; const prisma = new PrismaClient(); export const options: AuthOptions = { - providers: [ - Credentials({ - credentials: { - email: { label: 'Email', type: 'email', placeholder: 'E-Mail' }, - password: { label: 'Password', type: 'password' }, - }, - async authorize(credentials, req) { - try { - if (!credentials) throw new Error('No credentials provided'); - const user = await prisma.user.findFirstOrThrow({ - where: { email: credentials.email }, - }); - if (bcrypt.compareSync(credentials.password, user.password)) { - console.log('User found and password correct', user); - return user; - } - return null; - } catch (error) { - return null; - } - }, - }), - ], - secret: process.env.NEXTAUTH_SECRET, - session: { - strategy: 'jwt', - maxAge: 30 * 24 * 60 * 60, - }, + providers: [ + Credentials({ + credentials: { + email: { label: "Email", type: "email", placeholder: "E-Mail" }, + password: { label: "Password", type: "password" }, + }, + async authorize(credentials, req) { + try { + if (!credentials) throw new Error("No credentials provided"); + const user = await prisma.user.findFirstOrThrow({ + where: { email: credentials.email }, + }); + if (bcrypt.compareSync(credentials.password, user.password)) { + return user; + } + return null; + } catch (error) { + return null; + } + }, + }), + ], + secret: process.env.NEXTAUTH_SECRET, + session: { + strategy: "jwt", + maxAge: 30 * 24 * 60 * 60, + }, - adapter: PrismaAdapter(prisma as any), - callbacks: { - jwt: async ({ token, user }) => { - if (user && 'firstname' in user) { - return { - ...token, - ...user, - }; - } - return token; - }, - session: async ({ session, user, token }) => { - return { - ...session, - user: token, - }; - }, - }, - pages: { - signIn: '/login', - signOut: '/logout', - error: '/authError', - newUser: '/register', - }, + adapter: PrismaAdapter(prisma as any), + callbacks: { + jwt: async ({ token, user }) => { + if (user && "firstname" in user) { + return { + ...token, + ...user, + }; + } + return token; + }, + session: async ({ session, user, token }) => { + return { + ...session, + user: token, + }; + }, + }, + pages: { + signIn: "/login", + signOut: "/logout", + error: "/authError", + newUser: "/register", + }, } satisfies AuthOptions; export const getServerSession = async () => getNextAuthServerSession(options); diff --git a/apps/hub/app/api/auth/accessToken/route.ts b/apps/hub/app/api/auth/accessToken/route.ts index 37d3161c..dbdf8afa 100644 --- a/apps/hub/app/api/auth/accessToken/route.ts +++ b/apps/hub/app/api/auth/accessToken/route.ts @@ -5,15 +5,11 @@ import { services } from "../../../(auth)/oauth/page"; export const POST = async (req: NextRequest) => { const form = new URLSearchParams(await req.text()); - console.log("POST body:"); const client = new PrismaClient(); const accessToken = form.get("token") || form.get("code"); const clientId = form.get("client_id"); const clientSecret = form.get("client_secret"); - console.log("Access token:", accessToken); - console.log("Client ID:", clientId); - console.log("Secret:", clientSecret); const service = services.find((s) => s.id === clientId); if (!accessToken)