From 30b0caf19ffa402ed72a8dd76c75ade8433dc4e3 Mon Sep 17 00:00:00 2001 From: PxlLoewe <72106766+PxlLoewe@users.noreply.github.com> Date: Tue, 11 Mar 2025 22:49:54 -0700 Subject: [PATCH] Added Loading Button to hub auth --- .../app/(auth)/login/_components/Login.tsx | 196 ++++----- .../(auth)/register/_components/Register.tsx | 398 +++++++++--------- 2 files changed, 297 insertions(+), 297 deletions(-) diff --git a/apps/hub/app/(auth)/login/_components/Login.tsx b/apps/hub/app/(auth)/login/_components/Login.tsx index 7acc39eb..804f5299 100644 --- a/apps/hub/app/(auth)/login/_components/Login.tsx +++ b/apps/hub/app/(auth)/login/_components/Login.tsx @@ -1,111 +1,113 @@ "use client"; import { zodResolver } from "@hookform/resolvers/zod"; -import { signIn } from "next-auth/react"; +import { signIn, useSession } from "next-auth/react"; import Link from "next/link"; import { redirect, useSearchParams } from "next/navigation"; import { useState } from "react"; import { useForm } from "react-hook-form"; import { Toaster, toast } from "react-hot-toast"; import { z } from "zod"; +import { Button } from "../../../_components/ui/Button"; export const Login = () => { - const [isLoading, setIsLoading] = useState(false); - const searchParams = useSearchParams(); - const schema = z.object({ - email: z.string().email(), - password: z.string(), - }); + const [isLoading, setIsLoading] = useState(false); + const searchParams = useSearchParams(); + const schema = z.object({ + email: z.string().email(), + password: z.string(), + }); - type schemaType = z.infer; + type schemaType = z.infer; - const form = useForm({ - resolver: zodResolver(schema), - }); + const form = useForm({ + resolver: zodResolver(schema), + }); - return ( -
{ - setIsLoading(true); - const data = await signIn("credentials", { - redirect: false, - email: form.getValues("email"), - password: form.getValues("password"), - }); - setIsLoading(false); - if (!data || data.error) { - toast.error("E-Mail / Passwort ist falsch!", { - style: { - background: "var(--color-base-100)", - color: "var(--color-base-content)", - }, - }); - return; - } - redirect(searchParams.get("redirect") || "/"); - })} - > -
- -
-

Login

- - Noch keinen Account? Zur{" "} - - Registrierung - - - -

- {typeof form.formState.errors.email?.message === "string" - ? form.formState.errors.email.message - : ""} -

- -
- -
-
- ); + return ( +
{ + setIsLoading(true); + const data = await signIn("credentials", { + redirect: false, + email: form.getValues("email"), + password: form.getValues("password"), + }); + setIsLoading(false); + if (!data || data.error) { + toast.error("E-Mail / Passwort ist falsch!", { + style: { + background: "var(--color-base-100)", + color: "var(--color-base-content)", + }, + }); + return; + } + redirect(searchParams.get("redirect") || "/"); + })} + > +
+ +
+

Login

+ + Noch keinen Account? Zur{" "} + + Registrierung + + + +

+ {typeof form.formState.errors.email?.message === "string" + ? form.formState.errors.email.message + : ""} +

