added footer links, added email alias check

This commit is contained in:
PxlLoewe
2025-06-06 11:54:03 -07:00
parent 587884dfd9
commit b1262c4278
11 changed files with 141 additions and 97 deletions

View File

@@ -0,0 +1,56 @@
"use client";
import { CheckEmailCode } from "(app)/admin/user/action";
import { Check } from "lucide-react";
import { useRouter, useSearchParams } from "next/navigation";
import { useCallback, useEffect, useState } from "react";
import toast from "react-hot-toast";
export default function Page() {
const router = useRouter();
const searchParams = useSearchParams();
const paramsCode = searchParams.get("code");
const [code, setCode] = useState(paramsCode || "");
const verifyCode = useCallback(
async (code: string) => {
console.log("Verifying code:", code);
if (!code) return;
const res = await CheckEmailCode(code);
console.log("Verification response:", res);
if (res.error) {
console.log("Verification error:", res.error);
toast.error(res.error);
} else {
toast.success(res.message || "E-Mail erfolgreich bestätigt!");
router.push("/");
}
},
[router],
);
useEffect(() => {
if (!paramsCode) return;
verifyCode(paramsCode);
}, [paramsCode, verifyCode]);
return (
<div className="card bg-base-200 shadow-xl mb-4 ">
<div className="card-body">
<p className="text-2xl font-semibold text-left flex items-center gap-2">
<Check className="w-5 h-5" /> E-Mail Bestätigung
</p>
<div className="flex justify-center gap-3 w-full">
<input
className="input flex-1"
placeholder="Bestätigungscode"
value={code}
onChange={(e) => setCode(e.target.value)}
/>
<button className="btn btn-primary" onClick={() => verifyCode(code)} disabled={!code}>
Bestätigen
</button>
</div>
</div>
</div>
);
}

View File

@@ -6,22 +6,29 @@ 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";
import { useErrorBoundary } from "react-error-boundary";
import { sendVerificationLink } from "(app)/admin/user/action";
import toast from "react-hot-toast";
export const Register = () => {
const { showBoundary } = useErrorBoundary();
const schema = z
.object({
email: z.string().email({
message: "Please enter a valid email",
}),
email: z
.string()
.email({ message: "Please enter a valid email" })
.refine(
(value) => {
// Regex to check for email aliases like + or %
const emailAliasRegex = /[+%]/;
return !emailAliasRegex.test(value);
},
{
message: "Email-Aliase (wie + oder %) sind nicht erlaubt",
},
),
firstname: z.string().min(2).max(30),
lastname: z.string().min(2).max(30),
password: z.string(),
password: z.string().min(12),
passwordConfirm: z.string(),
})
.superRefine(({ password, passwordConfirm }, ctx) => {
@@ -29,7 +36,7 @@ export const Register = () => {
ctx.addIssue({
code: "custom",
message: "Die Passwörter stimmen nicht überein",
path: ["confirmPassword"],
path: ["passwordConfirm"],
});
}
});
@@ -46,7 +53,7 @@ export const Register = () => {
passwordConfirm: "",
},
});
console.log("Register form", form.formState.errors);
return (
<form
className="card-body"
@@ -66,9 +73,14 @@ export const Register = () => {
email: user.email,
password: values.password,
});
setIsLoading(false);
} catch (error) {
showBoundary(error);
toast.error(
error instanceof Error
? error.message
: "Es ist ein Fehler aufgetreten. Bitte versuche es später erneut.",
);
} finally {
setIsLoading(false);
}
})}
>
@@ -133,12 +145,7 @@ export const Register = () => {
<path d="M2.5 3A1.5 1.5 0 0 0 1 4.5v.793c.026.009.051.02.076.032L7.674 8.51c.206.1.446.1.652 0l6.598-3.185A.755.755 0 0 1 15 5.293V4.5A1.5 1.5 0 0 0 13.5 3h-11Z" />
<path d="M15 6.954 8.978 9.86a2.25 2.25 0 0 1-1.956 0L1 6.954V11.5A1.5 1.5 0 0 0 2.5 13h11a1.5 1.5 0 0 0 1.5-1.5V6.954Z" />
</svg>
<input
type="text"
className="grow"
{...form.register("email")}
placeholder="Email"
/>
<input type="text" className="grow" {...form.register("email")} placeholder="Email" />
</label>
<p className="text-error">
@@ -199,11 +206,7 @@ export const Register = () => {
: ""}
</p>
<div className="card-actions mt-6">
<Button
disabled={isLoading}
isLoading={isLoading}
className="btn btn-primary btn-block"
>
<Button disabled={isLoading} isLoading={isLoading} className="btn btn-primary btn-block">
Registrieren
</Button>
</div>

View File

@@ -2,10 +2,7 @@
import { prisma, Prisma } from "@repo/db";
import bcrypt from "bcryptjs";
export const register = async ({
password,
...user
}: Omit<Prisma.UserCreateInput, "publicId">) => {
export const register = async ({ password, ...user }: Omit<Prisma.UserCreateInput, "publicId">) => {
const hashedPassword = await bcrypt.hash(password, 12);
const lastUserPublicId = await prisma.user.findFirst({
select: {
@@ -21,6 +18,18 @@ export const register = async ({
varPublicId = `VAR${(lastUserInt + 1).toString().padStart(4, "0")}`;
}
const existingUser = await prisma.user.findFirst({
where: {
email: user.email,
},
select: {
id: true,
},
});
if (existingUser) {
throw new Error("Ein Nutzer mit dieser E-Mail-Adresse existiert bereits.");
}
const newUser = prisma.user.create({
data: {
...user,