autosend and autoverify verification mail

This commit is contained in:
PxlLoewe
2025-05-31 19:15:28 -07:00
parent 2f297ed878
commit ed775afd93
6 changed files with 161 additions and 26 deletions

View File

@@ -33,6 +33,7 @@
"jsonwebtoken": "^9.0.2",
"livekit-server-sdk": "^2.10.2",
"nodemailer": "^6.10.0",
"nodemon": "^3.1.10",
"react": "^19.0.0",
"redis": "^4.7.0",
"socket.io": "^4.8.1",

View File

@@ -27,6 +27,7 @@
"dotenv": "^16.4.7",
"express": "^4.21.2",
"nodemailer": "^6.10.0",
"nodemon": "^3.1.10",
"react": "^19.0.0",
"tsconfig-paths": "^4.2.0",
"tsx": "^4.19.4"

View File

@@ -3,7 +3,7 @@ import { CheckEmailCode } from "(app)/admin/user/action";
import { Check } from "lucide-react";
import { useSession } from "next-auth/react";
import { useRouter, useSearchParams } from "next/navigation";
import { useState } from "react";
import { useEffect, useState } from "react";
import toast from "react-hot-toast";
export default function Page() {
@@ -12,30 +12,39 @@ export default function Page() {
const searchParams = useSearchParams();
const paramsCode = searchParams.get("code");
const [code, setCode] = useState(paramsCode || "");
useEffect(() => {
if (!paramsCode) return;
verifyCode(paramsCode);
}, [paramsCode])
async function verifyCode(code: string) {
if (!session.data?.user.email || !code) return;
const res = await CheckEmailCode(session.data?.user.id || "", code);
if (res.error) {
toast.error(res.error);
} else {
toast.success(res.message || "E-Mail erfolgreich bestätigt!");
router.push("/");
}
}
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" /> Email Bestätigung
<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="code"
placeholder="Bestätigungscode"
value={code}
onChange={(e) => setCode(e.target.value)}
/>
<button
className="btn btn-primary"
onClick={async () => {
const res = await CheckEmailCode(session.data?.user.id || "", code);
if (res.error) {
toast.error(res.error);
} else {
toast.success(res.message || "Email erfolgreich bestätigt!");
router.push("/");
}
}}
onClick={() => verifyCode(code)}
disabled={!session.data?.user.email || !code}
>
Bestätigen

View File

@@ -10,6 +10,7 @@ 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";
export const Register = () => {
const { showBoundary } = useErrorBoundary();
@@ -59,6 +60,7 @@ export const Register = () => {
firstname: form.getValues("firstname"),
lastname: form.getValues("lastname"),
});
await sendVerificationLink(user.id);
await signIn("credentials", {
callbackUrl: "/",
email: user.email,

View File

@@ -13,9 +13,9 @@ export const EmailVerification = () => {
<div role="alert" className="alert alert-warning">
<TriangleAlert />
<div>
<h3 className="font-bold">Email Addresse nicht bestätigt!</h3>
<h3 className="font-bold">E-Mail Adresse nicht bestätigt!</h3>
<div className="text-xs">
Wenn deine Email Addresse nicht bestätigt ist kannst du dich nicht Verbinden
Wir haben dir bereits eine E-Mail gesendet. Wenn deine E-Mail Adresse nicht bestätigt ist, kannst du dich nicht mit der Leitstelle verbinden!
</div>
</div>
<Button
@@ -29,7 +29,7 @@ export const EmailVerification = () => {
setLoading(false);
}}
>
Link senden
Link erneut senden
</Button>
</div>
);