+ +
+ +
+
+ ); }; diff --git a/apps/hub/app/(auth)/register/_components/Register.tsx b/apps/hub/app/(auth)/register/_components/Register.tsx index 27d7721c..3aba1b7a 100644 --- a/apps/hub/app/(auth)/register/_components/Register.tsx +++ b/apps/hub/app/(auth)/register/_components/Register.tsx @@ -1,207 +1,205 @@ -'use client'; -import { zodResolver } from '@hookform/resolvers/zod'; -import { useForm } from 'react-hook-form'; -import { z } from 'zod'; -import { register } from '../action'; -import { signIn } from 'next-auth/react'; -import Link from 'next/link'; -import { useState } from 'react'; -import clsx, { ClassValue } from 'clsx'; -import { twMerge } from 'tailwind-merge'; +"use client"; +import { zodResolver } from "@hookform/resolvers/zod"; +import { useForm } from "react-hook-form"; +import { z } from "zod"; +import { register } from "../action"; +import { signIn } from "next-auth/react"; +import Link from "next/link"; +import { useState } from "react"; +import clsx, { ClassValue } from "clsx"; +import { twMerge } from "tailwind-merge"; +import { Button } from "../../../_components/ui/Button"; export const Register = () => { - const schema = z - .object({ - email: z.string().email({ - message: 'Please enter a valid email', - }), - firstname: z.string().min(2).max(30), - lastname: z.string().min(2).max(30), - password: z.string(), - passwordConfirm: z.string(), - }) - .superRefine(({ password, passwordConfirm }, ctx) => { - if (password !== passwordConfirm) { - ctx.addIssue({ - code: 'custom', - message: 'Die Passwörter stimmen nicht überein', - path: ['confirmPassword'], - }); - } - }); + const schema = z + .object({ + email: z.string().email({ + message: "Please enter a valid email", + }), + firstname: z.string().min(2).max(30), + lastname: z.string().min(2).max(30), + password: z.string(), + passwordConfirm: z.string(), + }) + .superRefine(({ password, passwordConfirm }, ctx) => { + if (password !== passwordConfirm) { + ctx.addIssue({ + code: "custom", + message: "Die Passwörter stimmen nicht überein", + path: ["confirmPassword"], + }); + } + }); - type IFormInput = z.infer; + type IFormInput = z.infer; - const [isLoading, setIsLoading] = useState(false); + const [isLoading, setIsLoading] = useState(false); - const form = useForm({ - resolver: zodResolver(schema), - defaultValues: { - email: '', - password: '', - passwordConfirm: '', - }, - }); - console.log(form.formState.errors); - return ( -
{ - setIsLoading(true); - const values = form.getValues(); - const user = await register({ - email: form.getValues('email'), - password: form.getValues('password'), - firstname: form.getValues('firstname'), - lastname: form.getValues('lastname'), - }); - await signIn('credentials', { - callbackUrl: '/', - email: user.email, - password: values.password, - }); - setIsLoading(false); - })} - > -

Registrierung

- - Zurück zum{' '} - - Login - - -
- -

- {typeof form.formState.errors.firstname?.message === 'string' - ? form.formState.errors.firstname.message - : ''} -

- -

- {typeof form.formState.errors.lastname?.message === 'string' - ? form.formState.errors.lastname.message - : ''} -

-
Account
- + const form = useForm({ + resolver: zodResolver(schema), + defaultValues: { + email: "", + password: "", + passwordConfirm: "", + }, + }); + console.log(form.formState.errors); + return ( + { + setIsLoading(true); + const values = form.getValues(); + const user = await register({ + email: form.getValues("email"), + password: form.getValues("password"), + firstname: form.getValues("firstname"), + lastname: form.getValues("lastname"), + }); + await signIn("credentials", { + callbackUrl: "/", + email: user.email, + password: values.password, + }); + setIsLoading(false); + })} + > +

Registrierung

+ + Zurück zum{" "} + + Login + + +
+ +

+ {typeof form.formState.errors.firstname?.message === "string" + ? form.formState.errors.firstname.message + : ""} +

+ +

+ {typeof form.formState.errors.lastname?.message === "string" + ? form.formState.errors.lastname.message + : ""} +

+
Account
+ -

- {typeof form.formState.errors.email?.message === 'string' - ? form.formState.errors.email.message - : ''} -

- -

- {typeof form.formState.errors.password?.message === 'string' - ? form.formState.errors.password.message - : ''} -

- -

- {typeof form.formState.errors.passwordConfirm?.message === 'string' - ? form.formState.errors.passwordConfirm.message - : ''} -

-
- -
-
- - ); +

+ {typeof form.formState.errors.email?.message === "string" + ? form.formState.errors.email.message + : ""} +

+ +

+ {typeof form.formState.errors.password?.message === "string" + ? form.formState.errors.password.message + : ""} +

+ +

+ {typeof form.formState.errors.passwordConfirm?.message === "string" + ? form.formState.errors.passwordConfirm.message + : ""} +

+
+ +
+
+ + ); };